Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert bootstrap.js to react app?

How to insert twitter-bootstrap js file to react app using webpack?

I know about react libraries like reactstrap and react-bootstrap, but I want to know how to insert bootstrap.js file without these libs.

like image 1000
Stanislav Mayorov Avatar asked May 01 '17 16:05

Stanislav Mayorov


People also ask

Does react JS need Bootstrap?

React. js has inbuilt module of bootstrap i.e. react-bootstrap that can be imported to use bootstrap in the HTML. One can also link to the CDN or import its files to use bootstrap classes.

How do I use Bootstrap in react native?

Import Bootstrap as a Dependency in React Your app will require Bootstrap to be installed as a dependency. After you've installed Bootstrap, be sure to include it in your app's entry JavaScript framwork code. If anyone is using the create-react-app, src/index. js should be the file.


1 Answers

You can just install Bootstrap and jQuery via npm/yarn:

npm install bootstrap jquery

Then import Bootstrap in your top-level React file (the entry point):

import 'bootstrap/dist/css/bootstrap.min.css'
import 'jquery/dist/jquery.min.js'
import 'bootstrap/dist/js/bootstrap.min.js'

You'll need the appropriate Webpack rules to transform CSS, of course.

The problem with using Bootstrap in React is that it requires jQuery, and now you have two things mucking with the DOM, which is a recipe for trouble. That's the real value proposition of Reactstrap (for Bootstrap 4) and React-Bootstrap (which also supports Bootstrap 4 now); they remove the dependence on jQuery, and implement the functionality as React components. I highly recommend you leverage the work of these projects; you're opening a can of worms by trying to combine jQuery with React. It's possible; I've done it; I don't recommend it.

like image 53
Ethan Brown Avatar answered Sep 29 '22 14:09

Ethan Brown