Add support for Symbols as option values.
See original GitHub issueLets say I have two arrays, and I want to use React Select to allow a user to create a mapping from people
to pets
.
const people = ['amy', 'bob', 'callum']
const pets = ['cat', 'dog']
Next to each item in people
there is a React Select dropdown allowing the user to select which item from pets
to map that person too, or a None
option if they are not mapped to a pet. Currently, the value
on the None
option is a string constant: '_none'
.
However, since my arrays are user-generated, and I want to allow any string value in my arrays, it is possible that the string '_none'
could appear in one of my arrays, which would break my implementation.
To work around this I’d like to use a Symbol
as the value of the None
option, because then it would always be unique and never clash with a literal string value of '_none'
, but when I do this I get an error.
Uncaught TypeError: Cannot convert a Symbol value to a string
I think this error is thrown at /src/utils/defaultMenuRenderer.js L37.
I could use .toString()
on my Symbol, but that would raise the same conflict concerns as above.
Are there any reasons not to support Symbol
types as values?
Do you have possible work arounds?
If not, I’d be happy to send a PR to add support for symbols as values.
Let me know if you need any clarification on my problem. Thanks for the awesome library ❤️
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (1 by maintainers)
Top GitHub Comments
The default behavior of react-select is to stringify both the value and label so typing can filter on both. This can be modified by setting a
stringify
function on customFilterAh oops I was using 3.X. Though I still don’t see why they need to be stringified.