I'm using react-select for a single select menu. The defaultValue appears to be displaying correctly when I edit the form, but when I submit the form the value returned is undefined if the selection is left unchanged. If I click the defaultValue then it works correctly when submitted. Is there an additional prop I'm missing to maintain the defaultValue through submission?
Code looks like this:
<Select
closeMenuOnSelect={true}
options={options()}
defaultValue={defaultVal}
className="basic-single"
classNamePrefix="select"
/>
Where options() is a simple function to format the data like this:
const options = [
{ value: "chocolate", label: "Chocolate" },
{ value: "strawberry", label: "Strawberry" },
{ value: "vanilla", label: "Vanilla" }
];
And defaultVal returns a single value by filtering options:
let defaultVal = options().filter(
(optionChoice) => optionChoice.label === props.choice
);