24
loading...
This website collects cookies to deliver better user experience
npm install formik --save
yarn add formik
<script>
tag to the bottom of your HTML file.<script src="https://unpkg.com/formik/dist/formik.umd.production.min.js"></script>
<input>
with formik's <Field>
tag. It provides more flexibility to customise the input fields along with existing features of formik.<Field />
automatically hook up the inputs to Formik. It uses the name attribute to match up with Formik state. <Field />
will default to an HTML <input />
element.<FieldArray>
component which helps us in dealing with array/list operations. We can pass a property in name
with the relevant path of the key in the array we want to deal. address
field which we initialised as an empty array. We have the ability to add address values using Add
button. On click of the button, it calls arrayHelpers.push()
method which takes in the value and adds it in the array defined in the name props of FieldArray
.arrayHelpers.remove()
, which takes in an index, and removes that particular item from the array.Pre-Submit: In this step, it touches all the fields once, incrementing submitCount=+1 and also checks for initialValues, which are required and should be specified(preferable).
Validate: Here it checks all field-level validations, validate function, and validationSchema asynchronously and deeply merge results.
Submission: It starts by calling your submit-handler (onSubmit/handleSubmit), and sets isSubmitting to false, completing the form cycle.