'React hook form - how to remove an error from an array without clearing its fields?

I have an array of fields in a react hook form controlled form. Using yup, I declared this array like that :

    activities: yup
      .array()
      .of(
        yup.object().shape({
          name: yup.string().required(requiredError),
/* lots more*/
        })
      )
      .min(1, atLeastOneActivity),

If the user submits without adding an activity, there's an error, that's what I want.

But if the user adds an activity, the error still stands. So I tried using trigger("activities") and it removes that error, but it also triggers all the fields under activities.

How can I make react-hook-form reconsider the error in the array itself, and not all the fields in the objects in the array ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source