I am trying to pass data in a component to another component, which are siblings to one another.But they are in a Formik Stepper
with Formik 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
I made a simple example code here the link
https://codesandbox.io/s/keen-germain-formikstepper-xntko?file=/src/
This is the answer -
import React from "react";
import { useFormikContext } from "formik";
export default function Step2() {
const{values} = useFormikContext()
return <p>{values.firstName} </p>;
}
full solution https://codesandbox.io/s/keen-germain-formiksteppersol-xntko?file=/src/App.tsx