Skip to content
Discussion options

You must be logged in to vote

Yes, that is basically the reason: the field array name itself is not the same thing as an individual registered input field.

useFieldArray({ name: 'items' }) manages the array structure, but the actual registered fields are usually paths like:

items.0.name
items.0.price
items.1.name

So getFieldState('items') is not usually the right way to ask "is any row in this array dirty?". It is better for a concrete field path:

const state = getFieldState('items.${index}.name', formState)
console.log(state.isDirty)

For array-level dirty state, use formState.dirtyFields or useFormState and inspect the array branch:

const { control } = useForm({
  defaultValues: {
    items: [{ name: '' }],
  },
})

c…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Felixmurithi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants