react-component / react-component/select

Can't create a Select component with a Object value

Open
#1,159 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
938
Forks
482
Avg merge
15h 8m
Merged PRs (30d)
2

Description

I'm trying to create a Select component with a object value.

{
 label: `My String`,
 value: { CuteCharm: true },
}

This results in a runtime error because value is rendered here: https://github.com/react-component/select/blob/48e24574fdf6a7b68589631e32d69d8dc629c974/src/OptionList.tsx#L309C9-L309C16

Image

Expected behaviour: value can be an object, and it is not rendered (only label is rendered).

Proposed solution: Replace {value} by {typeof value === 'object' ? value.toString() : value}

Contributor guide

No contributing guide indexed for this repository

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 src/OptionList.tsx at the rendering code linked from the issue and reproduce the runtime error with an option whose value is an object. Confirm that the label remains the rendered text while object-valued options no longer cause the error, then verify the relevant Select behavior with the existing test suite.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.