How to use jQuery dependent plugins in create-react-app

I want to use bootstrap and other jQuery plugins (datepicker, carousel, ...) in my React app that uses create-react-app .

This is how I import jQuery and bootstrap:

 import React, { Component } from 'react'; import 'bootstrap/dist/css/bootstrap.min.css'; import $ from 'jquery'; window.jQuery = window.$ = $; import 'bootstrap/dist/js/bootstrap.min'; 

And I get the following error:

 ./src/App.js Line 5: Import in body of module; reorder to top import/first Search for the keywords to learn more about each error. 

Please note that I do not want to use the react-bootstrap package.

+5
source share
1 answer

In this case, to use bootstrap or bootstrap-datepicker I needed require instead of importing.

 import React, { Component } from 'react'; import 'bootstrap/dist/css/bootstrap.min.css'; import $ from 'jquery'; window.jQuery = window.$ = $; require('bootstrap'); require('bootstrap-datepicker'); 
+6
source

Source: https://habr.com/ru/post/1268057/


All Articles