I'm trying to use jQuery in React Js but it shows that "$" is undefined. Is there some package I need to install or does React does not support jQuery.
-
Go through this post.Niladri Basu– Niladri Basu2017-10-26 05:32:16 +00:00Commented Oct 26, 2017 at 5:32
-
1they don't support it, and it's very easy screw stuff up using it, but it might make for some ok drag and drop or validation routines if used carefully.dandavis– dandavis2017-10-26 05:38:01 +00:00Commented Oct 26, 2017 at 5:38
-
Thanks everyone...Shibu– Shibu2017-10-26 05:49:42 +00:00Commented Oct 26, 2017 at 5:49
-
Jquery is not the answer, you should NEVER use it. you can use everything in react itself. JQuery is huge. dont add extra size to you app javascript files.hannad rehman– hannad rehman2017-10-26 09:25:23 +00:00Commented Oct 26, 2017 at 9:25
-
Actually what i'm trying is to create a dynamic <input /> for each time a function is called so I was trying to use jquery to append the input.. I searched for dynamically creating a component in react but found noneShibu– Shibu2017-10-26 11:00:01 +00:00Commented Oct 26, 2017 at 11:00
Add a comment
|
1 Answer
For your specific problem, try installing jQuery via npm.
npm i jquery --save
or
yarn add jquery
Then, in your modules...
import $ from 'jquery'
With that said, it's no easy thing to use jQuery and React together. React is unaware of changes made outside of the virtual DOM, and jQuery manipulates the standard DOM directly.
There's a write-up on how to approach this problem here.
3 Comments
Shiladitya
Please try not to answer duplicate question.
Michael Geary
@Shiladitya The question was not marked as a duplicate when Den answered it (obviously, because he couldn't have answered it if it was). It may not have been obvious that it was a duplicate at the time he answered it, so I don't see anything wrong with that.
Shibu
I searched for it and probably didn't find any questions related to it as far as I searched for it. I'm sorry if it is.