Are you looking for an easy guide to how to create a form in React?
The step-by-step guide on this page will show you how to create a form in React in just a minute with an easy process.
After completing this guide you will able to create forms in React without any problems. without any further fluff let’s get into it.

To create forms in React you need to follow these steps
- Import the necessary React components and libraries for handling forms, such as ‘
useState
‘ and ‘useEffect
‘ hooks. - Create a component for the form, and define the initial state using the ‘
useState
‘ hook. This state will hold the values of the form inputs. - Create the JSX markup for the form, using the ‘
onChange
‘ event handler to update the state whenever input is changed. - Handle the form submission by adding an ‘
onSubmit
‘ event handler to the form element. This event handler should prevent the default form submission behavior and instead handle the data as desired (e.g., sending it to an API, updating the UI, etc.).
Here is an e.g, you can copy this code.
import React, { useState } from 'react';
function MyForm() {
const [formState, setFormState] = useState({
name: '',
email: '',
message: ''
});
const handleChange = (event) => {
setFormState({
...formState,
[event.target.name]: event.target.value
});
};
const handleSubmit = (event) => {
event.preventDefault();
// handle form submission here
};
return (
<form onSubmit={handleSubmit}>
<label>
Name:
<input type="text" name="name" value={formState.name} onChange={handleChange} />
</label>
<label>
Email:
<input type="email" name="email" value={formState.email} onChange={handleChange} />
</label>
</label>
<button type="submit">Submit</button>
</form>
);
}
export default MyForm;
Form Libraries Available for React JS And its instruction
Libraries in React refer to external code modules that you can use to extend the functionality of your React application. There are many form libraries available for React, some of the most popular ones are ;
Formik
Formik was created by Jared Palmer, a software engineer at The Palmer Group, to simplify the development of forms in React applications. The library was first released in 2017 and has since become a popular choice for managing forms in React applications.
Formik is built on top of the React context API, which allows it to provide a set of tools and utilities that handle form state, validation, submission, and error handling. The library provides a simple and intuitive API that makes it easy to get started with building forms in React, and it also supports a range of customization options for more advanced use cases.
To use Formik you have to install it first in React js app
npm i formik --save
yarn add formik
For further information, Click here
React Hook Form
React Hook Form is a lightweight library that provides a simple way to manage forms in React. It offers features like input validation, form state management, and form submission handling.
The library was created by Bill Luo, a software engineer based in Canada, who wanted to build a form library that was simple, performant, and easy to integrate into React projects.
React Hook Form was first released in 2019 and has since gained popularity among React developers. It is built on top of the React hooks API, which allows it to provide a lightweight and performant solution for building forms in React.
To use React Hook Form you have to install it first in react js app
npm i react-hook-form
yarn add react-hook-form
For further information, Click here
Redux Form
Redux Form is a library that integrates with the Redux state management library to manage form states in a React application. It provides a simple API to handle form state and submission.
Redux was created by Dan Abramov and Andrew Clark, both software engineers at Facebook at the time, and was first released in 2015. It was inspired by the Flux architecture pattern, which was also developed by Facebook.
The primary motivation behind Redux was to solve the problem of managing the state in large and complex applications. In traditional JavaScript applications, the state is often scattered throughout the codebase, making it difficult to manage and reason about.
npm i redux-form
yarn add redux-form
For further information, Click Here
Yup
Yup is a form validation library that integrates with many form libraries in React. It provides a simple way to define and manage form validation rules.
Yup was created by Jake Prins, a software engineer based in the United States, and was first released in 2016. The library was developed as an alternative to existing validation solutions that were either too complex or too limited in functionality.
One of the primary motivations behind Yup was to provide a library that was both fast and flexible. The library is designed to be highly performant, with a focus on minimizing the amount of time it takes to validate objects. This makes it well-suited for use in performance-critical applications like web and mobile apps.
you can use it with other forms like Formik Form, React-hook Form Redux-Form for Validation Schema
to use Yarn first you need to install it in your Reactjs app
npm i yarn
yarn add yup
For further information, click here