useCall React hook
This package is about calling functions in React components
Installation
npm install use-call
or
yarn add use-call
Usage
useCall
Call a function lazily with arguments and just get cached result on next renders
It takes a function and arguments: const useCall = (fn, ...args) =>
const defaultValues = const three = // fn, ...argsconst companyPromise = // payload
useAsyncCall
Call an async function and handle promise. Returns the following array: [result, error, pending]
const company = const user userError userLoading = // id
Useful packages
usePromise
hook is used to handle promises in useAsyncCall
See docs: https://github.com/doasync/use-promise
const data dataError loading =
Use once-only
package to create a function to be called once
See docs: https://github.com/doasync/once-only
const fetchUsersOnce = // not in renderconst usersPromise =
Tip
If you found this hook useful, please star this package on GitHub ★
Author
@doasync