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.

5
  • Go through this post. Commented Oct 26, 2017 at 5: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. Commented Oct 26, 2017 at 5:38
  • Thanks everyone... Commented 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. Commented 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 none Commented Oct 26, 2017 at 11:00

1 Answer 1

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.

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

3 Comments

Please try not to answer duplicate question.
@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.
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.