Skip to content

Commit 71be38c

Browse files
authored
docs(user-feedback): Add snippet for manual injection (#11502)
* docs(user-feedback): Add snippet for manual injection * review suggestions
1 parent 7626ad7 commit 71be38c

File tree

6 files changed

+96
-44
lines changed

6 files changed

+96
-44
lines changed

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

Lines changed: 5 additions & 43 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

@@ -257,7 +219,7 @@ You can use your own button instead of the default injected button to trigger th
257219

258220
```javascript
259221
const feedback = feedbackIntegration({
260-
// Disable injecting the default widget
222+
// Disable the injection of the default widget
261223
autoInject: false,
262224
});
263225

@@ -268,7 +230,7 @@ feedback.attachTo(document.querySelector("#your-button"), {
268230
```typescript {tabTitle: NextJs}
269231
function AttachToFeedbackButton() {
270232
const [feedback, setFeedback] = useState();
271-
// Read `getFeedback` on the client only, to avoid hydration errors when server rendering
233+
// Read `getFeedback` on the client only, to avoid hydration errors during server rendering
272234
useEffect(() => {
273235
setFeedback(Sentry.getFeedback());
274236
}, []);
@@ -294,7 +256,7 @@ Alternatively, you can call `feedback.createForm()` and have full control over w
294256

295257
```javascript
296258
const feedback = feedbackIntegration({
297-
// Disable injecting the default widget
259+
// Disable the injection of the default widget
298260
autoInject: false,
299261
});
300262

@@ -305,7 +267,7 @@ form.open();
305267
```typescript {tabTitle: NextJS}
306268
function CreateFeedbackFromButton() {
307269
const [feedback, setFeedback] = useState();
308-
// Read `getFeedback` on the client only, to avoid hydration errors when server rendering
270+
// Read `getFeedback` on the client only, to avoid hydration errors during server rendering
309271
useEffect(() => {
310272
setFeedback(Sentry.getFeedback());
311273
}, []);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ You can use your own button instead of the default injected button to trigger th
169169

170170
```javascript
171171
const feedback = feedbackIntegration({
172-
// Disable injecting the default widget
172+
// Disable the injection of the default widget
173173
autoInject: false,
174174
});
175175

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 the injection of 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 during 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 during 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: Remix}
2+
function ToggleFeedbackButton() {
3+
const [feedback, setFeedback] = useState();
4+
// Read `getFeedback` on the client only, to avoid hydration errors during 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)