Skip to content

Commit d8f9f70

Browse files
bobbyg603Agent
andauthored
fix: add user feedback snippet to readme (#19) (#20)
Co-authored-by: Agent <agent@bugsplat.com>
1 parent 33c5fe5 commit d8f9f70

1 file changed

Lines changed: 99 additions & 4 deletions

File tree

README.md

Lines changed: 99 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616

1717
## Introduction
1818

19-
BugSplat supports the collection of errors in React applications. The
19+
BugSplat supports the collection of errors and user feedback in React applications. The
2020
@bugsplat/react npm package implements an
2121
[ErrorBoundary](https://reactjs.org/docs/error-boundaries.html)
2222
component in order to capture rendering errors in child components and
23-
post them to BugSplat where they can be tracked and managed. Adding BugSplat
24-
to your React application is extremely easy. Before getting started please
25-
complete the following tasks:
23+
post them to BugSplat where they can be tracked and managed. It also provides
24+
a `useFeedback` hook for collecting user feedback such as titles, descriptions,
25+
and file attachments. Adding BugSplat to your React application is extremely
26+
easy. Before getting started please complete the following tasks:
2627

2728
- [Sign up](https://app.bugsplat.com/v2/sign-up) for BugSplat
2829
- Create a new
@@ -253,6 +254,65 @@ function App() {
253254
}
254255
```
255256

257+
## User Feedback
258+
259+
Want to collect user feedback such as titles, descriptions, and file
260+
attachments? Use the `useFeedback` hook to submit feedback directly to your
261+
BugSplat dashboard.
262+
263+
```jsx
264+
// src/FeedbackForm.tsx
265+
266+
import { useState } from 'react';
267+
import { useFeedback } from '@bugsplat/react';
268+
269+
export default function FeedbackForm() {
270+
const [title, setTitle] = useState('');
271+
const [description, setDescription] = useState('');
272+
const [files, setFiles] = useState<FileList | null>(null);
273+
const { postFeedback, loading, response, error } = useFeedback();
274+
275+
const handleSubmit = async (e: React.FormEvent) => {
276+
e.preventDefault();
277+
278+
const attachments = files
279+
? Array.from(files).map((file) => ({ filename: file.name, data: file }))
280+
: [];
281+
282+
await postFeedback(title, { description, attachments });
283+
};
284+
285+
if (response) {
286+
return <p>Thanks for your feedback!</p>;
287+
}
288+
289+
return (
290+
<form onSubmit={handleSubmit}>
291+
<input
292+
type="text"
293+
placeholder="Title"
294+
value={title}
295+
onChange={(e) => setTitle(e.target.value)}
296+
/>
297+
<textarea
298+
placeholder="Description"
299+
value={description}
300+
onChange={(e) => setDescription(e.target.value)}
301+
/>
302+
<input
303+
type="file"
304+
multiple
305+
onChange={(e) => setFiles(e.target.files)}
306+
/>
307+
<button type="submit" disabled={loading}>
308+
{loading ? 'Submitting...' : 'Send Feedback'}
309+
</button>
310+
{error && <p>{error.message}</p>}
311+
</form>
312+
);
313+
}
314+
```
315+
256316
## Advanced Usage
257317

258318
### The `scope` property
@@ -511,6 +571,41 @@ function withErrorBoundary<P extends Record<string, unknown>>(
511571
function useErrorHandler(errorProp?: unknown): (error: unknown) => void;
512572
```
513573
574+
### `useFeedback`
575+
576+
```typescript
577+
/**
578+
* Hook for submitting user feedback to BugSplat.
579+
*
580+
* @returns Object with `postFeedback` function and `loading`/`response`/`error` state
581+
*
582+
* @example
583+
* const { postFeedback, loading, error } = useFeedback();
584+
* await postFeedback('Login button broken', { description: 'Nothing happens when I tap it' });
585+
*/
586+
function useFeedback(): {
587+
/**
588+
* Submit user feedback to BugSplat.
589+
*
590+
* @param title - Feedback title
591+
* @param options - Optional BugSplat options (description, attachments, etc.)
592+
*/
593+
postFeedback: (title: string, options?: BugSplatOptions) => Promise<void>;
594+
/**
595+
* Whether feedback is currently being submitted
596+
*/
597+
loading: boolean;
598+
/**
599+
* BugSplat response from the most recent feedback submission
600+
*/
601+
response: BugSplatResponse | null;
602+
/**
603+
* Error from the most recent feedback submission, if any
604+
*/
605+
error: Error | null;
606+
};
607+
```
608+
514609
## Test Suite
515610
516611
This package contains both unit and integration tests. To run them,

0 commit comments

Comments
 (0)