Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
Handling value state with multiple Formik forms on one component

I am building a page using React and Formik. On my form page, I have three Formik forms that are conditionally rendered using a switch statement. I am doing it this way because each form's data need to be sent to their own api endpoint so I'm keeping them logically separated. When the first form is submitted, it cycles to the next. I am having an issue where when accessing the value prop in the second Formik form, it displays the values from the first. It appears as though Formik by default isn't handling the data separation when multiple Formik's exist, despite them existing in different return statements.

My switch statement is something like this:

switch(currentform) {
    case 'form1':
        return (
            <Formik
                initialValues={form1Values}
                onSubmit={(values, actions) => {
                    let form1= JSON.stringify(values, null, 2);
                    console.log(form1)
                 }}
                 >
                {({ values, setFieldValue }) => (
                    <Form className='form-container'>
                    
                 </Form>
                 )}
                </Formik>

        )
     case 'form2':
        return (
            <Formik
                initialValues={form2Values}
                onSubmit={(values, actions) => {
                    let form2= JSON.stringify(values, null, 2);
                    console.log(form2)
                 }}
                 >
                {({ values, setFieldValue }) => (
                    <Form className='form-container'>
                    
                 </Form>
                 )}
                </Formik>

        )
}

When submitting form1, the console.log(form1) displays the correct data. After submitting form2, the console.log(form2) returns the same data as form1. I've tried renaming the values prop in each onSubmit but that doesn't seem to change the behavior. Can someone help to confirm if my implementation is flawed or if there is a better way to configure this? Thanks to anyone who reads this!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!