Rendering and Performance
7 pages · ~5 min✓ Reviewed
Builds on Effects and Data Fetching.
What Triggers a Re-render
1. Render vs DOM update
- A render = React calls your component to compute JSX
- A render can end with zero DOM changes
- The DOM is touched only at commit
2. What triggers one
| Trigger | Re-render? |
|---|---|
| Own state setter | yes |
| Parent re-renders | yes, all children |
| Consumed context changes | yes |
| Props change alone | no, not a trigger |
- Child re-renders even with identical props
- Skip it by wrapping the child in React.memo
3. Mistake: mutating state
jsx
items.push(4) // mutated in place setItems(items) // Object.is same: skipped setItems([...items, 4]) // new array: updates
Same reference = bail-out
React compares with Object.is. Always pass a new array or object.