How to set a default value in react-select How to set a default value in react-select reactjs reactjs

How to set a default value in react-select


I guess you need something like this:

const MySelect = props => (<Select    {...props}    value = {       props.options.filter(option =>           option.label === 'Some label')    }    onChange = {value => props.input.onChange(value)}    onBlur={() => props.input.onBlur(props.input.value)}    options={props.options}    placeholder={props.placeholder}  />);


I used the defaultValue parameter, below is the code how I achieved a default value as well as update the default value when an option is selected from the drop-down.

<Select  name="form-dept-select"  options={depts}  defaultValue={{ label: "Select Dept", value: 0 }}  onChange={e => {              this.setState({              department: e.label,              deptId: e.value              });           }}/>


If you've come here for react-select v2, and still having trouble - version 2 now only accepts an object as value, defaultValue, etc.

That is, try using value={{value: 'one', label: 'One'}}, instead of just value={'one'}.