midReact Hooks
What is lazy initialization in useState?
Updated May 6, 2026
Short answer
Lazy initialization computes initial state only once.
Deep explanation
A function is passed to useState to avoid recalculating expensive initial state.
Real-world example
Loading cached data from localStorage.
Common mistakes
- Calling expensive functions directly in useState.
Follow-up questions
- When is lazy init useful?
- Does it run on every render?