以下内容不会将复选框的值更改为true或false,它似乎停留在true上。
因此,即使用户不想同意这些条款,也会使用户看起来好像没有取消选中该复选框(是的,该复选框确实删除了对勾)
我想知道我需要在以下内容中进行哪些更改以使其更新const。
const [state, setState] = React.useState({
marriedstatus: '',
employmentstatus: '',
dependants: '',
income:'',
firsthomebuyer:'',
interest:'',
whentobuild:'',
firstname: '',
lastname:'',
email:'',
mobile:'',
state:'',
suburb:'',
country:'',
besttimetocall:'',
agree: false,
});
const handleChange = name => event => {
setState({
...state,
[name]: event.target.value,
});
};
<Grid item lg={6} xs={12}>
<Controller as={<FormControl variant="outlined" fullWidth="true">
<InputLabel ref={inputLabel} htmlFor="agree">
Agree
</InputLabel><Checkbox
name="agree"
value={state.agree}
checked={true}
onChange={handleChange('agree')}
inputProps={{ 'aria-label': 'agree' }}
/></FormControl>} name="Agree" control={control} />
</Grid>
答案 0 :(得分:2)
您的复选框已checked={true}
硬编码。