Dashboard sipadu mbip
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.

useStateAsync.d.ts 790B

123456789101112131415161718192021
  1. import React from 'react';
  2. export declare type AsyncSetState<TState> = (stateUpdate: React.SetStateAction<TState>) => Promise<TState>;
  3. /**
  4. * A hook that mirrors `useState` in function and API, expect that setState
  5. * calls return a promise that resolves after the state has been set (in an effect).
  6. *
  7. * This is _similar_ to the second callback in classy setState calls, but fires later.
  8. *
  9. * ```ts
  10. * const [counter, setState] = useStateAsync(1);
  11. *
  12. * const handleIncrement = async () => {
  13. * await setState(2);
  14. * doWorkRequiringCurrentState()
  15. * }
  16. * ```
  17. *
  18. * @param initialState initialize with some state value same as `useState`
  19. */
  20. declare function useStateAsync<TState>(initialState: TState | (() => TState)): [TState, AsyncSetState<TState>];
  21. export default useStateAsync;