Skip to content

useAsync ​

Category
Utilities

Hook that provides the state of an async callback

typescript
import { useAsync } from '@siberiacancode/reactuse';

Usage ​

typescript
const { data, isLoading, isError, error } = useAsync(() => fetch('url'), [deps]);

Demo ​

Api ​

Parameters

NameTypeDefaultNote
callback() => Promise<Data>-- The async callback
deps?DependencyList-- The dependencies of the callback

Contributors ​

Source • Demo