Answers for "react typescript custom hook"

1

react typescript custom hook

export function useLoading() {
  const [isLoading, setState] = React.useState(false);
  const load = (aPromise: Promise<any>) => {
    setState(true);
    return aPromise.finally(() => setState(false));
  };
  return [isLoading, load] as const; // infers [boolean, typeof load] instead of (boolean | typeof load)[]
}
Posted by: Guest on June-27-2021

Code answers related to "TypeScript"

Browse Popular Code Answers by Language