How to Build A Simple Contact Form in React 18 with Hook

Last Updated on by in React JS

In this tutorial, we will learn how to create a simple static contact form component in the React js application using functional component React Hook and Bootstrap module from scratch.

To build the contact form component, we will use the simple react hook and show you how to get the contact form data provided by users.

This step-by-step guide will demonstrate how to create a simple yet beautiful contact form in React using the bootstrap form control component.

Building a contact form in React is not that difficult; it may be if you are a newbie.

A contact us page is an essential page that enables the communication between your site and the users.

Ideally, a user fills the required fields such as name, email, and message.

We will add these fields to our contact form and get the information using the React useState hook.

React (Functional Component) Contact Form using useState Hook Example

  • Step 1: Install React App
  • Step 2: Add Bootstrap Library
  • Step 3: Create Component File
  • Step 4: Create Contact Form Function Component
  • Step 5: Add Component in App.js
  • Step 6: View App in Browser

Install React App

If you are willing to build a brand new project, you will have to install the create-react-app package in your system.

Head over to the command-line tool and invoke the following command:

npm install create-react-app --global

You are now ready to install a new React app; use the suggested command:

npx create-react-app react-contact-form

Then, enter into the project’s root:

cd react-contact-form

Add Bootstrap Library

Bootstrap helps in building the UI component in very less time, execute the command to add the bootstrap in React.

npm install bootstrap --legacy-peer-deps

Open the App.js file, import the bootstrap module’s CSS path within the file.

import '../node_modules/bootstrap/dist/css/bootstrap.min.css'

Create Component File

In the src/ folder, create another folder name it /components then create ContactForm.js file inside this folder.

In the subsequent step, we will be writing down the contact form code in this file.

import React from 'react'

function ContactForm() {
  return (

export default ContactForm

Create Contact Form Component

To create the contact form, in the contact form component you have to open the ContactForm.js file and add the following code into the file.

import React from 'react'

const ContactForm = () => {
  const [formStatus, setFormStatus] = React.useState('Send')

  const onSubmit = (e) => {
    const { name, email, message } =
    let conFom = {
      name: name.value,
      email: email.value,
      message: message.value,

  return (
    <div className="container mt-5">
      <h2 className="mb-3">React Contact Form Component Example</h2>
      <form onSubmit={onSubmit}>
        <div className="mb-3">
          <label className="form-label" htmlFor="name">
          <input className="form-control" type="text" id="name" required />
        <div className="mb-3">
          <label className="form-label" htmlFor="email">
          <input className="form-control" type="email" id="email" required />
        <div className="mb-3">
          <label className="form-label" htmlFor="message">
          <textarea className="form-control" id="message" required />
        <button className="btn btn-danger" type="submit">

export default ContactForm

Add Component in App.js

In this step, we are going to embed contact form contact in the react app.

Head over to the App.js file that you can find in your src folder, then import the component and define the component inside the App() function.

import './App.css'
import '../node_modules/bootstrap/dist/css/bootstrap.min.css'
import ContactForm from './components/ContactForm'

function App() {
  return (
    <div className="App">
      <ContactForm />

export default App

View App in Browser

The contact form component in React app is almost developed; you can now run the react server:

npm start

If you are testing the app locally, here is the url that will open the app on the browser:


How to Build A Simple Contact Form in React Js App


We believe you loved this simple post in which we created a static contact form in React js application using React hooks.

We also learned how to use bootstrap to spruce up the contact form looks in React.

Digamber - Author

Hi, I'm Digamber Singh, a New Delhi-based full-stack developer, tech author, and open-source contributor with 10+ years' experience in HTML, CSS, JavaScript, PHP, and WordPress.