useAsync ​
Hook that provides the state of an async callback
utilities
test coverage
Last changed: 7 days ago
Installation ​
Library
CLI
Manual
typescript
import { useAsync } from '@siberiacancode/reactuse';
Usage ​
typescript
const { data, isLoading, isError, error } = useAsync(() => fetch('url'), [deps]);
Demo ​
Api ​
Parameters
Name | Type | Default | Note |
---|---|---|---|
callback | () => Promise<Data> | - | The async callback |
deps | DependencyList | - | The dependencies of the callback |
Returns
UseAsyncReturn<Data>
Type declaration ​
typescript
import type { DependencyList } from 'react';
export interface UseAsyncReturn<Data> {
/* The state of the query */
data?: Data;
/* The error of the query */
error?: Error;
/* The error state of the query */
isError: boolean;
/* The loading state of the query */
isLoading: boolean;
}
Source ​
Source • DemoContributors ​
B
D