Home > Software engineering >  Import jQuery in React inside single component
Import jQuery in React inside single component

Time:06-06

I want to import jQuery inside reactjs only inside 1 component because of the performance of the app but it doesn't work i keep getting error that '$' is not defined when using jQuery inside the page

what i want to do something like this :

import "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js";

how can i achieve this ?

CodePudding user response:

CDN should be placed in index.html file not in js and then in you can use it in React component. You can't bundle CDN inside your JS, this againist the goal of having it on CDN. Check webpack externals https://webpack.js.org/configuration/externals/

  • Related