How to access FieldError object by index #12034
-
Hi there, firstly I have never made a discussion on GitHub before so apologies if I use any incorrect terminology. So I am creating a form to create a template. These templates can have multiple cards so all components are stored in a field called cardComponents which utilizes useFieldArray. Within these cards there is an optional field for buttons which is also using useFieldArray. The input fields for these buttons are stored in a different react component. I pass this component the errors like so:
The value being passed to the errors prop has type: FieldError | undefined so I pass the props like this:
I am trying to access the values of these errors within the components like so:
However, I am getting the following error underneath props.errors?.[index]: Element implicitly has an 'any' type because expression of type 'number' can't be used to index type 'FieldError'. When I breakpoint the props.errors or console.log it, the value printed is an array. How do I access these values by index? My button fields include: title, type and payload which should all be strings. Thank you for the help. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Would be nice to have code-sandbox to reproduce your case. |
Beta Was this translation helpful? Give feedback.
-
Closing as realised error was to do with field type being either string | object. |
Beta Was this translation helpful? Give feedback.
Closing as realised error was to do with field type being either string | object.