I have an issue using react-select. I use redux form and I've made my react-select component compatible with redux form. Here is the code:
const MySelect = props => (
{...props}
value={props.input.value}
onChange={value => props.input.onChange(value)}
onBlur={() => props.input.onBlur(props.input.value)}
options={props.options}
placeholder={props.placeholder}
selectedValue={props.selectedValue}
/>
);
and here how I render it:
id="side"
name="side"
component={SelectInput}
options={sideOptions}
clearable={false}
placeholder="Select Side"
selectedValue={label: 'Any', value: 'Any'}
/>
But the problem is that that my dropdown has not a default value as I wish. What I'm doing wrong? Any ideas?
解决方案
I guess you need something like this:
const MySelect = props => (
{...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}
/>
);