mirror of
https://github.com/streamich/react-use.git
synced 2025-12-08 18:02:14 +00:00
35 lines
560 B
Markdown
35 lines
560 B
Markdown
# `useError`
|
|
|
|
React side-effect hook that returns an error dispatcher.
|
|
|
|
## Usage
|
|
|
|
```jsx
|
|
import { useError } from 'react-use';
|
|
|
|
const Demo = () => {
|
|
const dispatchError = useError();
|
|
|
|
const clickHandler = () => {
|
|
dispatchError(new Error('Some error!'));
|
|
};
|
|
|
|
return <button onClick={clickHandler}>Click me to throw</button>;
|
|
};
|
|
|
|
// In parent app
|
|
const App = () => (
|
|
<ErrorBoundary>
|
|
<Demo />
|
|
</ErrorBoundary>
|
|
);
|
|
```
|
|
|
|
## Reference
|
|
|
|
```js
|
|
const dispatchError = useError();
|
|
```
|
|
|
|
- `dispatchError` — Callback of type `(err: Error) => void`
|