我正在使用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>
</>
);
};
对其他输入类型(例如文本)使用点表示法似乎可以正常工作。
答案 0 :(得分:1)
我的猜测是它的逻辑很好,但是视觉部分有问题,ReactstrapRadio样式可能有问题,我分叉了您的沙箱并摆脱了ReactstrapRadio,它工作正常,您可以在此处进行检查 https://codesandbox.io/s/naughty-christian-xhhdx?file=/src/App.js