Formik 步进器道具+步间挂钩

Formik stepper props+hooks between steps

我正在尝试将一个组件中的数据传递给另一个组件,它们是 another.But 的兄弟组件,它们在 Formik StepperFormik Hook(rff) 中。

index.js -> is entry point, that calls only one component App, as we have no route
App.js -> this the parent component, which has two child, Step1 and Step2
Step1.js -> takes input
Step2.js -> renders data from Step1

我在这里做了一个简单的示例代码 link

https://codesandbox.io/s/keen-germain-formikstepper-xntko?file=/src/

这就是答案-

import React from "react";
import { useFormikContext } from "formik";
export default function Step2() {

const{values} =  useFormikContext()
return <p>{values.firstName} </p>;
}

完整解决方案 https://codesandbox.io/s/keen-germain-formiksteppersol-xntko?file=/src/App.tsx