React Hooks Cheat Sheet/useState lazy initializer

Compute expensive initial state once.

Section: State Hooks

useState lazy initializer

tsx
tsx
const [items, setItems] = useState(() => loadInitialItems());
Explanation

Pass a function to avoid recalculating expensive initial state on every render.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing State Hooks
useState basic state
Create local component state.
OpenIn sheettsxsame section
useState updater function
Update based on previous state safely.
OpenIn sheettsxsame section
Reset component state
Reset state back to initial values.
OpenIn sheettsxsame section
useReducer basic reducer
Manage more structured state transitions.
OpenIn sheettsxsame section
useReducer with init function
Lazily derive reducer state.
OpenIn sheettsxsame section
useMemo memoized derived value
Cache an expensive derived computation.
OpenIn sheettsx3 tag match