skip to Main Content

As in the title. I have been used the react-select component and I pass props to it as the default value. but it did not show. why did this happen? even when I pass string to it like this defaultValue="aa"

this is the sandbox for my code:
enter link description here

2

Answers


  1. Please Check the sandbox. I’ve made some changes might help you.

    Login or Signup to reply.
  2. The defaultValue should be the Option type, see StateManager Props

    const options = [
      { value: 'chocolate', label: 'Chocolate' },
      { value: 'strawberry', label: 'Strawberry' },
      { value: 'vanilla', label: 'Vanilla' },
    ];
    
    // it should be
    <SelectItemComp b={options[0]} options={options} />
    
    // not
    <SelectItemComp b='chocolate' options={options} />
    

    codesandbox

    You can find the official example home#getting-started

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search