Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

176
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda