JedWatson / JedWatson/react-select
Runtime error if options are array of strings
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 28k
- Forks
- 4.1k
- PR merge metrics
- No merged PRs in 30d
Description
If options are array of strings:
<Select
options={["a", "b", "c"]}
value={value}
getOptionValue={e => e}
getOptionLabel={e => e}
onChange={e => setValue(e)}
/>
There is a runtime error:
Uncaught TypeError: Cannot use 'in' operator to search for 'options' in 1
Which happens here: https://github.com/JedWatson/react-select/blob/master/packages/react-select/src/Select.tsx#L382
Sometimes it is really convenient if options is an array of predefined strings (enum).
It could be fixed just by doing a typeof guard.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in packages/react-select/src/Select.tsx around line 382 and reproduce the issue with the provided Select example using string options. Trace the failing runtime path and verify the fix against string options with getOptionValue and getOptionLabel callbacks; done means the example no longer throws the reported TypeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100