Skip to content

Commit 0ea255d

Browse files
committed
docs(user-feedback): Add snippet for manual injection
1 parent b368f47 commit 0ea255d

File tree

4 files changed

+65
-39
lines changed

4 files changed

+65
-39
lines changed

docs/platforms/javascript/common/user-feedback/configuration/index.mdx

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,45 +30,7 @@ The following options can be configured for the integration in `feedbackIntegrat
3030

3131
If you have `autoInject: true` a button will be inserted into the page that triggers the form to pop up so the user can enter their feedback. If instead you want to control when this injection happens, call the `feedback.createWidget()` method to get a reference to an `Actor` object, and then call `appendToDom()` to insert it into the page.
3232

33-
```javascript
34-
const feedback = feedbackIntegration({
35-
// Disable injecting the default widget
36-
autoInject: false,
37-
});
38-
39-
// Create and render the button
40-
const widget = feedback.createWidget();
41-
42-
// Later, when it's time to clean up:
43-
widget.removeFromDom();
44-
```
45-
```typescript {tabTitle: NextJS}
46-
function ToggleFeedbackButton() {
47-
const [feedback, setFeedback] = useState();
48-
// Read `getFeedback` on the client only, to avoid hydration errors when server rendering
49-
useEffect(() => {
50-
setFeedback(Sentry.getFeedback());
51-
}, []);
52-
53-
const [widget, setWidget] = useState();
54-
return (
55-
<button
56-
type="button"
57-
onClick={async () => {
58-
if (widget) {
59-
widget.removeFromDom();
60-
setWidget(null);
61-
} else {
62-
setWidget(feedback.createWidget());
63-
}
64-
}}
65-
>
66-
{widget ? "Remove Widget" : "Create Widget"}
67-
</button>
68-
);
69-
}
70-
```
71-
33+
<PlatformContent includePath="user-feedback/manual-injection" />
7234

7335
Read more about how to [use your own UI](#bring-your-own-button) below.
7436

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
```javascript
2+
const feedback = feedbackIntegration({
3+
// Disable injecting the default widget
4+
autoInject: false,
5+
});
6+
7+
// Create and render the button
8+
const widget = feedback.createWidget();
9+
10+
// Later, when it's time to clean up:
11+
widget.removeFromDom();
12+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
```jsx {tabTitle: NextJS}
2+
function ToggleFeedbackButton() {
3+
const [feedback, setFeedback] = useState();
4+
// Read `getFeedback` on the client only, to avoid hydration errors when server rendering
5+
useEffect(() => {
6+
setFeedback(Sentry.getFeedback());
7+
}, []);
8+
9+
const [widget, setWidget] = useState();
10+
return (
11+
<button
12+
type="button"
13+
onClick={async () => {
14+
if (widget) {
15+
widget.removeFromDom();
16+
setWidget(null);
17+
} else {
18+
setWidget(feedback.createWidget());
19+
}
20+
}}
21+
>
22+
{widget ? "Remove Widget" : "Create Widget"}
23+
</button>
24+
);
25+
}
26+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
```jsx {tabTitle: React}
2+
function ToggleFeedbackButton() {
3+
const [feedback, setFeedback] = useState();
4+
// Read `getFeedback` on the client only, to avoid hydration errors when server rendering
5+
useEffect(() => {
6+
setFeedback(Sentry.getFeedback());
7+
}, []);
8+
9+
const [widget, setWidget] = useState();
10+
return (
11+
<button
12+
type="button"
13+
onClick={async () => {
14+
if (widget) {
15+
widget.removeFromDom();
16+
setWidget(null);
17+
} else {
18+
setWidget(feedback.createWidget());
19+
}
20+
}}
21+
>
22+
{widget ? "Remove Widget" : "Create Widget"}
23+
</button>
24+
);
25+
}
26+
```

0 commit comments

Comments
 (0)