How can I remove useFieldArray in child component? #11487
Unanswered
leesb971204
asked this question in
Q&A
Replies: 1 comment
-
In your code snippet, you create the same fields with const Children = ({index}) => {
const { control } = useFormContext();
const { remove } = useFieldArray({
control,
name: `options.${index}`, // It points the parent index
});
// It points the child index
<button onClick={()=>remove(nestedItemIndex)}></button>
} you can check the nested array example this codesandbox. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have trouble in remove useFieldArray in child component.
I want write code have not much props drilling.
In my code, if I click remove button in children component, it does not work.
Am I missing something? (like useFieldArray Context?)
Beta Was this translation helpful? Give feedback.
All reactions