Skip to content
Discussion options

You must be logged in to vote

@celtric

In your example, the "First tag" is not checked because Material UI expects it should be set with prop "defaultChecked" or "checked".

When clicking on the "First tag" checkbox at the first time, react-hook-form will remove the value "First tag" and update DOM element of the checkbox but because it's already "unchecked" therefore it remains the same state "unchecked", that's why when clicking "Submit", the value is empty array.

With checkbox group use case, it would be recommended to use Controller component or useController hook because it provides the selected value array of checkboxes in order to set checked or unchecked state.

Working sample: https://codesandbox.io/s/busy-rhod…

Replies: 3 comments 10 replies

Comment options

You must be logged in to vote
1 reply
@celtric
Comment options

Comment options

You must be logged in to vote
9 replies
@bluebill1049
Comment options

@celtric
Comment options

@bluebill1049
Comment options

@celtric
Comment options

@bluebill1049
Comment options

Answer selected by bluebill1049
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants