Build forms in React JS using formik and yup

Phanendra Guptha Katta
4 min readJul 2, 2022

Building forms in react is a tedious process, for every input field we might need a different useState. As the number of inputs fields in our component increases state variables in our component also increase along with the complexity of our codebase. And validating these inputs is the biggest problem that we face while building forms.

In this article, we are going to build a signup form with formik and yup, where we have name, email, password, and confirm password fields.

Formik helps us to keep track of the form state, validations, error messages, and form submissions. Yup helps us with parsing and validation of the forms. The reason we are choosing formik and yup together is formik has built-in support for yup. Which makes a better choice for building forms with fewer tears and complexity.

Create a new react app

npx create-react-app forms
cd forms
npm start

Replace the App.js code with the below code

import "./App.css";function App() {
return (
<div className="wrapper">
<label htmlFor="name">Name</label>
<input id="name" type="text" />
<label htmlFor="email">Email</label>
<input id="email" type="email" />
<label

--

--