1

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 ?

1 Answer 1

1

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/

Sign up to request clarification or add additional context in comments.

3 Comments

but if i added CDN inside index.html it will be loaded inside the whole app , also the $ is still not defined even when I import $ , should i ( npm i jquery ) and use it instead ? also does it affect the whole app ?
Cdn in index.html or install with npm will be available for whole app, that's why I explained that you can not bundle for single component @RazorJhon
npm is easier than importing an external link module , i will use npm instead , thank you for explanation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.