Define: Render Purity (React).
List 3 Categories of “Impure” Red Flags in React Render.
localStorage during render.fetch, setTimeout, setCount, or mutating props like props.data.push()).Math.random(), new Date(), or crypto.randomUUID()).React Purity “Red Flag”:
External Dependencies
(The “Global Variable Trap”)
Reading/writing variables defined outside the function or localStorage during render.
React Purity “Red Flag”:
Illegal Side Effects & Prop Mutation
(The “Mutation & API Trap”)
Performing actions that change the state of the “world” (e.g., fetch, setTimeout, or setCount) or mutating props directly.
props.items.sort(), props.items.reverse(), or props.data.push() is a critical error. These mutate the parent’s data in memory, breaking unidirectional data flow.[...props.items].sort().React Purity “Red Flag”:
Non-Determinism
(The “Randomness & Time Trap”)
Using values that change every time the function is called (e.g., Math.random(), new Date(), or crypto.randomUUID()).
key={Math.random()}, it’s a massive red flag for reconciliation performance and stability.Define: reconciliation.
Definition: React’s “diffing” process to sync the Virtual DOM with the Real DOM.
* The Goal: To find the minimal set of changes needed to update the UI efficiently.
* The Heuristics:
1. Element Type: If the tag changes (e.g., <div> to <span>), React destroys the old tree and builds a new one.
2. Stable Keys: key props allow React to match items across renders, even if they move positions.
* Why it matters: Prevents expensive, full-page re-renders.
Additional info:
The Algorithm: Uses two main heuristics:
1. Different Types: If elements change from <div> to <span>, React destroys the old tree and builds a new one.
2. Keys: Stable, unique keys allow React to match items across renders, even if they’ve moved positions (crucial for lists).
Define: controlled component.
Definition: A form element (e.g., <input>, <select>) where the source of truth is React state, not the internal DOM state.
value={state} (Forces the input to show the state).onChange={e => setState(e.target.value)} (Updates state from user input).ref).Define: uncontrolled component.
Define: lifting state up.
Define: prop drilling.
Define: referential equality.
Define: key (list rendering).
Define: derived state.
Define: batching (state updates).
Define: functional state update.
Define: stale state bug (increment pattern).
Define: strict mode double-invocation (dev).
Define: state immutability.
Define: composition (React).
Define: conditional rendering.
Define: fragment.
Define: React.memo (concept).
Define: Suspense (baseline).
Define: Error Boundary (baseline).