useSafeState
API
import useSafeState from '@restart/hooks/useSafeState'
useSafeState
<TState>(state: [TState,AsyncSetState<TState>]) => [TState,(stateUpdate: React.SetStateAction<TState>) => Promise<void>]useSafeState
takes the return value of auseState
hook and wraps the setter to prevent updates onces the component has unmounted. Can used withuseMergeState
anduseStateAsync
as wellParameters
state
[TState,AsyncSetState<TState>]The return value of a useStateHook
const [show, setShow] = useSafeState(useState(true));
Return Value [TState,(stateUpdate: React.SetStateAction<TState>) => Promise<void>]
useSafeState
<TState>(state: [TState,StateSetter<TState>]) => [TState,StateSetter<TState>]Parameters
state
[TState,StateSetter<TState>]
Return Value [TState,StateSetter<TState>]