Skip to content

How do you use it with formik? #119

@fddayan

Description

@fddayan

I'm building a multi step form and on each step I need to validate different fields. The problema I'm finding is that I have to wrap te steps outside the Wizard component and I need to load formik inside the Wizard component to have access to the activeStep, like

 <Wizard>
      <Formik
        initialValues={{
          firstName: '',
          lastName: '',
          email: '',
          password: '',
          username: '',
          phoneNumber: '',
        }}
        validationSchema={SignUpValidations[activeStep]} # I know it'I have not used useWizard to get this value, I can wrap that later,  but you get the ide.
        onSubmit={handleOnSubmit}
      >
        {() => (      
          <>
            <StepOne />
            <StepTwo />
          </>      
        )}
      </Formik>
    </Wizard>

with formik I used to do:

const stepsValidations = [
  StepOneSchema, 
  StepTwoSchema,
]

<Formik 
    validationSchema={stepsValidations[steps]}
   ....
``

any solution to this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions