A collection of powerful, reusable custom React hooks for complex, non-trivial interactions that go beyond Reactβs native features.
Built with performance and developer ergonomics in mind, these hooks help you accelerate development and build more interactive experiences effortlessly.
- π Fully typed with TypeScript
- π§ Designed for advanced and non-standard use cases
- π§Ή Pluggable and composable React hooks
- π§ Minimal dependencies, lightweight and tree-shakable
- π Open-source and community-driven
npm install react-hooks-bankOr using yarn:
yarn add react-hooks-bankImport the hooks you need and use them in your components:
import { useInfiniteScroll } from "react-hooks-bank"; const MyComponent = () => { const isLoading = useInfiniteScroll(() => { // Callback when scroll reaches threshold fetchMoreItems(); }); return ( <div> {/* Your list rendering */} {isLoading && <p>Loading more...</p>} </div> ); };Click a hook to jump to detailed usage instructions:
useClickOutsideuseDebouncedValueuseFetchuseGeolocationuseHoveruseInfiniteScrolluseIntersectionObserveruseLockBodyScrolluseNetworkStatususeThrottleuseDeviceInfouseOrientationuseCopyToClipboard
Purpose: Detect clicks outside a specific DOM element.
How to use:
const ref = useRef(null); useClickOutside(ref, () => console.log("Clicked outside!"));Returns: void
Parameters:
ref: RefObject<HTMLElement>- Required: Element to monitorcallback: () => void- Required: Triggered when clicking outside
Purpose: Return a debounced version of a value.
How to use:
const debouncedValue = useDebouncedValue(searchTerm, 500);Returns: any β Debounced value
Parameters:
value: anyβ Required: The value to debouncedelay: numberβ Required: Delay in ms
Purpose: Fetch data with loading and error state.
How to use:
const { data, loading, error } = useFetch('/api/data');Returns: { data, loading, error }
Parameters:
url: stringβ Required: Endpoint URLoptions?: RequestInitβ Optional fetch options
Purpose: Track user's geolocation.
How to use:
const { coords, error } = useGeolocation();Returns: { coords, error }
Parameters:
options?: PositionOptionsβ Optional navigator geolocation options
Purpose: Detect hover state on an element.
How to use:
const { ref, hovered } = useHover();Returns: { ref, hovered }
Parameters: None
Purpose: Trigger callback when scrolled to bottom threshold.
How to use:
const isLoading = useInfiniteScroll(() => loadMoreItems());Returns: boolean β true if loading
Parameters:
callback: () => voidβ Requiredthreshold?: numberβ Distance in px to bottom (default: 100)
Purpose: Observe if an element is visible in viewport.
How to use:
const { ref, entry } = useIntersectionObserver();Returns: { ref, entry }
Parameters:
options?: IntersectionObserverInit
Purpose: Prevent body scroll when active.
How to use:
useLockBodyScroll();Returns: void
Parameters: None
Purpose: Detect online/offline network status.
How to use:
const isOnline = useNetworkStatus();Returns: boolean
Parameters: None
Purpose: Throttle a value change over time.
How to use:
const throttled = useThrottle(value, 300);Returns: any β Throttled value
Parameters:
value: anyβ Requireddelay: numberβ Required
Purpose: Retrieve device OS, browser, and screen info.
How to use:
const { os, browser, screen } = useDeviceInfo();Returns: { os, browser, screen }
Parameters: None
Purpose: Track screen orientation and angle.
How to use:
const { angle, type } = useOrientation();Returns: { angle: number, type: string }
Parameters: None
Purpose: Simplifies copying text to the userβs clipboard and reporting success/failure.
How to use:
const [ copy, isCopied ] = useCopyToClipboard();Returns: [ copy: (text: string) => Promise<boolean>, isCopied: boolean ]
Parameters: None
To run the project locally:
git clone https://github.com/mysticwillz/react-hooks-bank.git cd react-hooks-bank npm install npm run buildContributions are very welcome!
If you'd like to add a new hook, improve documentation, or fix a bug:
- Fork the repo
- Create a new branch
- Submit a PR
Please follow the guidelines in CONTRIBUTING.md.
This project is licensed under the MIT License
Built with β€οΈ by Eze Williams Ezebuilo
- Twitter: @mysticwillz
- LinkedIn: mysticwillz
If this project helps you or youβd like to collaborate, star the repo and share it with other developers!