Can I validate my select dropdown without using react-hook, I have to ensure that the value in the select is never empty / null when user clicked onto the submit button.
handleChange = (option) => { this.setState({option:option.target.value})
<Select onChange={this.handleChange} value={this.state.option}>
<MenuItem>test1</MenuItem>
<MenuItem>test2</MenuItem>
</Select>
This is the current code for my react select, I would like to validate it so that the is never empty when clicking on submit button. As the code for my submit is just as below, along with basic buttons function etc..
OnClickSubmit(event)=>{event.preventDefault()}
You can put a check on the OnClickSubmit method.
OnClickSubmit(event)=>{
event.preventDefault()
// check if value is not empty/null before invoking your fns
if(!!this.state.option){
// invoke your functions here
...
}
}