Repository navigation
How Hooks Are Designed
github-actions[bot] edited this page Sep 28, 2026
·
1 revision
Design rules for public hooks in src/hooks/.
-
Named export matching the file (
export function useBoolean/export const useConfirm). - Re-export from
src/index.tsso the package surface stays explicit. - Prefer interfaces for options/return object shapes; union types (not enums) for closed sets of strings.
- Avoid
any. Preferunknownand narrow at the boundary.
- No new runtime dependency unless the hook cannot work without it. Prefer peer React APIs.
- Keep each hook file under ~150 lines. Extract shared UI (e.g.
dialogFrame.tsx) when overlays share markup. - Overlay / dialog hooks that need DOM portals use
react-domand ship as.tsx.
Browser-facing hooks should:
- Return a safe default when
typeof window === 'undefined'. - Subscribe to listeners / storage / observers after mount (effects), so hydration does not fight the server render.
Overlay hooks (useConfirm, usePrompt, useOverlay, useStepFlow) are client-oriented: callers mount render() in the tree on the client.
- Prefer declarative controls: e.g.
useInterval/useTimeoutpause withnulldelay rather than imperative start/stop-only APIs. - Stable function identity where it matters (
useStableCallback, event hooks) so consumers can pass handlers without effect churn. - Public helpers must not introduce XSS (no
dangerouslySetInnerHTMLfrom untrusted strings) or unexpected cross-origin storage leakage.
Every public hook is documented in the playground with catalog entry, description, API table, and demo. The wiki does not replace that documentation.