mirror of
https://github.com/streamich/react-use.git
synced 2026-01-18 14:06:52 +00:00
Also reduce max line width to 100. And remove `lint:types` step for commit sequence, it bothers when committing incomplete (wip) changes.
21 lines
468 B
TypeScript
21 lines
468 B
TypeScript
import { DependencyList, useEffect } from 'react';
|
|
import useAsyncFn from './useAsyncFn';
|
|
import { FunctionReturningPromise } from './misc/types';
|
|
|
|
export { AsyncState, AsyncFnReturn } from './useAsyncFn';
|
|
|
|
export default function useAsync<T extends FunctionReturningPromise>(
|
|
fn: T,
|
|
deps: DependencyList = []
|
|
) {
|
|
const [state, callback] = useAsyncFn(fn, deps, {
|
|
loading: true,
|
|
});
|
|
|
|
useEffect(() => {
|
|
callback();
|
|
}, [callback]);
|
|
|
|
return state;
|
|
}
|