【发布时间】:2019-09-25 13:04:38
【问题描述】:
我正在尝试将自定义 Radio 组件与 React-final-form 一起使用,但它不是作为单选按钮而是作为复选框,即所有按钮都打开以供选择。
第 3 方单选按钮具有以下架构:
checked boolean
Whether or not radio is checked
onChange () => void
Called when the user attempts to change the checked state
name string
The input name, used to reference the element in JavaScript
我创建了一个自定义组件来使用Radio 组件:
const CustomRadio = (props: any) => (
<Radio
{...props.input}
{...props.rest}
name={props.name}
onChange={() => props.input.onChange()}
/>
)
我的使用方法如下:
<Field name="food"
component={CustomRadio}
value="1"
/>
<Field name="food"
component={CustomRadio}
value="2"
/>
作为 RFF 和 React 的新手,我可能做错了什么,因此我们将不胜感激。
基本上,我想将 RFF 与我的 3rd 方组件一起使用。虽然我已经成功地按预期将我的 Input 组件与 RFF 一起使用,但 Radio Button 是造成问题的一个。
【问题讨论】:
-
您可能需要将
type="radio"添加到Field吗?