reactjs - 复选框不改变值
问题描述
以下不会将复选框的值更改为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>
解决方案
您已经checked={true}
为您的复选框进行了硬编码。
推荐阅读
- angular - 如何以角度创建动态链接按钮
- django - 带有 Jinja2 的 Django:模板搜索路径
- amazon-ecs - 如何更新和 ECS 服务添加一个额外的负载平衡,服务与之对话而不停机?
- reactjs - 自动 DynamoDB 数据库检查 | ReactJS + AWS 放大
- visual-studio-code - 更改vs代码中括号和大括号的颜色
- ruby-on-rails - 恢复数据库后,从相同的 SGID 加载 ActionText::Attachable 不再有效
- javascript - 使用 javascript 抓取网页 - 由于错误 80020101 无法完成操作
- ssh - gitlab runner ssh私钥644文件权限错误
- angular - ngmodel没有在茉莉花测试中填充输入元素值?
- r - R:一个时间间隔是否落在另一个时间间隔内?