1
Hi, would you like to know how to set a value in Select Component, Material UI, through a click? For example, by clicking the button, invoke the handleAlert function, which changes the Select value;
export default function NativeSelects() {
const classes = useStyles();
const [age, setState] = React.useState('');
const handleChange = event => {
const name = event.target.value;
setState(name);
};
const handleAlert = () => {
const teste = 'teste'
setState(teste);
};
return (
<div>
<FormControl className={classes.formControl}>
<InputLabel htmlFor="age-native-simple">Age</InputLabel>
<Select
native
value={age}
onChange={handleChange}
inputProps={{
name: "age",
id: "teste"
}}
>
<option aria-label="None" value="teste" />
<option value={10}>Ten</option>
<option value={20}>Twenty</option>
<option value={30}>Thirty</option>
</Select>
</FormControl>
<Button onClick={handleAlert}>Teste</Button>
</div>
);
}