I am want to handle nested array using react hook from that’s my task. I am able to do everything but the state is not setting on onChange while I am getting all the correct value.
This is how my array looks like
const { register, handleSubmit, setValue, getValues } = useForm({
defaultValues: {
quizData: [{
pId: 1,
questions: [{ que: 'QUESTION 1', options: ['option 1', 'option 2'], correctAnswer: 0, selectedAnswer: -1 }, { que: 'QUESTION 2', options: ['option 1', 'option 2'], correctAnswer: 0, selectedAnswer: -1 }]
}]
}
});
Selected answer is not been updated below is link for codesandbox you can run the app over there.
2
Answers
Try these steps and see if they help resolve the issue. Let me know if you need further assistance!
Update your code as bellow:
Changes:
watch()
function for rendering updated form valuesLearn more here