Skip to content

Commit

Permalink
Change useAsync() to catch error thrown from useAsyncFn's callback
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoarcega committed Sep 21, 2019
1 parent ff12319 commit 32b0020
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/useAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ export default function useAsync<Result = any, Args extends any[] = any[]>(
});

useEffect(() => {
callback();
init();
}, [callback]);

async function init() {
try {
await callback();
} catch {}
}

return state;
}

0 comments on commit 32b0020

Please sign in to comment.