Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
It duplicates the source of truth and renders once with stale data before the effect fixes it; calculate the value during render, or make the component fully controlled or reset it with a key.
useState only uses its argument on the first render, so later prop changes are ignored unless you add an effect, and that effect causes an extra render with outdated values first. If the value can be computed from props, compute it directly during render, using useMemo only if the calculation is expensive. If the component needs editable local state initialized from a prop, choose one owner: either make it controlled by the parent, or give it a key so it resets when the identity changes, for example