It seems that using jQuery with React is generally frowned upon. I would like to know the reason. So, my question is do you use jQuery with React? If not, why is it considered a bad practice?
jQuery is a big an bloated library with nearly nothing in it which can't be solved with Vanilla JS. Especially when you are working with react, it just doesn't make sense to use jQuery too. You have all necessary event handlers within react. It must be a very specific usecase if i need jQuery for anything. And if thats the case, there sure is another library out there which can do that too, but is much smaller and without overhead. I did everything with jQuer some time ago, but currently we are forcing us to remove it as dependency and solve problems another way.
You should too. ;)
Let's say the Store in a React app is S0, it changed to S1 after an action. And the DOM state is changed from V0 to V1. So theoretically it's a state changing in a state machine. Since React is in a declarative way, it fits into a state machine naturally. But jQuery does not. You have to code it carefully to make it cooperate with that state machine.
There are also another concern that is called performance. React has its way of optimizing DOM operations by separating component render stage and DOM patching stage to eliminate forced layouts. But in jQuery it can be hard because it manipulates the DOM directly. It can be tedious in large apps.
In conclusion, my answer is: you can use jQuery but you need to be careful with the DOM states and performance issues, and it's sometimes much easier not to use jQuery.
Solemn way that blending jQuery and React would bode well reports this site is when bit by bit conveying React to the venture, when just a piece of the application is utilizing React and there is as yet old code utilizing jQuery.
I think it is necessary sometimes. E.g, in componentDidMount().
Ben Buchanan (200ok)
I make some bits of the web.
jQuery in this context usually refers to DOM scripting, where events and UI updates happen in the browser DOM. Because React handles events directly and uses a virtual DOM, in theory using React should mean you simply don't need to use jQuery as well.
Changing the browser DOM outside your React app means React is potentially no longer handling state, events and UI rendering. Also, it means you are basically building one thing two entirely different ways; and sending two dependency loads down to the browser instead of one.
Still - it's not the end of the world if both are being used, you just have to be aware of what each is doing and how the other will deal with that.