react-hook-form: Uncaught TypeError: Cannot delete property '3' of [object Array]

I’m getting an error Uncaught TypeError: Cannot delete property '3' of [object Array].

My component is a dynamic that uses useFieldArray({ name: 'step.answers', control }).

    if (defaultValues && fields.length < defaultValues.length) {
      defaultValues.pop(); // here where it breaks
      set(fieldArrayDefaultValuesRef.current, name, defaultValues);
    }

defaultValues.length is 4, fields.length is 2. That’s why defaultValues.pop(); is fired.

Could you clarify please, why this error might happen? I can debug further then.

It would be nice to have a clarification error in the console for such cases.

Screenshot 2021-01-07 at 14 07 54 Screenshot 2021-01-07 at 14 11 37

I’d be glad to create a codesandbox, but my form is very complicated. With funnel and little-state-machine.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Keep this open, i will patch this tonight and close it.

actually will do a slice and it would solve this issue for now.