usePromise
About
Promise management hook for React that handles async operations with automatic loading, error, and data states.
Examples
Basic usage
With dependencies
Error handling
Arguments
Argument | Type | Description | Default value |
---|---|---|---|
asyncFunction | function | Async function that returns a Promise | - |
deps | array | Dependency array for re-running the promise | [] |
Return value
Return value | Type | Description |
---|---|---|
state | Object | Object containing {data: T | null, loading: boolean, error: Error | null} |