I am newb to reactjs, I want to include bootstrap in my react app
I have installed bootstrap by npm install bootstrap --save
Now, want to load b
Somehow the accepted answer is only talking about including css file from bootstrap.
But I think this question is related to the one here - Bootstrap Dropdown not working in React
There are couple of answers that can help -
Full answer to give you jquery and bootstrap since jquery is a requirement for bootstrap.js:
Install jquery and bootstrap into node_modules:
npm install bootstrap
npm install jquery
Import in your components using this exact filepath:
import 'jquery/src/jquery'; //for bootstrap.min.js
//bootstrap-theme file for bootstrap 3 only
import 'bootstrap/dist/css/bootstrap-theme.min.css';
import 'bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap/dist/js/bootstrap.min.js';
After installing bootstrap in your project "npm install --save bootstrap@3.3.7" you have to move to the index.js file in the project SRC folder and import bootstrap from node module package.
import 'bootstrap/dist/css/bootstrap.min.css';
If you like you can get help from this video, sure it will help you a lot.
Import Bootstrap In React Project
Just in case if you can use yarn
which is recommended for React apps,
you can do,
yarn add bootstrap@4.1.1 // this is to add bootstrap with a specific version
This will add the bootstrap as a dependency to your package.json
as well.
{
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"bootstrap": "4.1.1", // it will add an entry here
"react": "^16.5.2",
"react-dom": "^16.5.2",
"react-scripts": "1.1.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
After that just import bootstrap
in your index.js
file.
import 'bootstrap/dist/css/bootstrap.css';
I try with instruction:
npm install bootstrap
npm install jquery popper.js
then in src/index.js:
import 'bootstrap/dist/css/bootstrap.min.css';
import $ from 'jquery';
import Popper from 'popper.js';
import 'bootstrap/dist/js/bootstrap.bundle.min';
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
ReactDOM.render(<Dropdown />, document.getElementById('root'));
registerServiceWorker();
Simple Solution (2020) is as follows :-
npm install --save jquery popper.js
npm install --save bootstrap
npm install --save style-loader css-loader
import "bootstrap/dist/css/bootstrap.min.css";
import $ from "jquery";
import Popper from "popper.js";
import "bootstrap/dist/js/bootstrap.bundle.min";