streamich / react-use

React Hooks — 👍
http://streamich.github.io/react-use
The Unlicense
41.98k stars 3.16k forks source link

fix: initial loading unable to update correctly #2606

Open xnmeet opened 6 days ago

xnmeet commented 6 days ago

Description

When useAsyncFn is used and the given initial value loading is true, subsequent fetch will not be able to update the loading state

  const [state, fetch] = useAsyncFn(
    async () => {
      await sleep();
      return 'hello';
    },
    undefined,
    { loading: true },
  );

  console.log(state.loading); // once to false and don't change again

Type of change

Checklist