Download react-use/src/useError.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 382 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/src/useError.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/src/useError.ts
-
curl -L -o useError.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/src/useError.ts
382 Bytes
| import { useCallback, useEffect, useState } from 'react'; | |
| const useError = (): ((err: Error) => void) => { | |
| const [error, setError] = useState<Error | null>(null); | |
| useEffect(() => { | |
| if (error) { | |
| throw error; | |
| } | |
| }, [error]); | |
| const dispatchError = useCallback((err: Error) => { | |
| setError(err); | |
| }, []); | |
| return dispatchError; | |
| }; | |
| export default useError; | |