GoScrobble/web/node_modules/@restart/hooks/esm/useSafeState.js

12 lines
318 B
JavaScript
Raw Permalink Normal View History

2022-04-25 02:47:15 +00:00
import { useCallback } from 'react';
import useMounted from './useMounted';
function useSafeState(state) {
var isMounted = useMounted();
return [state[0], useCallback(function (nextState) {
if (!isMounted()) return;
return state[1](nextState);
}, [isMounted, state[1]])];
}
export default useSafeState;