Skip to content

imbhargav5/rooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 



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




Collection of awesome react hooks



List of all hooks

🎬 Animation & Timing - 5 hooks

  • useIntervalWhen - Sets an interval immediately when a condition is true
  • useLockBodyScroll - This hook locks the scroll of the body element when isLocked is set to true.
  • useRaf - A continuously running requestAnimationFrame hook for React
  • useResizeObserverRef - Resize Observer hook for React.
  • useTimeoutWhen - Takes a callback and fires it when a condition is true

🌐 Browser APIs - 9 hooks

πŸ› οΈ Development & Debugging - 1 hook

πŸš€ Events - 15 hooks

πŸ“ Form & File Handling - 1 hook

⌨️ Keyboard & Input - 5 hooks

  • useInput - Input hook for React.
  • 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.

πŸ”₯ Lifecycle & Effects - 9 hooks

πŸ–±οΈ Mouse & Touch - 3 hooks

⚑ Performance & Optimization - 4 hooks

❇️ State - 18 hooks

  • 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

πŸ”„ State History & Time Travel - 4 hooks

  • useTimeTravelState - A hook that manages state which can undo and redo. A more powerful version of useUndoState hook.
  • useToggle - Toggle (between booleans or custom data)hook for React.
  • useUndoRedoState - Setstate but can also undo and redo
  • useUndoState - Drop in replacement for useState hook but with undo functionality.

βš›οΈ UI - 12 hooks

πŸ”§ Utilities & Refs - 7 hooks

  • useEventListenerRef - A react hook to add an event listener to a ref
  • useForkRef - A hook that can combine two refs(mutable or callbackRefs) into a single callbackRef
  • useFreshCallback - Avoid stale closures and keep your callback fresh
  • useFreshRef - Avoid stale state in callbacks with this hook. Auto updates values using a ref.
  • useFreshTick - Like use-fresh-ref but specifically for functions
  • useMergeRefs - Merges any number of refs into a single ref
  • useRefElement - Helps bridge gap between callback ref and state

πŸ“± Window & Viewport - 2 hooks

πŸ§ͺ Experimental Hooks - 4 hooks

⚠️ Experimental hooks may be removed or significantly changed in any release without notice. Use with caution in production.



Features

βœ… Collection of 99 hooks as standalone modules.

βœ… Standalone package with all the hooks at one place

βœ… Built for ESM

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
Bhargav Ponnapalli

πŸ’» 🚧
anil kumar chaudhary
anil kumar chaudhary

πŸ’»
Qiwei Yang
Qiwei Yang

πŸ’» 🚧
maciek_grzybek
maciek_grzybek

πŸ’»
Harsh Zalavadiya
Harsh Zalavadiya

πŸ’»
B V K MAHIJENDRA
B V K MAHIJENDRA

πŸ’»
Braxton Christensen
Braxton Christensen

πŸ’»
Hansel
Hansel

πŸ’»
Harshil Parmar
Harshil Parmar

πŸ’»
Lionel
Lionel

πŸ’»
Max Stoiber
Max Stoiber

πŸ’»
Michael Moore
Michael Moore

πŸ’»
Rajas Paranjpe
Rajas Paranjpe

πŸ’»
Mahendra Choudhary
Mahendra Choudhary

πŸ’»
Nghia Pham
Nghia Pham

πŸ’»
Akshay Kadam (A2K)
Akshay Kadam (A2K)

πŸ’»
Alex Golubtsov
Alex Golubtsov

πŸ’»
Arman
Arman

πŸ’»
Branden Visser
Branden Visser

πŸ’»
Brian Steere
Brian Steere

πŸ’»
Cal Courtney
Cal Courtney

πŸ’»
Chris Milson
Chris Milson

πŸ’»
Cong Zhang
Cong Zhang

πŸ’»
Daniel Holmes
Daniel Holmes

πŸ’»
Fernando Beck
Fernando Beck

πŸ’»
Josh Davenport
Josh Davenport

πŸ’»
MARCEL
MARCEL

πŸ’»
Neilor Caldeira
Neilor Caldeira

πŸ’»
Tobias Lins
Tobias Lins

πŸ’»
Tsvetan
Tsvetan

πŸ’»
Wei Zhu
Wei Zhu

πŸ’»
Yakko Majuri
Yakko Majuri

πŸ’»
Frank Hellwig
Frank Hellwig

πŸ’»
Austin Peterson
Austin Peterson

πŸ’»
thodubois
thodubois

πŸ’»
wes christiansen
wes christiansen

πŸ’»
CJ Patoilo
CJ Patoilo

πŸ’»
mar1u50
mar1u50

πŸ’»
Ayushman Gupta
Ayushman Gupta

πŸ’»
Rafael Ferreira
Rafael Ferreira

πŸ’»
Kristinn Thor Johannsson
Kristinn Thor Johannsson

πŸ’»
Michael Moore
Michael Moore

πŸ’»
Trevor Blades
Trevor Blades

πŸ’»
official_dulin
official_dulin

πŸ’»
Billy Mosis Priambodo
Billy Mosis Priambodo

πŸ’»
Stafford Williams
Stafford Williams

πŸ’»
Chanhee Kim
Chanhee Kim

πŸ’»
Hooriza
Hooriza

πŸ’»
Nils Wittler
Nils Wittler

πŸ’»
Sebastian SzczepaΕ„ski
Sebastian SzczepaΕ„ski

πŸ’»
Mahendra Choudhary
Mahendra Choudhary

πŸ’»
Som Shekhar Mukherjee
Som Shekhar Mukherjee

πŸ’»
Qiushi Pan
Qiushi Pan

πŸ’»
Jishnu Viswanath
Jishnu Viswanath

πŸ’»
brahambence
brahambence

πŸ’»
dependabot[bot]
dependabot[bot]

πŸ’»
renovate[bot]
renovate[bot]

πŸ’»
dependabot-preview[bot]
dependabot-preview[bot]

πŸ’»
github-actions[bot]
github-actions[bot]

πŸ’»
allcontributors[bot]
allcontributors[bot]

πŸ’»
zhangenming
zhangenming

πŸ’»
Antoni Kiszka
Antoni Kiszka

πŸ’»
Greg Poole
Greg Poole

πŸ’»
mergify[bot]
mergify[bot]

πŸ’»
Chaitanya J
Chaitanya J

πŸ’»
G H Mahimaanvita
G H Mahimaanvita

πŸ’»
Danilo Woznica
Danilo Woznica

πŸ’»
dan-klasson
dan-klasson

πŸ’»
SΓ©bastien Vanvelthem
SΓ©bastien Vanvelthem

πŸ’»
Aleksandr Soldatov
Aleksandr Soldatov

πŸ’»
Eli Yukelzon
Eli Yukelzon

πŸ’»
Mahendra Choudhary
Mahendra Choudhary

πŸ’»
Chaitanya J
Chaitanya J

πŸ’»
Dominik Dorfmeister
Dominik Dorfmeister

πŸ’»
Nghiệp
Nghiệp

πŸ’»
Seongmin Park
Seongmin Park

πŸ’»
Nate Higgins
Nate Higgins

πŸ’»
Michael Moore
Michael Moore

πŸ’»
Moritz Brandes
Moritz Brandes

πŸ’»
Som Shekhar Mukherjee
Som Shekhar Mukherjee

πŸ’»
cursor[bot]
cursor[bot]

πŸ’»
JulianWielga
JulianWielga

πŸ’»

Other hooks libraries

These are some libraries that I constantly take inspiration and ideas from

  1. React-use
  2. React-aria
  3. Valtio
  4. Jotai
  5. Recoil
  6. Downshiftjs
  7. React hook form