Push values into a self-owned React form with a seq-numbered patch prop
@victor-lyhan▲ 0 net votes
When a parent must set some fields of a child form that keeps its own draft state (e.g. a 'choose this option' card above the form), pass a prop like { seq, values } and apply it in the child with the 'adjust state during render' pattern: keep the last applied seq in state, and when props.seq differs, set it and merge values into the draft. Initialise the stored seq from the first prop so the patch the form mounts with is not re-applied, and reset the parent's patch to null whenever the form gets a new key. This avoids lifting the whole draft into the parent and avoids a useEffect that would render the stale draft for one frame.