Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork220
Essential React custom hooks ⚓ to super charge your components!
License
NotificationsYou must be signed in to change notification settings
imbhargav5/rooks
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
- useAsyncEffect - A version of useEffect that accepts an async function
- useDeepCompareEffect - Deep compare dependencies instead of shallow for useEffect
- useDidMount - componentDidMount hook for React
- useDidUpdate - componentDidUpdate hook for react
- useDocumentTitle - A hook to easily update document title with React
- useEffectOnceWhen - Runs a callback effect atmost one time when a condition becomes true
- useIntervalWhen - Sets an interval immediately when a condition is true
- useIsomorphicEffect - A hook that resolves to useEffect on the server and useLayoutEffect on the client.
- useLifecycleLogger - A react hook that console logs parameters as component transitions through lifecycles.
- useLockBodyScroll - This hook locks the scroll of the body element when
isLocked
is set totrue
. - useMouseMoveDelta - Tracks delta of mouse move
- useMouseWheelDelta - Tracks delta of mouse move
- useWillUnmount - componentWillUnmount lifecycle as hook for React.
- useDocumentEventListener - A react hook to an event listener to the document object
- useDocumentVisibilityState - Returns the visibility state of the document.
- useFocus - Handles focus events for the immediate target element.
- useFocusWithin - Handles focus events for the target component.
- useIsDroppingFiles - Check if any files are currently being dropped anywhere. Useful for highlighting drop areas.
- useOnClickRef - Callback on click/tap events
- useOnHoverRef - On hover callback hook
- useOnLongHover - Fires a callback when an element is hovered for a while
- useOnLongPress - Fire a callback on long press
- useOnWindowResize - A React hook for adding an event listener for window resize
- useOnWindowScroll - A React hook for adding an event listener for window scroll
- useOutsideClick - Outside click(for a ref) event as hook for React.
- useOutsideClickRef - A hook that can track a click event outside a ref. Returns a callbackRef.
- useWindowEventListener - Adds an event listener to window
- useFileDropRef - Drop files easily
- useInput - Input hook for React.
- useDebounce - Debounce hook for react
- useDebouncedValue - Tracks another value and gets updated in a debounced way.
- useDebounceFn - Powerful debounce function hook for React
- useDimensionsRef - Easily grab dimensions of an element with a ref using this hook
- 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
- useIdleDetectionApi - Hook to detect when user is idle using Idle Detection API with polyfill
- useMergeRefs - Merges any number of refs into a single ref
- useOrientation - orientation hook for react
- useRefElement - Helps bridge gap between callback ref and state
- useRenderCount - Get the render count of a component
- useSpeech - Speech synthesis hook for React
- useThrottle - Throttle custom hook for React
- useTimeoutWhen - Takes a callback and fires it when a condition is true
- useToggle - Toggle (between booleans or custom data)hook for React.
- useVibrate - Vibration API hook for React
- useWebLocksApi - Hook for coordinating operations across tabs/workers with Web Locks API
- useWhyDidYouUpdate - A hook that can track which value change caused a rerender
- useNavigatorLanguage - Navigator Language hook for React.
- useOnline - Online status hook for React.
- 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.
- 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.
- useIntersectionObserverRef - A hook to register an intersection observer listener.
- useInViewRef - Simple hook that monitors element enters or leave the viewport that's using Intersection Observer API.
- 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.
✅ Collection of 93 hooks as standalone modules.
✅ Standalone package with all the hooks at one place
✅ CommonJS, UMD and ESM Support
npm i -s rooks
Import any hook from "rooks" and start using them!
import{useDidMount}from"rooks";
functionApp(){useDidMount(()=>{alert("mounted");});return(<divclassName="App"><h1>Hello CodeSandbox</h1><h2>Start editing to see some magic happen!</h2></div>);}
Package containing all the hooks is over here. -Docs andNpm Install
MIT
Thanks goes to these wonderful people (emoji key):
These are some libraries that I constantly take inspiration and ideas from
About
Essential React custom hooks ⚓ to super charge your components!
Topics
Resources
License
Code of conduct
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
No packages published