Select component is not working with react-hook-form
See original GitHub issueHere’s the snippet:
<Select
className="max-w-xs"
aria-label="Thought tag"
{...register("tag")}
>
<Select.Option value={"default"} disabled>
Select Tag
</Select.Option>
<Select.Option value={"Life"}>Life</Select.Option>
<Select.Option value={"Tech"}>Tech</Select.Option>
<Select.Option value={"Random"}>Random</Select.Option>
<Select.Option value={"Rant"}>Rant</Select.Option>
<Select.Option value={"Truth"}>Truth</Select.Option>
</Select>
and when I select something from the dropdown, it shows this:
I tried the native select and it works
<select className="select w-full max-w-xs" {...register("tag")}>
<option disabled defaultChecked>
Select Tag
</option>
<option value={"Life"}>Life</option>
<option value={"Tech"}>Tech</option>
<option value={"Random"}>Random</option>
<option value={"Rant"}>Rant</option>
<option value={"Truth"}>Truth</option>
</select>
Please let me know if this problem is specific to me or it is not really working, thank you.
Issue Analytics
- State:
- Created 9 months ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
React Hook Form and React Select Not Working as Expected
I am using typescript and have this select component as a separate component. What would be the type for the {...field} props? –...
Read more >FAQs | React Hook Form - Simple React forms validation
React Hook Form doesn't control your entire form and inputs, which is the reason why React wouldn't recognize the actual input that has...
Read more >MUI Select with react-hook-form setValue not working #8544
I have a project using MUI Select and react-hook-form 7 with YUP resolver. When I try to change the value of a field...
Read more >React Hook Form: A guide with examples
Learn all about using forms in React with React Hook Form, including how to create and validate forms — even with third-party components....
Read more >How to Create Forms in React using react-hook-form
Note, we're not using the register function here. Regular use of the react-select library to allow multiple selection goes like this: import ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Since we expose the ref and value and onChange, I think you should be able to use the select component with react-hook-form Controller, like you would with any other component library.
Can you try it out and let us know if it works?
I use RHF fairly often so if this doesn’t work I’ll take a look at the code and figure out a fix
@Jiseeeh @seba5dev thanks for finding this, I’ll look into it. I’m not too familiar with
react-hook-form
because I’ve never used it, so if anybody has a better understanding of how it works/what it expects to plug into on a<select>
please feel free to contribute a fix!