2

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.

Shiladitya
  • 12,003
  • 15
  • 25
  • 38
Shibu
  • 181
  • 2
  • 2
  • 14
  • Go through [this](https://medium.com/@shuvohabib/using-jquery-in-react-component-the-refs-way-969de9aa651f) post. – BlackBeard Oct 26 '17 at 05:32
  • 1
    they 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 Oct 26 '17 at 05:38
  • Thanks everyone... – Shibu Oct 26 '17 at 05: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 Oct 26 '17 at 09:25
  • Actually what i'm trying is to create a dynamic 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 none – Shibu Oct 26 '17 at 11:00

1 Answers1

8

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.

Denny
  • 744
  • 4
  • 10
  • Please try not to answer duplicate question. – Shiladitya Oct 26 '17 at 05:30
  • 4
    @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. – Michael Geary Oct 26 '17 at 06:59
  • 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. – Shibu Oct 28 '17 at 04:48