Razor Jhon
Razor Jhon

Reputation: 145

Import jQuery in React inside single component

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 ?

Upvotes: 1

Views: 603

Answers (1)

Evren
Evren

Reputation: 4410

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/

Upvotes: 1

Related Questions