react-component / react-component/select

`Option` Not working as a wrapped component

Open
#605 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

When I have some custom logic I want to put in an Option, I may want to extra that to a separate component for easy-reuse. Imagine an extremely contrived example:

const CheckboxOption = ({ label, value }) => (
  <Option value={value} label={label}>
    🎉 {label}
  </Option>
);

const  MySelect = ({options, setValue, value}) =>  (
  <Select onChange={v => setValue(v)} optionLabelProp="label" value={value}>
      {options.map(o => (
        <CheckboxOption {...o} />
      ))}
  </Select>
);

This won't work, the custom emoji doesn't render, and we only see the label get rendered.

However, if I call the function component like a function, it does work and the custom option is rendered:

const  MySelect = ({options, setValue, value}) =>  (
  <Select onChange={v => setValue(v)} optionLabelProp="label" value={value}>
     {options.map(o => CheckboxOption({ ...o }))}
  </Select>
);

It appears that the Option must be a direct child of Select and it does not work when wrapped.

Is this intentional? While calling it like a function isn't a huge deal in this example, if I wanted to use hooks in the component for anything, it wouldn't work.

I have a stackblitz with the issue here: https://stackblitz.com/edit/react-4dhwku

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

Reproduce the behavior in the linked StackBlitz, then trace how Select discovers Option children and applies optionLabelProp. Done means a wrapped CheckboxOption renders its custom emoji and content while remaining usable as a component with hooks. Add or update the relevant test after locating the Select and Option child-handling entry points.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.