Skip to content

Commit

Permalink
feat: pass arguments to useAsyncFn function
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich authored May 24, 2019
2 parents 3f532a8 + c6d692a commit 6789d10
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/useAsyncFn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ export type AsyncState<T> =
value: T;
};

const useAsyncFn = <T>(fn: () => Promise<T>, deps: DependencyList = []): [AsyncState<T>, () => void] => {
const useAsyncFn = <T>(fn: (...args: any[]) => Promise<T>, deps: DependencyList = []): [AsyncState<T>, () => void] => {
const [state, set] = useState<AsyncState<T>>({
loading: false,
});

const mounted = useRefMounted();

const callback = useCallback(() => {
const callback = useCallback((...args) => {
set({ loading: true });

fn().then(
fn(...args).then(
value => {
if (mounted.current) {
set({ value, loading: false });
Expand Down

0 comments on commit 6789d10

Please sign in to comment.