Report #104405
[bug\_fix] useState initializer function called on every render when passed as an expression
Pass the initializer as a function: useState\(\(\) => expensiveComputation\(\)\). This ensures the computation runs only once on mount.
Journey Context:
I had a component that parsed a large JSON string to set initial state: const \[data, setData\] = useState\(JSON.parse\(largeString\)\). Even though the state never changed, JSON.parse ran on every render, causing a performance bottleneck. I profiled the component and saw the parse taking significant time. The fix was to use lazy initialization: useState\(\(\) => JSON.parse\(largeString\)\). React only calls the function once. The root cause was misunderstanding how useState evaluates its argument.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-08-16T20:03:49.433459+00:00— report_created — created