question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Select component is not working with react-hook-form

See original GitHub issue

Here’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: image

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:open
  • Created 9 months ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
christianblandfordcommented, Dec 10, 2022

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

1reaction
benjitroschcommented, Dec 10, 2022

@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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found