Skip to content

Commit

Permalink
fix: do not re-render unncessarily in useAsyncFn hook
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich authored Aug 31, 2021
2 parents 27f841d + e5fb4e9 commit fa3ba25
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/useAsyncFn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export default function useAsyncFn<T extends FunctionReturningPromise>(

const callback = useCallback((...args: Parameters<T>): ReturnType<T> => {
const callId = ++lastCallId.current;
set((prevState) => ({ ...prevState, loading: true }));

if (!state.loading) {
set((prevState) => ({ ...prevState, loading: true }));
}

return fn(...args).then(
(value) => {
Expand Down

0 comments on commit fa3ba25

Please sign in to comment.