I have two components side-by-side which are React-Select
drop-down list components:
<SelectField
options={props.directories}
placeholder=Directory
onChange={props.onDirectoriesChange}
value={props.directoryCodeName}
isClearable={true}
/>
<SelectField
options={props.subDirectories}
placeholder=Sub Directory
onChange={props.onSubDirectoryChange}
value={props.subDirectoryCodeName}
isClearable={true}
/>
Now, when I select a value in the first drop-down, the second drop-down is populated according to what has been selected in the first one. When I select an option in the second drop-down then change the option in the first drop-down, the list of options have changed in the second drop down, which is great. However, the current value of the second drop down is not cleared. What is the best way to clear the value of the second drop-down?
First thing that comes to mind is to put some code in the onChange
handlers below:
const onDirectoriesChangeHandler = (props: WrappedFieldsProps) => (
selectedDirectories: IOption<string>
) => {
props.directoryCodeName.input.onChange(fromJS(selectedDirectories));
};
const onSubDirectoryChangeHandler = (props: WrappedFieldsProps) => (
selectedSubDirectories: IOption<string>
) => {
props.subDirectoryCodeName.input.onChange(fromJS(selectedSubDirectories));
};
But I have reached a dead-end and I am thinking of Lifting State Up, unless there is a way to do this using React-Select's attributes?