📜  react typescript custom hook - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:16.477000             🧑  作者: Mango

代码示例1
export function useLoading() {
  const [isLoading, setState] = React.useState(false);
  const load = (aPromise: Promise) => {
    setState(true);
    return aPromise.finally(() => setState(false));
  };
  return [isLoading, load] as const; // infers [boolean, typeof load] instead of (boolean | typeof load)[]
}