如何解决Formik无线电不适用于嵌套对象值
我正在使用Formik。当我尝试根据嵌套文档的初始值使用嵌套对象来渲染单选按钮时,请点击此处:https://formik.org/docs/guides/arrays,无法选择我的单选按钮。
此处的沙盒:https://codesandbox.io/s/gracious-sanderson-8g3ls?file=/src/App.js:0-1046
我的代码:
import React from "react";
import { Field,Formik,Form } from "formik";
import { ReactstrapRadio } from "reactstrap-formik";
import { Col,Row,Container } from "reactstrap";
export const App = () => {
return (
<>
<Formik
initialValues={{
name: {
test: "testValue"
}
}}
>
{() => (
<Container>
<Form>
<Row>
<Col>
<Field
label="Test 1"
type="radio"
value="testValue"
name="name.test"
component={ReactstrapRadio}
/>
<Field
label="Test2"
type="radio"
value="otherValue"
name="name.test"
component={ReactstrapRadio}
/>
</Col>
</Row>
</Form>
</Container>
)}
</Formik>
</>
);
};
对其他输入类型(例如文本)使用点表示法似乎可以正常工作。
解决方法
我的猜测是它的逻辑很好,但是视觉部分有问题,ReactstrapRadio样式可能有问题,我分叉了您的沙箱并摆脱了ReactstrapRadio,它工作正常,您可以在此处进行检查 https://codesandbox.io/s/naughty-christian-xhhdx?file=/src/App.js
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。