0
votes

I build a simple project to explain my problem

here the full code

https://codesandbox.io/s/check-it-4d2g1?file=/src/App.tsx:585-598

I want to pass initialValues from App component to Step1 component and after that show the firstName in Step2 component

here my initialValues in useFormik hooks

const formik = useFormik({ initialValues: { firstName: "", lastName: "" } });

This is step 1

here the user fill the firstName input

enter image description here

here the firstName field

enter image description here

This is step 2

image

So how can I displat firstName at Step2 ?

How I try is the right way?

I know there is 3 way for that

1.Passing a component to the component prop of Formik

2.Using the render method and passing your forms markup in JSX

3.Wrap your form with Formik and add your form as JSX

What is the fit way can you fill my codesandbox example according this way...?

https://codesandbox.io/s/check-it-4d2g1?file=/src/App.tsx:585-598

1
If I’m understanding your question correctly.. if you’re looking to just pass values from one component to another you can have a global store using Reacts useContext hook. Then import it on the step 2 form and display the data. It just kinda depends on how you’re modularizing your forms. From the example, it looks like theirs a lot in one file. I’m not sure if that’s how you’re doing it - graysonmcm

1 Answers