State Management
useAsync
Handle async operations with loading, error, and success states automatically.
import { useAsync } from "saha-ui"Uses
Wrap an async function to handle loading/success/error state and to provide an `execute` function; optional immediate execution.
Props
| Name | Type | Description | Default |
|---|---|---|---|
| asyncFunction | function | Function returning a Promise. | - |
| options.immediate | boolean | Run immediately on mount. | false |
Returns
| Name | Description |
|---|---|
| data, error, isLoading, isSuccess, isError | Async state flags and data. |
| execute(...args) | Run the async function and update state. |
| reset() | Reset the internal state. |
Example
const { data, isLoading, execute } = useAsync(fetchUsers, { immediate: false }); await execute();Notes
Errors are re-thrown by `execute` to allow caller-level handling; state is maintained in the hook.