React JS Bootstrap Form Component Example

Sep 07, 2022 . Admin

Hello Artisan,

This definitive guide, we will show you react js bootstrap form example. This article will give you a simple example of react js bootstrap form component example. We will use react bootstrap form not working. This article will give you a simple example of how to use bootstrap form in react.js.

Bootstrap is a wold best design framework right now. Currently bootstrap 4 and bootstrap 5 version is running. Bootstrap provides alerts, buttons, badge, card, modal, forms, collapse, navs, pagination etc.

In this post, i will show you step by step how to use bootstrap form component in reactjs app. we will create new react js project and install "react-bootstrap and bootstrap" npm packages for bootstrap, then we will use bootstrap form with Label, Control and Button component. so let's follow below command:

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 bootstrap-app
Step 2: Install React-Bootstrap

In this step, we will install bootstrap and react-bootstrap npm package for bootstrap design component. let's run below command:

npm install react-bootstrap bootstrap
Step 3: Import Bootstrap CSS File

In this step, we will import bootstrap css file in index.js file of react js app. so let's add it.

src/index.js
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import 'bootstrap/dist/css/bootstrap.min.css';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
);

reportWebVitals();
strong class="step">Step 4: Update App.js Component

Here, we will use bootstrap design class and button component for demo. so just update App.js file as the below:

src/App.js
import Container from 'react-bootstrap/Container';
import Form from 'react-bootstrap/Form';
import Button from 'react-bootstrap/Button';

function App() {

  let users = [
      {id: 1, name: "Hardik Savani", email: "hardik@gmail.com"},
      {id: 2, name: "Vimal Kashiyani", email: "vimal@gmail.com"},
      {id: 3, name: "Harshad Pathak", email: "harshad@gmail.com"},
  ];

  return (
    <Container>
        <h1>React JS Bootstrap Form Component Example - MyWebtuts.com</h1>
        <Form>
        <Form.Group>
            <Form.Label>Name:</Form.Label>
            <Form.Control type="text" 
                          placeholder="Enter your full name" />
          </Form.Group>
          <Form.Group>
            <Form.Label>Email:</Form.Label>
            <Form.Control type="email" 
                          placeholder="Enter your your email address" />
          </Form.Group>
          <Form.Group>
            <Form.Label>Age:</Form.Label>
            <Form.Control type="number" placeholder="Enter your age" />
          </Form.Group>
          <Button variant="primary" type="submit">
             Submit
          </Button>
        </Form>
    </Container>
  );
}

export default App;
Step 5: Run React JS App

All the required steps have been done, now you have to type the given below command and hit enter to run the React app:

ng serve

Now, Go to your web browser, type the given URL and view the app output:

http://localhost:3000

In the last step run your project using bellow command.

Output

I hope it can help you...

#React JS