// adding react-formik package. Using app based on [Create React App](https://github.com/facebook/create-react-app)
npx create-react-app react-formik
cd react-formik
// using yarn
npm install -g yarn
// we are going to need bootstrap
yarn add bootstrap
// adding basic styling
// adding yup form validation
yarn add formik styled-components yup
// start yarn
yarn start
// open browser to
open http://localhost:3000/
- Getting state values
- Validation and error messages
- Handling form submission on Form
Formik provides: Formik, Form, Field, and ErrorMessage.
Just wrap the Form component inside Formik component:
<Formik>
<Form>
{/* here will be dragons */}
</Form>
</Formik>
Yup is an object schema validator. Simple put it is a library that allows you to define the blueprint of a JS object and ensure that the object values match that blueprint through the validation process.
Formik provided pre-defined Fields out of the box, we will implement it and also create a new Custom field to compare both options
Finally we will set a blueprint of the JS object in a object. So we can later on re-use it.
Thanks to Jared Palmer for this great tool, further information: react-hook-form