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 a useState hook and wraps the setter to prevent updates onces the component has unmounted. Can used with useMergeState and useStateAsync as well

      Parameters

      • 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>]