Custom Hooks visual mental model
A custom Hook reuses behavior, not one shared state instance.
Component A
useOnlineStatus()
A's own state + Effect lifecycle
Component B
useOnlineStatus()
B's own state + Effect lifecycle
What extraction changes
Before extraction
Component owns listener setup, cleanup, state, timers, derived flags, and JSX.
After extraction
Custom Hook owns reusable React mechanics. Component keeps UI and domain intent visible.
Hooks compose other Hooks
Component
asks for a domain capability
useDashboardData(userId)
combines focused reusable behavior
useOnlineStatus
usePreferences
useNotifications
React primitives + external systems
state · Effects · refs · Context · subscriptions
A Hook is an API
Leaky API
Exposes internal setters, refs, loading flags, and unrelated responsibilities.
Domain API
Exposes meaningful values and operations such as signIn, signOut, reload, or selectPlan.
Should this become a custom Hook?
Repeated stateful React behavior?Good extraction candidate
Reusable browser/external integration?Good extraction candidate
Pure calculation with no Hooks?Normal helper function
Several unrelated Effects hidden together?Split responsibilities first
Only reason is file length?Not enough reason by itself
Hooks do not make state global
Custom Hook implementation
Caller A state
Caller B state
Caller C state
Choose shared ownership architecture
Context · external store · shared cache · framework data owner
Continue with Custom Hooks for API design, Effect Events, testing, platform constraints, and production examples.