1

I am trying to create a custom component for React-Select, where I want to show more than just label in the select box. Kind of similar to Custom Placeholder, Option, Value, and Arrow Components part here. The problem is that the link to the source code is not accessible anymore, and I found the documentation for styling pretty awful.

Assume I have my data like this:

[
  {
    'id': 1,
    'label': 'Alpha',
    'gender': 'Male'
    'country': 'USA'
  },
  {
    'id': 2,
    'label': 'Beta',
    'gender': 'Male'
    'country': 'ENG'
  },
  {
    'id': 3,
    'label': 'Charlie',
    'gender': 'Female'
    'country': 'GER'
  }
]

What I want to show in select box is something like:

Alpha - Male - USA

Beta - Male - ENG

Charlie - Female - GER

But it should still filter only for labels, which are Alpha, Beta, and Charlie.

Right now I can only show Alpha, Beta, and Charlie. I am trying to understand how to do this from the documentation here but for example there are no definitions for style keys and what they do. I could use some guidance here.

1 Answer 1

1

Use the getOptionLabel prop on your Select:

const label = (option) => `${option.label} - ${option.gender} - ${option.country}`;

<Select getOptionLabel={label} />
Sign up to request clarification or add additional context in comments.

1 Comment

Hm, really usefull, I prefer to use components and then manipulate options, but it works too :) Best regards!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.