# ReactUse (@reactuses/core) ReactUse is a comprehensive collection of 100+ essential React Hooks for building modern React applications, inspired by VueUse. It provides production-ready, tree-shakable hooks organized into four categories — Browser, State, Element, and Effect — covering everything from clipboard access and media queries to drag-and-drop, intersection observation, and async effects. The library is fully typed with TypeScript, SSR-compatible for use with Next.js and Remix, and ships with an optional MCP (Model Context Protocol) server for AI-powered hook discovery. At its core, the library follows a consistent design philosophy: hooks accept `BasicTarget` values (refs, direct elements, or selector functions) for flexible DOM targeting; browser-environment checks prevent SSR crashes; event listeners and observers are cleaned up automatically; and stable function references via `useEvent`/`useLatest` eliminate common infinite-render pitfalls. Version 6.3.1 (the current release) requires React 19 as a peer dependency and supports concurrent mode. --- ## Installation ```bash npm i @reactuses/core # or pnpm add @reactuses/core # or yarn add @reactuses/core ``` --- ## State Hooks ### useToggle — toggle a boolean on/off Manages a boolean value and returns a toggler that optionally accepts a forced value. ```tsx import { useToggle } from "@reactuses/core"; function ToggleDemo() { const [on, toggle] = useToggle(false); return (

Status: {on ? "ON" : "OFF"}

); } ``` --- ### useBoolean — boolean state with named helpers Returns an object with `setTrue`, `setFalse`, and `toggle` for ergonomic boolean state management. ```tsx import { useBoolean } from "@reactuses/core"; function Modal() { const { value: isOpen, setTrue: open, setFalse: close, toggle } = useBoolean(false); return ( <> {isOpen && (

Modal content

)} ); } ``` --- ### useCounter — numeric counter with bounds Provides increment, decrement, set, and reset with optional min/max clamping. ```tsx import { useCounter } from "@reactuses/core"; function CounterDemo() { const [count, setCount, inc, dec, reset] = useCounter(0, 10, 0); // max=10, min=0 return (

Count: {count}

); } ``` --- ### useMap — reactive Map data structure Wraps `Map` with reactive state and convenience methods: `set`, `get`, `remove`, `has`, `clear`, `reset`. ```tsx import { useMap } from "@reactuses/core"; function MapDemo() { const { map, set, get, remove, has, clear, size } = useMap([ ["apples", 5], ["oranges", 3], ]); return (

Items: {size}

Apples: {get("apples")}

); } ``` --- ### useLocalStorage — persistent state synced to localStorage Persists state across page reloads and syncs changes across browser tabs in real time. ```tsx import { useLocalStorage } from "@reactuses/core"; interface UserPrefs { theme: "light" | "dark"; fontSize: number; } function Settings() { const [prefs, setPrefs] = useLocalStorage("user-prefs", { theme: "light", fontSize: 16, }, { listenToStorageChanges: true, // sync across tabs (default: true) onError: (err) => console.error("Storage error:", err), }); return (

Theme: {prefs?.theme}

); } ``` --- ### useSessionStorage — session-scoped persistent state Identical API to `useLocalStorage` but backed by `sessionStorage` (cleared when tab closes). ```tsx import { useSessionStorage } from "@reactuses/core"; function WizardStep() { const [step, setStep] = useSessionStorage("wizard-step", 1); return (

Current step: {step}

); } ``` --- ### useDebounce — debounce a reactive value Returns a debounced copy of a value that only updates after the specified delay has passed without changes. ```tsx import { useDebounce } from "@reactuses/core"; import { useState } from "react"; function SearchInput() { const [query, setQuery] = useState(""); const debouncedQuery = useDebounce(query, 400); // debouncedQuery only changes 400ms after the user stops typing useEffect(() => { if (debouncedQuery) fetchResults(debouncedQuery); }, [debouncedQuery]); return setQuery(e.target.value)} />; } ``` --- ### useDebounceFn — debounce a callback function Returns a `{ run, cancel, flush }` object wrapping a debounced version of the provided function. ```tsx import { useDebounceFn } from "@reactuses/core"; function AutoSave({ onSave }: { onSave: (data: string) => void }) { const { run: save, cancel, flush } = useDebounceFn(onSave, 1000); return (