@vincecao/use-tools v1.3.3-beta.1
use-tools
Installation
# npm
npm i @vincecao/use-tools
# yarn
yarn add @vincecao/use-toolsThis package was published in both NPMJS and GITHUB npm registry.
To use page from Github npm registry, add below file in your repo before run npm i or yarn add.
# .npmrc
@vincecao:registry=https://npm.pkg.github.comYou can also install directly from git master
# npm
npm i vincecao/use-tools
npm i github:vincecao/use-tools
# yarn
yarn add vincecao/use-tools
yarn add github:vincecao/use-toolsDemo
Please check more samples at below
Hooks
usePromiseState
A hook that allows user to retrieve data from a remote by a promise function. It takes a required promise and optional options as inputs, return data, error status and useful callbacks.
const [remoteData, { error, status, refetch }, setRemoteData] = usePromiseState<T>(promise, {
deps,
onPending,
onSuccess,
onError,
onFinal
})The promise needs to be wrapped with useCallback and options needs to be wrapped with useMemo if it is not undefined.
useTimeout
A simple implementation of useTimeout hook. The changes of promise will reset timeout delay. The disable option pause entire hook, disableDelay remove setTimeout behavior.
useTimeout<T>(func, delay, disabled, disableDelay)The func needs to be wrapped with useCallback.
useShuttle
A hook returns a shuttled list for each unique given array. The changes of array will also trigger re-generate a new shuttled list.
const shuttled = useShuttle<T>(array)Running live example
yarn
yarn start
cd example
yarn
yarn start3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago