Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

rooks

imbhargav5396kMIT8.0.1TypeScript support: included

Essential React custom hooks ⚓ to super charge your components!

react, hooks, custom, custom-hooks, typescript, react-hooks

readme




CI and Semantic Release GitHub GitHub release (latest by date) GitHub contributors npm npm bundle size Codecov branch node-lts Website Module




Essential React custom hooks ⚓ to super charge your components!



List of all hooks

🔥 Effects

🚀 Events

📝 Form

✨ Misc

🚃 Navigator

❇️ State

  • useArrayState - Array state manager hook for React
  • useCountdown - Count down to a target timestamp and call callbacks every second (or provided peried)
  • useCounter - Counter hook for React.
  • useGetIsMounted - Checks if a component is mounted or not at the time. Useful for async effects
  • useLocalstorageState - UseState but auto updates values to localStorage
  • useMapState - A react hook to manage state in a key value pair map.
  • useMultiSelectableList - A custom hook to easily select multiple values from a list
  • useNativeMapState - Manage Map() object state in React
  • usePreviousDifferent - usePreviousDifferent returns the last different value of a variable
  • usePreviousImmediate - usePreviousImmediate returns the previous value of a variable even if it was the same or different
  • usePromise - Promise management hook for react
  • useQueueState - A React hook that manages state in the form of a queue
  • useSafeSetState - set state but ignores if component has already unmounted
  • useSelect - Select values from a list easily. List selection hook for react.
  • useSelectableList - Easily select a single value from a list of values. very useful for radio buttons, select inputs etc.
  • useSessionstorageState - useState but syncs with sessionstorage
  • useSetState - Manage the state of a Set in React.
  • useStackState - A React hook that manages state in the form of a stack
  • useTimeTravelState - A hook that manages state which can undo and redo. A more powerful version of useUndoState hook.
  • useUndoRedoState - Setstate but can also undo and redo
  • useUndoState - Drop in replacement for useState hook but with undo functionality.

⚛️ UI

  • useAudio - Audio hook
  • useBoundingclientrect - getBoundingClientRect hook for React.
  • useBoundingclientrectRef - A hook that tracks the boundingclientrect of an element. It returns a callbackRef so that the element node if changed is easily tracked.
  • useFullscreen - Use full screen api for making beautiful and emersive experinces.
  • useGeolocation - A hook to provide the geolocation info on client side.
  • useInViewRef - Simple hook that monitors element enters or leave the viewport that's using Intersection Observer API.
  • useIntersectionObserverRef - A hook to register an intersection observer listener.
  • useKey - keypress, keyup and keydown event handlers as hooks for react.
  • useKeyBindings - useKeyBindings can bind multiple keys to multiple callbacks and fire the callbacks on key press.
  • useKeyRef - Very similar useKey but it returns a ref
  • useKeys - A hook which allows to setup callbacks when a combination of keys are pressed at the same time.
  • useMediaMatch - Signal whether or not a media query is currently matched.
  • useMouse - Mouse position hook for React.
  • useMutationObserver - Mutation Observer hook for React.
  • useMutationObserverRef - A hook that tracks mutations of an element. It returns a callbackRef.
  • useRaf - A continuously running requestAnimationFrame hook for React
  • useResizeObserverRef - Resize Observer hook for React.
  • useVideo - Video hook for react
  • useWindowScrollPosition - A React hook to get the scroll position of the window
  • useWindowSize - Window size hook for React.


Features

✅ Collection of 91 hooks as standalone modules.

✅ Standalone package with all the hooks at one place

✅ CommonJS, UMD and ESM Support

Installation

npm i -s rooks

Import any hook from "rooks" and start using them!

import { useDidMount } from "rooks";

Usage

function App() {
  useDidMount(() => {
    alert("mounted");
  });
  return (
    <div className="App">
      <h1>Hello CodeSandbox</h1>
      <h2>Start editing to see some magic happen!</h2>
    </div>
  );
}

Standalone Package

Package containing all the hooks is over here. - Docs and Npm Install


License

MIT

Contributors ✨

All Contributors

Thanks goes to these wonderful people (emoji key):


Bhargav Ponnapalli

💻 🚧

anil kumar chaudhary

💻

Qiwei Yang

💻 🚧

maciek_grzybek

💻

Harsh Zalavadiya

💻

B V K MAHIJENDRA

💻

Braxton Christensen

💻

Hansel

💻

Harshil Parmar

💻

Lionel

💻

Max Stoiber

💻

Michael Moore

💻

Rajas Paranjpe

💻

Mahendra Choudhary

💻

Nghia Pham

💻

Akshay Kadam (A2K)

💻

Alex Golubtsov

💻

Arman

💻

Branden Visser

💻

Brian Steere

💻

Cal Courtney

💻

Chris Milson

💻

Cong Zhang

💻

Daniel Holmes

💻

Fernando Beck

💻

Josh Davenport

💻

MARCEL

💻

Neilor Caldeira

💻

Tobias Lins

💻

Tsvetan

💻

Wei Zhu

💻

Yakko Majuri

💻

Frank Hellwig

💻

Austin Peterson

💻

thodubois

💻

wes christiansen

💻

CJ Patoilo

💻

mar1u50

💻

Ayushman Gupta

💻

Rafael Ferreira

💻

Kristinn Thor Johannsson

💻

Michael Moore

💻

Trevor Blades

💻

official_dulin

💻

Billy Mosis Priambodo

💻

Stafford Williams

💻

Chanhee Kim

💻

Hooriza

💻

Nils Wittler

💻

Sebastian Szczepański

💻

Mahendra Choudhary

💻

Som Shekhar Mukherjee

💻

Qiushi Pan

💻

Jishnu Viswanath

💻

brahambence

💻

dependabot[bot]

💻

renovate[bot]

💻

dependabot-preview[bot]

💻

github-actions[bot]

💻

allcontributors[bot]

💻

zhangenming

💻

Antoni Kiszka

💻

Greg Poole

💻

changelog

rooks

8.0.1

Patch Changes

8.0.0

Major Changes

7.14.1

Patch Changes

7.14.0

Minor Changes

7.13.0

Minor Changes

  • 5b90f1b1 Thanks @imbhargav5! - useUndoRedoState: add isUndoPossible, isRedoPossible booleans to controls

7.12.0

Minor Changes

7.11.3

Patch Changes

7.11.2

Patch Changes

7.11.1

Patch Changes

7.11.0

Minor Changes

7.10.1

Patch Changes

7.10.0

Minor Changes

7.9.0

Minor Changes

7.8.5

Patch Changes

7.8.4

Patch Changes

7.8.3

Patch Changes

7.8.2

Patch Changes

7.8.1

Patch Changes

7.8.0

Minor Changes

  • 656e58e7 Thanks @imbhargav5! - added useMapObjectState, useSafeSetState, useDeepCompareEffect

7.7.0

Minor Changes

Patch Changes

7.6.1

Patch Changes

7.6.0

Minor Changes

  • #1583 ac0086dd Thanks @imbhargav5! - add useAudio, useVideo, useOnLongHover, useOnLongPress, useFreshCallback, useFileDropRef, useOrientation, useVibrate, useMouseMoveDelta, useMouseWheelDelta, useIsDroppingFiles hooks

7.5.0

Minor Changes

  • 7773cf47 Thanks @imbhargav5! - useArrayState initializer can be a function returning an array

7.4.4

Patch Changes

  • #1576 33b09d7a Thanks @imbhargav5! - useDebounce bug fixes. It will now work as intended with inline functions. Stale closure bug fixed

7.4.3

Patch Changes

7.4.2

Patch Changes

7.4.1

Patch Changes

7.4.0

Minor Changes

7.3.0

Minor Changes

  • f2ee3a66 Thanks @imbhargav5! - add splice, removeItemAtIndex and replaceItemAtIndex controls for useArrayState

7.2.1

Patch Changes

7.2.0

Minor Changes

7.1.2

Patch Changes

7.1.2-alpha.1

Patch Changes

7.1.2-alpha.0

Patch Changes

7.1.1

Patch Changes

  • bea1ddaf: fix isNumber import in usetimeTravelState

7.1.0

Minor Changes

  • 0dc2004e: New hook! useTimeTravelState hook added which can undo and redo a state variable seamlessly.

7.0.0

Major Changes

  • ae9a465a: useFullscreen hook rewrite

Patch Changes

  • b2003b87: bundle size decrease
  • 886a6721: Make useKey target option support undefined

7.0.0-alpha.2

Patch Changes

  • 886a6721: Make useKey target option support undefined

7.0.0-alpha.1

Patch Changes

  • b2003b87: bundle size decrease

6.4.3

Patch Changes

  • 140fceab: fix dependency checking in useAsyncEffect

7.0.0-alpha.0

Major Changes

  • 9ca2be66: useFullscreen hook rewrite

6.4.2

Patch Changes

  • 47e847ae: bugfix: window (or document) is not defined when using ssr

6.4.1

Patch Changes

  • 19b280fa: decrease bundle size

6.4.0

Minor Changes

  • 182e8498: add useArrayState and useSetState hooks to manage arrays and sets

6.3.0

Minor Changes

  • 2eac1e11: add useFocus & useFocusWithin hooks

6.2.1

Patch Changes

  • e3866ce5: useKeys comes with a new preventLostKeyup option for native events
  • 7aea2fea: Add an opt-in option to prevent useKeys from losing track of keyup.

6.2.0

Minor Changes

  • 11d5b33a: add useResizeObserverRef hook

6.1.0

Minor Changes

  • 33f6630d: add useAsyncEffect and useRenderCount hooks

6.0.1

Major Changes

  • 8b98cf06: useLocalstorage, useSessionstorage, useTimeout, useInterval, usePrevious, useVisibilitySensor, useUpdateEffect hooks removed. Please use useLocalstorageState, useSessionstorageState, useTimeoutWhen, useIntervalWhen, usePreviousImmediate, useInViewRef and useDidUpdate

6.0.0-alpha.0

Major Changes

  • a9d4e0af: useLocalstorage, useSessionstorage, useTimeout, useInterval, usePrevious, useVisibilitySensor, useUpdateEffect hooks removed. Please use useLocalstorageState, useSessionstorageState, useTimeoutWhen, useIntervalWhen, usePreviousImmediate, useInViewRef and useDidUpdate