【问题标题】:react final form conditional form fields are not getting values while rendered反应最终形式条件表单字段在渲染时未获取值
【发布时间】:2019-09-12 08:24:51
【问题描述】:
【问题讨论】:
标签:
reactjs
react-final-form
final-form
【解决方案1】:
因为<Form /> 需要可见的<Field /> 才能订阅
但是当 values.meterType !== "heat" 时,您的字段 scalingFactor 将被删除
{values.meterType && values.meterType === "heat" && (
<Field name="scalingFactor" component="input" />
)}
你需要修改你的代码如下:
<Field name="scalingFactor">
{({ input }) => {
return (
<React.Fragment>
{values.meterType && values.meterType === "heat" &&
<input {...input} />
}
</React.Fragment>
);
}}
</Field>