Skip to content

useError

Category
Export Size
139 B
Last Changed
5 days ago

Returns a stable error dispatcher that re-throws on the next render.

Demo

Usage

tsx
import { 
useError
} from '@reause/shared'
function
ThrowButton
() {
const
dispatchError
=
useError
()
// dispatch from an event handler / async callback: `dispatchError` never // throws itself, the error surfaces on the following render return <
button
onClick={() =>
dispatchError
(new
Error
('boom'))}>throw</button>
} // wrap the tree in an Error Boundary so the re-thrown error is caught

Type Declarations

ts
export function useError(): (err: Error) => void

Source

Source · Demo · react-use

Contributors

hairyf

Changelog

v0.1.6 on
287f0 - feat(shared): add useError (#917)

Released under the MIT License. v0.1.8