The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →If a value can be calculated from the props and state a component already has, calculate it during rendering instead of storing it in another useState. The extra state creates a second value that must stay synchronized—and can go stale. State is still right for information that changes independently, or when you intentionally want to preserve an initial value.
What “derived state” means
Derived state is a value that can be worked out from the component’s current props or other state. A full name derived from a first and last name is a simple example. So is the object for a selected list item when the component already has the list and the selected item’s ID.
Storing both the source values and their derivation gives the component two representations of the same information. Every update must keep them consistent. If one changes without the other, the interface can show an outdated or contradictory result.
Calculate display values during rendering
When a value is determined by current props or state, declare it in the component body. React will calculate it as part of rendering, using the current inputs.
#1 Best Overall
function Name({ firstName, lastName }) {
const fullName = firstName + ' ' + lastName;
return <p>{fullName}</p>;
}
There is no need for a separate fullName state variable and an Effect that updates it when either name changes. The calculation already describes the relationship directly.
Why copying a prop into state goes stale
A prop passed to useState supplies the initial value; it does not keep the state synchronized with future prop changes.
function Message({ messageColor }) {
const [color, setColor] = useState(messageColor);
// ...
}
If the parent later passes a different messageColor, color remains the component’s local state value. That may be an accidental stale copy if the child is supposed to follow the parent.
If the child should always reflect the latest value, use messageColor directly. If it should start with the prop and then become independently editable, make that intent visible in the API with a name such as initialColor or defaultColor. In that design, ignoring later changes to the initial prop is deliberate.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteRank #3
Store a selected ID, not a copied list item
When a selection refers to an item already held in a list, keep the stable identifier in state and find the current item during rendering.
function List({ items }) {
const [selectedId, setSelectedId] = useState(null);
const selectedItem = items.find(item => item.id === selectedId);
// ...
}
If an item’s details change in items, the derived selectedItem comes from the current list. A separately stored copy of the object could continue showing old details.
Rank #4
Use an Effect for external synchronization, not routine derivation
An Effect is appropriate when a component must synchronize with something outside React. It is not the routine way to transform props or state into a value for display, or to keep one React state variable updated from another.
If there is no external system involved and the task is simply to derive a value from current inputs, calculate it during rendering. This avoids an extra synchronization step and the stale intermediate render it can introduce.
Best Value
Choose the pattern that matches who owns the value
| Need | Pattern | Tradeoff |
|---|---|---|
| The value follows current props or state | Calculate during rendering | Uses current inputs; calculation runs as part of rendering. |
| The calculation is expensive | Consider useMemo |
Can reduce repeated computation; the result is still derived, not independently owned state. |
| The child should always follow its parent | Use the prop directly or make the component controlled | The parent remains the source of truth. |
| The child should preserve only an initial prop value | Initialize local state from a clearly named initial/default prop | Later changes to that prop are intentionally ignored. |
| A change of identity should reset all child state | Give the component a different key |
React resets the keyed component’s state tree. |
| A selection refers to an item in a collection | Store its ID and derive the current item | Avoids a stale copied object. |
| The component must synchronize with a non-React system | Use an Effect where appropriate | Designed for external synchronization, not ordinary value derivation. |
When a prop change should reset or adjust local state
Use a controlled component when the parent should decide
If the parent owns the value and determines how it changes, pass the value and an event handler to the child. The child displays the supplied value rather than maintaining a competing copy.
Use a key when the whole child state belongs to a new identity
If changing a prop means the child should start fresh, change the component’s key. React then treats it as a different component and resets its state tree. This is often clearer than copying the prop and manually resetting several state variables.
Update state in the event that changes it
When a user action changes a value and related state, update the relevant state in that event handler where possible. That keeps the cause and its state changes together instead of waiting for an Effect to notice a derived difference.
Adjusting state during render is a rare escape hatch
React also documents conditionally adjusting the same component’s state during rendering when a prop change must affect some local state but neither a controlled design nor a key-based reset fits. This pattern is harder to follow because it complicates data flow; it must be conditional so it does not trigger an update on every render. Most components should not need it.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesQuick Recap
A quick decision check
- If the value can be computed from the current props or other state, calculate it in the component body.
- If it is an expensive calculation, consider
useMemoas an optimization rather than adding a second independently updated state value. - If it identifies an existing item, store the ID and look up the current item.
- If it should follow the parent, use the prop or a controlled component.
- If it should retain only its starting value, name that initial/default contract explicitly.
- If a new identity should reset the child, consider changing its
key. - If the component must coordinate with an external system, use an Effect for that synchronization.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




