1

I have gone through many articles, people do not recommend usage of jQuery in React.

Sometime I feel we can do some operations really quickly using them. Some developers do not include the jQuery at all in their codebase but they use many npm modules which internally may use jQuery.

jQuery Dom is not a part of react diffing algorithm then how can they affect performance ?

5
  • 2
    When you alter the DOM in a way that react/angular isn't listening for, you're creating a scenario where the DOM that exists doesn't match the DOM angular/react think they are working on. Nothing is preventing angular/react from mangling/undoing whatever you do with jquery. Commented Oct 22, 2019 at 22:13
  • 1
    Why do you feel like you need to use jQuery? What specifically does it allow you to do that you can't do without it? Commented Oct 22, 2019 at 22:13
  • I am agree to the part that we can do anything without jQuery too. Being familiar with jQuery, I tend to use it but which is bad practice according to many authors. Commented Oct 22, 2019 at 22:17
  • 1
    Well aside from the point Kevin makes above that you really don't want to be updating the dom without react reconciliation happening most of the things you do in jquery can be so easily achieved with regular javascript that it seems pointless to import another library? Commented Oct 22, 2019 at 22:22
  • Thanks for your time @kevin and Jon. I really appreciate it. Commented Oct 22, 2019 at 22:25

1 Answer 1

1

the basic answer is this:

1) For animations, jQuery does in-browser looping and doesn't leverage CSS3 transitions. This takes up clock cycles (battery power) on mobile browsers and that's why you get jagged, not-smooth animations when using jQuery. but more importantly, the React DOM is special because it MAINTAINS A COMPLETE COPY OF YOUR DOM in its own internals ("the virtual DOM"). Now think about this: You come along and change the DOM using jQuery but React has an old copy of the DOM. It uses this copy of the DOM every time it re-renders, and so you've just make its copy out of sync with the real DOM. When you do this, Very Bad Things can happen to you and you're basically totally thumbing your nose at the very heart of React (the virtual DOM).

If you want to do animations or move things on the screen, forget everything you know about jQuery and learn CSS3 transitions. then do it the React way.

2) For everything non-animated, like utility functions, try an alternative (smaller) library like lodash or underscore. They have map, each, pluck, etc for all your utility function needs.

3) I can see using jQuery only for some very specialized things (for example throttle and debounce), but even those probably have alternatives now.

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

1 Comment

I think I am pretty much clear now. Thanks for your time Jason.

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.