Create-react-app: Document how to add React Bootstrap

Created on 30 Jul 2016  路  19Comments  路  Source: facebook/create-react-app

This comes up fairly often.

Unlike React Router, it is not immediately obvious how to add React Bootstrap because it needs its own CSS. So I think it鈥檚 worth documenting this here (even though we won鈥檛 document adding e.g. the router) because this is a super common use case for beginners.

up for grabs!

Most helpful comment

Here's how I got React Bootstrap working at https://github.com/manavsehgal/react-eshop (Create React App scaffolded app).

Step 1. Install React Bootstrap and Bootstrap from NPM.

npm install react-bootstrap --save
npm install bootstrap --save

Step 2. Import Bootstrap CSS and optionally Bootstrap theme CSS in the index.js file.

import './index.css';
import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap/dist/css/bootstrap-theme.css';

Step 3. Import required React Bootstrap components within App.js file or your custom component file.

import React, { Component } from 'react';
import { Navbar, Jumbotron, Button } from 'react-bootstrap';

Now you are ready to use the imported React Bootstrap components within your component hierarchy defined in the render method. Here is an example App.js redone using React Bootstrap.

All 19 comments

Here's how I got React Bootstrap working at https://github.com/manavsehgal/react-eshop (Create React App scaffolded app).

Step 1. Install React Bootstrap and Bootstrap from NPM.

npm install react-bootstrap --save
npm install bootstrap --save

Step 2. Import Bootstrap CSS and optionally Bootstrap theme CSS in the index.js file.

import './index.css';
import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap/dist/css/bootstrap-theme.css';

Step 3. Import required React Bootstrap components within App.js file or your custom component file.

import React, { Component } from 'react';
import { Navbar, Jumbotron, Button } from 'react-bootstrap';

Now you are ready to use the imported React Bootstrap components within your component hierarchy defined in the render method. Here is an example App.js redone using React Bootstrap.

Nice, would you like to contribute this to template/README.md?

Thx, will do.

Thanks @manavsehgal! It worked smoothly!

The provided App.js doesn't show how to work with bootstrap anymore.

@Oxyrus I think it's on purpose, there is a section of the readme that covers how to add it.

@gaearon How about yarn instructions? Are they reqd? Or just overkill?

@ShashankaNataraj I don't think we need Yarn instructions everywhere. I would suggest any Yarn user to also learn the same npm commands.

Extremely helpful for beginners! Thanks @manavsehgal 馃憤

greate work like a charm...
thank you so much

Wow..It worked

Life saver. Thank you! This Medium article has also helped me out with Webpack config in conjunction to react-bootstrap setup.

Can anyone help me (noob here) understand why the css imports have to be done in index.js ? Why does it not work in App.js?

The method described by @manavsehgal only works for bootstrap v3 not v4.
Can anyone provide a solution to run bootstrap v4 with react 16?

@saranshbansal I'd recommend locking bootstrap on 3.3.7 to unblock yourself

Module not found: Can't resolve 'bootstrap/dist/css/bootstrap-theme.css' in 'C:\reactApps\loginpage\src'

@Arpeetgautam that's because Bootstrap version four doesn't have the bootstrap theme css included when downloaded via npm

The method described by @manavsehgal only works for bootstrap v3 not v4.
Can anyone provide a solution to run bootstrap v4 with react 16?

The documentation has been updated with Bootstrap v4
https://facebook.github.io/create-react-app/docs/adding-bootstrap

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fson picture fson  路  3Comments

xgqfrms-GitHub picture xgqfrms-GitHub  路  3Comments

rdamian3 picture rdamian3  路  3Comments

adrice727 picture adrice727  路  3Comments

onelson picture onelson  路  3Comments