ReReact · Lesson 3 of 8
State & useState
State is a component's memory. Unlike props (which come from outside), state lives inside the component and triggers a re-render when it changes. `useState` is the hook you'll use constantly.
⚠ Warning
Never mutate state directly: `state.count++` or `state.items.push(x)`. React uses reference equality to detect changes — mutating the existing object means React sees the same reference and skips the re-render. Always create new objects/arrays: `setState(prev => ({ ...prev, count: prev.count + 1 }))`.
Never mutate state directly: `state.count++` or `state.items.push(x)`. React uses reference equality to detect changes — mutating the existing object means React sees the same reference and skips the re-render. Always create new objects/arrays: `setState(prev => ({ ...prev, count: prev.count + 1 }))`.