1.0.0 • Published 5 years ago
react-async-handler v1.0.0
react-async-handler
React hook for handling asynchronous task
Install
npm install react-async-handlerUsage
import useAsyncHandler from 'react-async-handler'
const [execute, { status, data, error }] = useAsyncHandler(() => fetch('https://jsonplaceholder.typicode.com/todos'))API
Return type
execute
type (...args: any[]) => Promise<any>
This is the function to execute the async function
status
type string
The status of the async process, the value can be idle loading success or error
data
type any
The data that returned from the Promise
error
type Error
The error object that caught from Promise
Parameters
callback
type (...args: any[]) => Promise<any>
This is the function that return a Promise that you want to execute
1.0.0
5 years ago