Assign/get custom key value for useFieldArray #5142
Replies: 4 comments 2 replies
-
|
U should use ur own key and stored in a hidden input, hook form id is purely made for react render. |
Beta Was this translation helpful? Give feedback.
-
|
Understood. Though I think it'll be useful and reduce workaround if we could have something like const id = append({}) |
Beta Was this translation helpful? Give feedback.
-
|
thanks for the suggestion @donysukardi what's your usage like? |
Beta Was this translation helpful? Give feedback.
-
|
I ran into the same issue and this approach worked for me.
Then in your Accordion, you can use uuid as the expanded key. React Hook Form will ignore extra fields, so you won’t break the array logic. The warning shows up if you try to use uuid as the This worked perfectly for me without any extra hacks. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Is your feature request related to a problem? Please describe.
I'm using
useFieldArraywith controlled<Accordion>component from ant-design. Newly added entry would have to be expanded by default. In order to do that, I need to have the key value of the new entry to be added to Accordion state.Describe the solution you'd like
append,prepend, etc.Describe alternatives you've considered
append({ uuid: 'xxx' }). However, I'm getting warning:useFieldArray fieldValues contain the keyNameuuidwhich is reserved for use by useFieldArray.Additional context
N.A.
Beta Was this translation helpful? Give feedback.
All reactions