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
useCounter- Create and manage counter state with increment, decrement, and resetuseToggle- Simple boolean toggle functionalityuseBoolean- Toggle boolean values with semantic methods
Advanced
useLatest- Always get the latest value in closuresuseLockFn- Prevent concurrent function callsuseMemoizedFn- Memoize function references
Lifecycle & Effects
useMount- Execute code on component mountuseUnmount- Execute cleanup on component unmountuseIsHydrated- Detect client-side hydrationuseEffectEvent- Stable event handlers for effectsuseIsomorphicLayoutEffect- SSR-safe layout effectsuseDeepCompareEffect- Effect with deep comparison of dependenciesuseDeepCompareLayoutEffect- Layout effect with deep comparison
Browser APIs
useHash- Track URL hash changesuseIsOnline- Monitor online/offline statususeIsMatchMedia- React to media query changes
External Libraries
useSWR- SWR data fetchinguseQuery- TanStack Query integrationuseMcp- Model Context Protocol integration
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