How To Install Bootstrap In React JS

Websolutionstuff | Sep-08-2022 | Categories : Bootstrap React JS

In this article, we will see how to install bootstrap in react js. Also, we will see how to use bootstrap in react js. If you work as a front-end developer, then Bootstrap, Foundation, and Bulma kind of frameworks are not new to you. Most industries use the Bootstrap framework. Millions of websites are running on bootstrap.

So, let's see how to install bootstrap 4/5 in react js and how to add bootstrap in react js.

In this article, we will see two ways to install bootstrap in react application.

1. we will use the npm bootstrap library. So, you can easily use all the classes of bootstrap 4 in your react js app.

2. we will use react-bootstrap they provide the library for bootstrap javascript. So, you can easily import bootstrap buttons, alert, navbar, and modal.

Install Bootstrap 4

Now, we will install bootstrap 4 using the npm command. So, run the following command.

npm install --save bootstrap

src/index.js

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import 'bootstrap/dist/css/bootstrap.css';
   
ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById('root')
);
serviceWorker.unregister();

Now, you can use a bootstrap class like the below code example.

src/App.js

import React from 'react';
import logo from './logo.svg';
import './App.css';
    
function App() {
  return (
    <div class="container">
        <h1>How To Install Bootstrap In React JS - Websolutionstuff</h1>
   
        <button class="btn btn-success">Success Button!</button>
        <button class="btn btn-primary">Primary Button!</button>
        <button class="btn btn-danger">Danger Button!</button>
   
        <div class="alert alert-success">
          <p>This is success alert.</p>
        </div>
        <div class="alert alert-primary">
          <p>This is primary alert.</p>
        </div>
        <div class="alert alert-danger">
          <p>This is danger alert.</p>
        </div>
    </div>
  );
}
  
export default App;

 

 

Install react-bootstrap

Now, we will install bootstrap using the npm react-bootstrap command.

npm install react-bootstrap bootstrap

After successfully installing bootstrap, we need to import bootstrap CSS in the src/index.js file.

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

src/index.js

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import 'bootstrap/dist/css/bootstrap.css';
   
ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById('root')
);
serviceWorker.unregister();

src/App.js

import React from 'react';
import logo from './logo.svg';
import './App.css';
import { Button, Alert } from 'react-bootstrap';
  
function App() {
  return (
    <div className="container">
  
        <Button variant="success">Success</Button>
        <Button variant="primary">Primary</Button>
        <Button variant="danger">Danger</Button>
   
        <Alert key="1" variant="success">
           This is a success message!
        </Alert>
    </div>
  );
}
  
export default App;

 


You might also like:

Recommended Post
Featured Post
Laravel 9 Create Zip File And Download
Laravel 9 Create Zip File And...

In this article, we will see laravel 9 create a zip file and download it. Laravel provides ZipArchive class fo...

Read More

May-02-2022

How To Store Backup On Dropbox In Laravel 9
How To Store Backup On Dropbox...

In this article, we will see how to store the backup on dropbox in laravel 9. Here, we will learn to store database...

Read More

Jan-16-2023

How To Live Search In Laravel 9 Using Meilisearch
How To Live Search In Laravel...

In this article, we will see how to live search in laravel 9 using Meilisearch. Here we will learn live search in l...

Read More

Dec-13-2022

Send Email In Laravel
Send Email In Laravel

In this article, we will explore the process of sending emails in Laravel, covering versions 6, 7, 8, 9, and 10. Email f...

Read More

Sep-02-2020