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