mirror of
https://github.com/streamich/react-use.git
synced 2025-12-08 18:02:14 +00:00
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`
20 lines
382 B
TypeScript
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;
|