Download react-use/src/useAsync.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 468 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/src/useAsync.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/src/useAsync.ts
-
curl -L -o useAsync.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/1e92f2d0b9e054abc23a53595fd89ad3e2b4a34e/react-use/src/useAsync.ts
468 Bytes
| 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; | |
| } | |