--- title: Separate Sequential Field Array Operations impact: MEDIUM-HIGH impactDescription: prevents state corruption from batched mutations tags: array, useFieldArray, append, remove, sequential --- ## Separate Sequential Field Array Operations Chaining `append()` and `remove()` in the same handler can cause state corruption. Defer removals to a useEffect or separate user action to allow React to process renders between operations. **Incorrect (stacked operations cause state issues):** ```typescript function ReplaceItemForm() { const { control } = useForm() const { fields, append, remove } = useFieldArray({ control, name: 'items' }) const replaceItem = (indexToReplace: number, newItem: Item) => { remove(indexToReplace) // Remove old item append(newItem) // Immediately add new - state may be stale } return (