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.

no way to set primitive value(s) directly

See original GitHub issue

First, 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
mysufcommented, Feb 24, 2021

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.

1reaction
ebonowcommented, Feb 24, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Primitive vs Non-Primitive Value in Javascript? | by Ayush Tibra
Immutable values are those which cannot be modified after creation. Primitives are known as being immutable data types because there is no way...
Read more >
Why Java Collections Cannot Directly Store Primitives Types?
Java primitive types are not referenced types. ... are not directly storing primitives types ... Adding the int primitives type values.
Read more >
Assigning primitive & non primitive values in Javascript | Medium
When a primitive value is assigned to a variable (eg let name = 'Mike'), the variable is set to that value directly.
Read more >
Primitive - MDN Web Docs Glossary: Definitions of ... - Mozilla
It is important not to confuse a primitive itself with a variable assigned a primitive value. The variable may be reassigned to a...
Read more >
Why can Java Collections not directly store Primitives types?
Consider if you wanted to create a collection that stored primitive values. How would you write a collection that can store either int,...
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