Package Exports
- react-use
- react-use/lib/useAsync
- react-use/lib/useAudio
- react-use/lib/useBoolean
- react-use/lib/useDebounce
- react-use/lib/useGetSetState
- react-use/lib/useHoverDirty
- react-use/lib/useIdle
- react-use/lib/useKeyPressEvent
- react-use/lib/useList
- react-use/lib/useLocalStorage
- react-use/lib/useLocation
- react-use/lib/useLockBodyScroll
- react-use/lib/useMedia
- react-use/lib/useObservable
- react-use/lib/useOutsideClick
- react-use/lib/useRefMounted
- react-use/lib/useScroll
- react-use/lib/useSetState
- react-use/lib/useSpring
- react-use/lib/useToggle
- react-use/lib/useUpdateEffect
- react-use/lib/useVideo
- react-use/lib/useWindowSize
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-use) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
👍
react-use
Collection of essential React Hooks. Port of
libreact
. See demos.
Translations: 🇨🇳 汉语
npm i react-use
- Sensors
useBattery
— tracks device battery state.useGeolocation
— tracks geo location state of user's device.useHover
anduseHoverDirty
— tracks mouse hover state of some element.useIdle
— tracks whether user is being inactive.useKeyPress
— tracks whether a keyboard key—or set of keys—was pressed.useKeyPressEvent
— callonKeyDown
andonKeyUp
callbacks, when key pressed.useLocation
— tracks page navigation bar location state.useMedia
— tracks state of a CSS media query.useMediaDevices
— tracks state of connected hardware devices.useMotion
— tracks state of device's motion sensor.useNetwork
— tracks state of user's internet connection.useOrientation
— tracks state of device's screen orientation.useScroll
— tracks some HTML element's scroll position.useSize
— tracks some HTML element's dimensions.useWindowScroll
— tracksWindow
scroll position.useWindowSize
— tracksWindow
dimensions.
- UI
useAudio
— plays audio and exposes its controls.useOutsideClick
— triggers callback when user clicks outside target area.useSpeech
— synthesizes speech from a text string.useVideo
— plays video, tracks its state, and exposes playback controls.useWait
— complex waiting management for UIs.
- Animations
useRaf
— re-renders component on eachrequestAnimationFrame
.useSpring
— interpolates 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
useAsync
— resolves anasync
function.useAsyncRetry
—useAsync
withretry()
method.useCss
— dynamically adjusts CSS.useFavicon
— sets favicon of the page.useLocalStorage
— manages a value inlocalStorage
.useLockBodyScroll
— lock scrolling of the body element.useSessionStorage
— manages a value insessionStorage
.useTitle
— sets title of the page.useDebounce
— debounces a function.
- Lifecycles
useLifecycles
— callsmount
andunmount
callbacks.useRefMounted
— tracks if component is mounted.usePromise
— resolves promise only while component is mounted.useLogger
— logs in console as component goes through life-cycles.useMount
— callsmount
callbacks.useUnmount
— callsunmount
callbacks.useUpdateEffect
— run aneffect
only on updates.
- State
createMemo
— factory of memoized hooks.useCallbag
— tracks latest value of a callbag.useGetSet
— returns state getterget()
instead of raw state.useGetSetState
— as ifuseGetSet
anduseSetState
had a baby.useObservable
— tracks latest value of anObservable
.useSetState
— createssetState
method which works likethis.setState
.useToggle
anduseBoolean
— tracks state of a boolean.useCounter
anduseNumber
— tracks state of a number.useList
— tracks state of an array.useMap
— tracks state of an object.
Usage
You need to have React 16.8.1
or later installed to use Hooks API.
You can import each hook individually import useToggle from 'react-use/lib/useToggle'
.
License
Unlicense — public domain.