1 | import { Dispatch, SetStateAction } from 'react';
|
2 | import { AsyncSetState } from './useStateAsync';
|
3 | declare type StateSetter<TState> = Dispatch<SetStateAction<TState>>;
|
4 | /**
|
5 | * `useSafeState` takes the return value of a `useState` hook and wraps the
|
6 | * setter to prevent updates onces the component has unmounted. Can used
|
7 | * with `useMergeState` and `useStateAsync` as well
|
8 | *
|
9 | * @param state The return value of a useStateHook
|
10 | *
|
11 | * ```ts
|
12 | * const [show, setShow] = useSafeState(useState(true));
|
13 | * ```
|
14 | */
|
15 | declare function useSafeState<TState>(state: [TState, AsyncSetState<TState>]): [TState, (stateUpdate: React.SetStateAction<TState>) => Promise<void>];
|
16 | declare function useSafeState<TState>(state: [TState, StateSetter<TState>]): [TState, StateSetter<TState>];
|
17 | export default useSafeState;
|