How to Get Text Box Value in React JS?

Oct 06, 2022 . Admin

Hi Developer,

In this quick example, let's see how to get text box value in react js. This tutorial will give you a simple example of how to get text field value in react js. step by step explain react js get text value. step by step explain react js get text value on button click. follow the below example for how to get text value in react js.

In this example, i will show you how to get text box value in react js. we will create form with "name" and "email" text box. Then we will get text fields value on form submit. so, let's see the simple example

Step 1: Create React JS App

In this step, open your terminal and execute the following command on your terminal to create a new react app:

npx create-react-app reactjs-my-example
Step 2: Install Bootstrap

In this step, we will install bootstrap npm package to use design css. let's run below command:

npm install bootstrap --save
Step 3: Create Form.js Component

Here, we will create Form.js component and make form. Then we will add form with "name" and "email" input fields. so let's update code on following file.

import React from 'react';
class Form extends React.Component {
  state = {
    name: '',
    email: ''
  handleChange() Code
  handleChange = (event) => {
    const input =;
    const value = input.value;
    this.setState({ []: value });

  handleFormSubmit() Code
  handleFormSubmit = (e) => {

    const inputData = this.state;
  render() {
    return (
        <form onSubmit={this.handleFormSubmit}>
            Name: <input name="name" className="form-control" value={} onChange={this.handleChange}/>
            Email: <input name="email" className="form-control" value={} onChange={this.handleChange}/>
          <button type="submit" className="btn btn-success  ">Submit</button>
export default Form;
Step 4: Update App.js File

Here, we will update our App.js file code. we will import Form component and import bootstrap for design. so let's update code on App.js file.

import './App.css';
import 'bootstrap/dist/css/bootstrap.min.css';

import Form from './Form';

function App() {

  return (
    <div className="App container">
      <h1>How to Get Input Box Value in React JS? -</h1>

      <Form />


export default App;
Step 5: Run React JS App

In the last step run your project using bellow command.

npm start

I hope it can help you...

#React JS