I need to reset the react select value, when I click on a button I need to reset to the default value of react select, the data is provided from api, how can I do this ??
maybe I need to guard the value because I cannot lost the value selected if the user refresh the page
code below:
class SelectTabs extends Component {
constructor(props) {
super(props);
this.state = {
options: [],
};
this.getDataTab = this.getDataTab.bind(this);
this.makeOptions = this.makeOptions.bind(this);
}
componentDidMount() {
this.getDataTab();
}
getDataTab() {
const URL = `${Utils.ngrok_service}/tab/tabGet`;
const skills = this.props.manager.workerClient.attributes.routing.skills;
axios.post(URL).then((response) => {
this.setState({
options: [...response.data.SAC, ...response.data.AC],
});
}
makeOptions(object) {
const options = object.map((data, index) => {
return {
value: index + 1 + '. ' + data,
label: index + 1 + '. ' + data,
};
});
return options;
}
render() {
const selectProps = {
isRtl: false,
isMulti: false,
isClearable: false,
isSearchable: false,
placeholder: 'Selecione',
noOptionsMessage: () => 'Não Encontrado.',
};
return (
<React.Fragment>
<SC.Container>
<SC.Title>Tabulação</SC.Title>
<Select
{...selectProps}
options={this.makeOptions(this.state.options)}
/>