mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-29 03:45:15 +00:00
12 lines
318 B
JavaScript
12 lines
318 B
JavaScript
|
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;
|