The react-use fork for react-native
It doesn't depend on 'react-dom'.
A better choice for React Native development for native apps only.
Collection of essential React Hooks. Port of
libreact.
Translations: π¨π³ ζ±θ―
npm i react-use-native
- Animations
useRafβ re-renders component on eachrequestAnimationFrame.useIntervalβ re-renders component on a set interval usingsetInterval.useTimeoutβ re-renders component after a timeout.useTimeoutFnβ calls given function after a timeout.useUpdateβ returns a callback, which re-renders component when called.
- Side-effects
useAsync,useAsyncFn, anduseAsyncRetryβ resolves anasyncfunction.useDebounceβ debounces a function.useErrorβ error dispatcher.useRafLoopβ calls given function inside the RAF loop.useThrottleanduseThrottleFnβ throttles a function.
- Lifecycles
useEffectOnceβ a modifieduseEffecthook that only runs once.useLifecyclesβ callsmountandunmountcallbacks.useMountedStateanduseUnmountPromiseβ track if component is mounted.usePromiseβ resolves promise only while component is mounted.useLoggerβ logs in console as component goes through life-cycles.useMountβ callsmountcallbacks.useUnmountβ callsunmountcallbacks.useUpdateEffectβ run aneffectonly on updates.useIsomorphicLayoutEffectβuseLayoutEffectthat that works on server.useDeepCompareEffect,useShallowCompareEffect, anduseCustomCompareEffect
- State
createMemoβ factory of memoized hooks.createReducerβ factory of reducer hooks with custom middleware.createReducerContextandcreateStateContextβ factory of hooks for a sharing state between components.useDefaultβ returns the default value when state isnullorundefined.useGetSetβ returns state getterget()instead of raw state.useGetSetStateβ as ifuseGetSetanduseSetStatehad a baby.useLatestβ returns the latest state or propsusePreviousβ returns the previous state or props.usePreviousDistinctβ likeusePreviousbut with a predicate to determine ifpreviousshould update.useObservableβ tracks latest value of anObservable.useRafStateβ createssetStatemethod which only updates afterrequestAnimationFrame.useSetStateβ createssetStatemethod which works likethis.setState.useStateListβ circularly iterates over an array.useToggleanduseBooleanβ tracks state of a boolean.useCounteranduseNumberβ tracks state of a number.useListandβ tracks state of an array.useUpsertuseMapβ tracks state of an object.useSetβ tracks state of a Set.useQueueβ implements simple queue.useStateValidatorβ tracks state of an object.useStateWithHistoryβ stores previous state values and provides handles to travel through them.useMultiStateValidatorβ alike theuseStateValidator, but tracks multiple states at a time.useMediatedStateβ like the regularuseStatebut with mediation by custom function.useFirstMountStateβ check if current render is first.useRendersCountβ count component renders.createGlobalStateβ cross component shared state.useMethodsβ neat alternative touseReducer.
- Miscellaneous
useEnsuredForwardedRefandensuredForwardRefβ use a React.forwardedRef safely.
Usage β how to import.
Unlicense β public domain.
Support β add yourself to backer list below.