Skip to content

Commit 6d42457

Browse files
authored
docs(feedback): Example docs on sendFeedback (#9560)
1 parent db127a3 commit 6d42457

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

packages/feedback/README.md

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ import {BrowserClient, getCurrentHub} from '@sentry/react';
212212
import {Feedback} from '@sentry-internal/feedback';
213213

214214
function MyFeedbackButton() {
215-
const client = hub && getCurrentHub().getClient<BrowserClient>();
215+
const client = getCurrentHub().getClient<BrowserClient>();
216216
const feedback = client?.getIntegration(Feedback);
217217

218218
// Don't render custom feedback button if Feedback integration not installed
@@ -230,22 +230,40 @@ function MyFeedbackButton() {
230230

231231
### Bring Your Own Widget
232232

233-
You can also bring your own widget and UI and simply pass a feedback object to the `sendFeedback()` function.
233+
You can also bring your own widget and UI and simply pass a feedback object to the `sendFeedback()` function. The `sendFeedback` function accepts two parameters:
234+
* a feedback object with a required `message` property, and additionally, optional `name` and `email` properties
235+
* an options object
236+
237+
```javascript
238+
sendFeedback({
239+
name: 'Jane Doe', // optional
240+
email: 'email@example.org', // optional
241+
message: 'This is an example feedback', // required
242+
}, {
243+
includeReplay: true, // optional
244+
})
245+
```
246+
247+
Here is a simple example
234248

235249
```html
236250
<form id="my-feedback-form">
237251
<input name="name" />
238252
<input name="email" />
239253
<textarea name="message" placeholder="What's the issue?" />
240254
</form>
255+
```
256+
257+
```javascript
258+
import {BrowserClient, getCurrentHub} from '@sentry/react';
259+
import {Feedback} from '@sentry-internal/feedback';
241260

242-
<script>
243261
document.getElementById('my-feedback-form').addEventListener('submit', (event) => {
262+
const feedback = getCurrentHub().getClient<BrowserClient>()?.getIntegration(Feedback);
244263
const formData = new FormData(event.currentTarget);
245-
Feedback.sendFeedback(formData);
264+
feedback.sendFeedback(formData);
246265
event.preventDefault();
247266
});
248-
</script>
249267
```
250268
251269
## Alerting on User Feedback Reports

0 commit comments

Comments
 (0)