Skip to content

Validation problem with react-hook-form #148

Answered by csandman
sonesay asked this question in Q&A
Discussion options

You must be logged in to vote

If react-hook-form doesn't receive the value in it's onChange function there's no way for it to know if the value is selected. The easiest way to fix this is by adding an inline onChange function which calls both your custom function along with react-hook-form's:

onChange={(newValue) => {
  typeChanged(newValue);
  onChange(newValue);
}}

Here's a working version of your code: https://codesandbox.io/s/chakra-react-select-rhf-example-frc697?file=/src/App.tsx:3325-3496

Replies: 1 comment 1 reply

Comment options

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

Answer selected by sonesay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants