【发布时间】:2020-11-22 03:12:38
【问题描述】:
我正在尝试在 react-hook-form 中使用 Material UI 的 React 评级组件。
...
<form onSubmit={handleSubmit(onSubmit)}>
<FormControlLabel
control={
<Checkbox
inputRef={register}
name="remember"
defaultValue={false}
/>
}
label="remember"
/>
<br />
<FormControlLabel
control={
<Rating
inputRef={register}
name="rating"
defaultValue={2}
precision={1}
icon={<RadioButtonUncheckedIcon fontSize="inherit" />}
/>
}
label="select rating"
/>
<Button type="submit">
Submit
</Button>
</form>
...
我不明白为什么评级组件的值没有被注册,但复选框的值是。请在https://codesandbox.io/s/suspicious-drake-1d0kx?file=/src/form.js 找到代码(提交时,评分的值不会打印到控制台,而复选框的值是)。
【问题讨论】:
标签: reactjs forms material-ui frontend