Drop-in upgrade
Swap your imports and keep coding. `useState2` returns the same `[state, setState]` tuple you already know, but plugs in smarter semantics.
React 19 Ready
gReact Hooks keeps everything you love about hooks and layers in modern state ergonomics: immutable snapshots, effortless partial updates, and production-grade utilities.
pnpm add greact-hooks
const [presence, setPresence] = useState2({
status: "offline",
lastSeen: 0,
});
useInterval(() => {
fetchPresence().then(setPresence);
}, 3000);
setPresence({ status: "online" });
Drop in `useState2` and unlock a cleaner state flow immediately. Every hook in the suite is engineered for concurrency-safe React 19 apps.
Swap your imports and keep coding. `useState2` returns the same `[state, setState]` tuple you already know, but plugs in smarter semantics.
Immutable snapshots make accidental mutations a thing of the past. Inspect state confidently in devtools and concurrent renders.
Update only what changed. Pass a patch object or a functional updater — we merge the rest so you can stay focused on the UI.
ES module builds ship with types and zero runtime baggage. Pick the hooks you need and your bundle stays lean.
`useState2` introduces partial merging and read-only snapshots while staying fully backwards compatible. It is the evolution of state management you always wanted — designed to thrive in the age of concurrent rendering.
Everything you need to integrate gReact Hooks today.
Smart state with immutable reads and ergonomic writes. Works as a drop-in replacement for React's `useState`.
const [state, setState] = useState2(initialState);
setState(nextValue | patch | updater);
const [todo, setTodo] = useState2({ title: "", done: false });
setTodo({ done: true });
setTodo((prev) => ({ ...prev, title: prev.title.trim() }));
Run logic on a stable cadence without manual cleanup. Pause by passing `null` for the delay.
useInterval(callback: () => void, delay: number | null);
const [tick, setTick] = useState2(0);
useInterval(() => setTick((n) => n + 1), 1000);
Safely access the global console while providing a no-op fallback when it is
unavailable (such as during SSR or in locked-down environments).
const consoleApi = useConsole();
consoleApi.log("ready");
console object when present.log, warn, and error methods otherwise.console.Validates that an injected hook is well-formed and runs it through a stable callback so you can expose hook extension points without compromising React's naming rules.
const runHook = useHook({ hook: providedHook, name: "useProvided" });
runHook();
hook is not a function.use prefix on the name so React tooling stays accurate.hook or name changes.
Perform imperative navigation by assigning to window.location.href. Handy for
redirects outside router contexts.
useNavigate("/dashboard");
Manage boolean state with a stable toggler backed by useState2. Perfect for
modals, dropdowns, and other show/hide UI behaviours.
const [isOpen, toggle] = useToggleToggle(false);
false when no initial state is provided.toggle flips the state each time it is invoked.toggle reference across renders.