react-use/src/useError.ts
Renovate Bot a27f09fd36
chore: refactoring and rearrangement.
More DRY code. Also move non-hooks to separate directories.

BREAKING CHANGE: all `create*` factories been moved to `factory` subdirectory and in case direct import should be imported like `react-use/esm/factory/createBreakpoint`
BREAKING CHANGE: `comps` directory renamed to `component`
2021-01-30 23:30:26 +03:00

20 lines
382 B
TypeScript

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;