Guides

Standard Usage Patterns

HookNest follows a standardized return pattern for all hooks, ensuring predictable state management across your entire application.

Stateful Hooks

Hooks like `useToggle` and `useLocalStorage` return an array containing the state and its setter/switcher.

StatefulPattern.js
const [isActive, toggle] = useToggle(false);
const [name, setName] = useLocalStorage('user_key', 'Default');

Event Listeners

Event-based hooks like `useOnClickOutside` require a ref to properly track interactions.

EventPattern.js
const modalRef = useRef(null);
useOnClickOutside(modalRef, () => setIsOpen(false));

SSR WARNING

When using Next.js App Router, ensure you use the "use client" directive at the top of your file to avoid hydration errors with browser-specific hooks like `useLocalStorage`.