2019-04-02 20:02:13 +11:00
2019-03-28 17:47:38 +01:00
2019-04-02 20:02:13 +11:00
2019-04-02 20:02:13 +11:00
2018-10-29 23:11:53 +01:00
2019-03-31 13:23:22 +00:00
2018-10-27 12:15:13 +02:00
2019-03-31 13:23:22 +00:00
2019-04-02 20:02:13 +11:00
2019-02-24 16:00:48 +01:00
2019-03-13 20:58:57 +01:00

👍 react-use

npm package npm downloads demos

A collection of essential React Hooks.

Setup

You need to have React 16.8.0 or later installed to use the Hooks API.

npm i react-use

Sensors

UI

  • useAudio — play audio, track its state and hook up controls
  • useClickAway — trigger callback when user clicks outside target area
  • useCss — dynamically adjusts CSS
  • useDrop and useDropArea — track file, link and copy-paste drops
  • useFullscreen — display an element or video full-screen
  • useSpeech — synthesize speech audio from a text string
  • useVideo — play video, track its state and hook up playback controls
  • useWait — complex waiting management for UIs

Animation

  • useRaf — re-render component on each requestAnimationFrame
  • useSpring — interpolate number over time according to spring dynamics
  • useTimeout — returns true after a timeout
  • useTween — re-renders component, while tweening a number from 0 to 1
  • useUpdate — returns a callback, which re-renders component when called

Side-effects

Lifecycle

State

Usage

You can import each hook individually

import useToggle from 'react-use/lib/useToggle'

or use ES6 named import

import {useToggle} from 'react-use'

Depending on your bundler you might run into a missing dependency error. Some hooks require you to install peer dependencies so we recommend using individual imports. If you want the best of both worlds you can transform the named import statements to individual import statements with babel-plugin-import by adding the following config to your .babelrc file

[
  "import", {
    "libraryName": "react-use",
    "libraryDirectory": "lib",
    "camel2DashComponentName": false
  }
]

Translations

🇨🇳_汉语

License

Unlicense — public domain.

Description
React Hooks — 👍
Readme Unlicense 146 MiB
Languages
TypeScript 99.6%
JavaScript 0.4%