Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何将组件中的值传递到Formik多步骤表单向导?_Reactjs_Formik_React Bootstrap Typeahead - Fatal编程技术网

Reactjs 如何将组件中的值传递到Formik多步骤表单向导?

Reactjs 如何将组件中的值传递到Formik多步骤表单向导?,reactjs,formik,react-bootstrap-typeahead,Reactjs,Formik,React Bootstrap Typeahead,正如标题所说。 我有一个基于react bootstrap typeahead的无状态组件和一个基于文档中找到的 但是,我无法将从typeahead组件获得的值传递到formik。我无法访问setFieldValue const FormElements = setFieldValue => ( <Wizard initialValues={FORM_VALUES} onSubmit={(values, actions)

正如标题所说。 我有一个基于
react bootstrap typeahead
的无状态组件和一个基于文档中找到的

但是,我无法将从
typeahead
组件获得的值传递到
formik
。我无法访问
setFieldValue

    const FormElements = setFieldValue => (
        <Wizard
          initialValues={FORM_VALUES}
          onSubmit={(values, actions) => {
            sleep(300).then(() => {
              window.alert(JSON.stringify(values, null, 2));
              actions.setSubmitting(false);
            });
          }}
        >
          <Wizard.Page>
            <GoogleMapsPlaceLookup
              value={location => {
                console.log("I got the value correctly from my child: ", location);
              }}
            />
          </Wizard.Page>
        </Wizard>
    );

    export default FormElements;
const FormElements=setFieldValue=>(
{
睡眠(300)。然后(()=>{
alert(JSON.stringify(value,null,2));
动作。设置提交(错误);
});
}}
>
{
log(“我从我的孩子那里正确地得到了值:”,location);
}}
/>
);
导出默认表单元素;
如何将此值注入
Formik
,以便在Submit上处理它。任何指示或帮助都将不胜感激。 谢谢这里的Formik作者

因此,
FormElements
函数中的
setFieldValue
实际上不在正确的范围内。如果您需要在向导的某个页面中访问
setFieldValue
,则可以使用高阶组件和自定义组件从自定义中获取,或者使用render prop直接从Formik上下文获取

我的建议是将Formik的
组件与渲染道具一起使用,如下所示:

const FormElements=()=>(
{
睡眠(300)。然后(()=>{
alert(JSON.stringify(value,null,2));
动作。设置提交(错误);
});
}}
>
{({field,form})=>(

它工作得很好。你能考虑把这个添加到<代码> Fuffik < /Cord>的文档吗?在网络上搜索,我发现了很多类似的未回答的问题。