One possible solution: instead of using the selected property in the parameters, use a controlled component using the value property of the select field. Whenever any changes occur to the bank list, reset the status of the state selected for applying. Also set the parameter value=''with the default parameter.
Like this:
<select value={this.props.value} onChange={this.onChangeDropdown}>
<option value='' disabled>
{this.props.defaultOption}
</option>
{makeDropDown()}
</select>;
Pass the value from the parent component, for example:
<DropDown
value={this.state.bankName}
data={this.state.bankData}
defaultOption="select Bank"
callbackFn={this.callStateService}
/>
<DropDown
value={this.state.stateName}
data={this.state.stateData}
defaultOption="select State"
callbackFn={this.callDistrictService}
/>
Define the onChange function to change the state selection field:
callDistrictService = value => {
this.setState({ stateName: value });
}
Working sandbox.
source
share