1 | import { useCallback } from 'react';
|
2 | import useMounted from './useMounted';
|
3 |
|
4 | function useSafeState(state) {
|
5 | var isMounted = useMounted();
|
6 | return [state[0], useCallback(function (nextState) {
|
7 | if (!isMounted()) return;
|
8 | return state[1](nextState);
|
9 | }, [isMounted, state[1]])];
|
10 | }
|
11 |
|
12 | export default useSafeState; |
\ | No newline at end of file |