JedWatson / JedWatson/react-select

Runtime error if options are array of strings

Open
#5,369 6 comments 12 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

issue/bug-unconfirmed
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.