no way to set primitive value(s) directly
See original GitHub issueFirst, I tried to find similar issue here, but without luck. You can find this on stackoverflow in number of forms, but the root cause is still the same. react-select produces value as ValueType {value: any, label: string}
(or with custom props), but it actually represents option used by component. Value is a property of this object, not an object itself. The result is that form with primitive field f.e. user_id: int
can not be set as integer directly, it is always ValueType. I saw only workarounds with onSubmit and mapping options back to values which is…well…ugly. Also it seems that getOptionValue is used only to stringify and compare value, not to actually get/set value… If I missed some simple approach, I appreciate any advice, otherwise it looks like serious drawback…
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5
Top GitHub Comments
I got the name property within fieldProps passed to custom SelectField. You can see fieldProps destructed into react-select props above - name is one of them. Thank you.
It’s probably worth adding that if you specify a name, it will add a hidden field that gets set to the value of the selected options. This makes its value natively accessible to the form.
In case you were looking for an example of how to integrate react-select into react-hook-form, here is an example from RHF using react-select (among many other libraries) demo example
Let me know if you have any further questions but it would seem that you have a working solution and on the right direction so it seems safe to close this now.