You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
12 lines
318 B
12 lines
318 B
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; |