React Core · 8 min read · Intermediate
State & Immutable Updates (useState)
Manage interactive UI state with useState, functional updaters (prev => prev + 1), and immutable array/object updates.
What you'll learn
- Declare component state with const [value, setValue] = useState(initial)
- Use functional updates setCount(c => c + 1) when new state depends on previous state
- Update arrays and objects immutably with spread (...) and .filter()/.map()
React detects state changes by comparing object references (Object.is). If you mutate an array in place (items.push(x); setItems(items)), React sees the exact same array reference and skips re-rendering. Always create a fresh copy: setItems(prev => [...prev, x]).
Fill-in-the-Blank Exercise
Functional State Update
Initialize count to 0 with useState and increment using a functional updater.
const [count, setCount] = (0);
const increment = () => setCount( => prev + 1);Live Interactive State Demo
JSXLive useState & Immutable Array Update
Live React Preview
Check Your Understanding
Score: 0 / 1
1. Why does items.push(newItem); setItems(items); fail to trigger a React re-render?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.