Introduction
A comprehensive React Hooks Collection built with Shadcn
What is Shadcn Hooks?
Shadcn Hooks is a carefully curated collection of modern React hooks designed to enhance your development experience. Built with the same philosophy as Shadcn UI, this collection provides high-quality, TypeScript-first hooks that are production-ready and follow React best practices.
Key Features
- TypeScript First: All hooks are written in TypeScript with full type safety
- SSR Compatible: Hooks work seamlessly with server-side rendering
- Modern React: Built for React 19+ with latest patterns and optimizations
- Zero Dependencies: Most hooks have minimal or no external dependencies
- Tree Shakeable: Import only what you need
- Well Tested: Each hook is thoroughly tested and documented
Hook Categories
State Management
useBoolean- Toggle boolean values with semantic methodsuseControllableValue- Manage a controllable valueuseCounter- Create and manage counter state with increment, decrement, and resetuseDebounce- A hook to debounce a valueuseThrottle- A hook to throttle a valueuseToggle- Simple boolean toggle functionality
Advanced
useCreation- Create a value only onceuseCustomCompareEffect- Effect with custom compare functionuseLatest- Always get the latest value in closuresuseLockFn- Prevent concurrent function callsuseMemoizedFn- Memoize function referencesusePrevious- Get the previous value of a state
Lifecycle & Effects
useDebounceEffect- A hook to debounce an effectuseDebounceFn- A hook to debounce a functionuseDeepCompareEffect- Effect with deep comparison of dependenciesuseDeepCompareLayoutEffect- Layout effect with deep comparisonuseEffectEvent- Stable event handlers for effectsuseEffectWithTarget- A hook to create an effect with a target element that re-runs when the target or dependencies changeuseInterval- A hook to create an intervaluseIsHydrated- Detect client-side hydrationuseIsomorphicLayoutEffect- SSR-safe layout effectsuseMount- Execute code on component mountuseThrottleEffect- A hook to throttle an effectuseThrottleFn- A hook to throttle a functionuseTimeout- A hook to create a timeoutuseUnmount- Execute cleanup on component unmountuseUpdate- Force a component to re-renderuseUpdateEffect- Run an effect only when the component updates
Browser
useClickAnyWhere- Attach a click event listener to the documentuseClickAway- A hook to click away from an elementuseEventListener- Attach event listeners to DOM elements, the window, or media query lists.useFps- Calculate the FPS of the browseruseHash- Track URL hash changesuseHover- Check if the mouse is hovering over an elementuseInViewport- Check if an element is in the viewportuseIsMatchMedia- React to media query changesuseIsOnline- Monitor online/offline statususeNetwork- Monitor network state
Dev
useWhyDidYouUpdate- A hook to log the props that changed in a component
External Libraries
useMcp- Model Context Protocol integrationuseQuery- TanStack Query integrationuseStickToBottom- A lightweight React Hook intended mainly for AI chat applications, for smoothly sticking to bottom of messagesuseSWR- SWR data fetching
Getting Started
Each hook comes with:
- CLI Installation: Use the shadcn CLI for easy setup
- Manual Installation: Copy-paste the source code
- TypeScript Support: Full type definitions included
- Documentation: Comprehensive examples and usage patterns
Design Philosophy
Shadcn Hooks follows the same principles as Shadcn UI:
- Copy, don't fork: Own your code
- Minimal dependencies: Keep bundles small
- Modern patterns: Use latest React features
- Developer experience: Great TypeScript support and documentation
Credits
This collection is inspired by and builds upon the excellent work of:
- ahooks - Comprehensive React hooks library
- usehooks-ts - TypeScript-first hooks collection
Last updated on