'how to use jquery from cdn in react's component
I am using Jquery with CDN in react's index.html file.. Unfortunatelly, this is how it should be and can't install react separately with yarn.
How can I use now $ in React's components ?
I can't do import $ from Jquery. and if i use $ directly, it's not defined.
Any idea ?
I also tried useEffect, but in that, $ is not defined at first.
Solution 1:[1]
have you tried with npm or yarn.
npm install jquery
import $ from "jquery"
I have tried it and its working fine.
if ($(".enclosing_container ").length) {
$(".enclosing_container div").remove();
} else {
$(".main-row div").remove();
this.setState({ focusUI: false });
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Wasif Ali |
