1.3.3-beta.0 • Published 4 years ago

@vincecao/use-tools v1.3.3-beta.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

use-tools

npm version npm.io

Installation

# npm
npm i @vincecao/use-tools

# yarn
yarn add @vincecao/use-tools

Demo

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 start
1.6.1

3 years ago

1.6.0

3 years ago

1.3.7

4 years ago

1.3.6

4 years ago

1.3.5

4 years ago

1.5.2

4 years ago

1.3.4

4 years ago

1.5.1

4 years ago

1.3.3

4 years ago

1.5.0

4 years ago

1.3.2

4 years ago

1.4.0

4 years ago

1.3.1

4 years ago

1.3.4-alpha.1

4 years ago

1.3.4-alpha.0

4 years ago

1.3.6-beta.0

4 years ago

1.3.5-beta.0

4 years ago

1.3.4-beta.0

4 years ago

1.3.3-beta.1

4 years ago

1.3.1-beta.1

4 years ago

1.3.5-beta.1

4 years ago

1.3.3-beta.0

4 years ago

1.3.2-beta.0

4 years ago

1.3.4-beta.4

4 years ago

1.3.4-beta.3

4 years ago

1.3.4-beta.2

4 years ago

1.3.4-beta.1

4 years ago

1.3.4-beta.5

4 years ago

1.3.8

4 years ago

1.3.1-beta.0

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago