在ReactJS中使用jQuery是一种不好的做法吗? [英] Is it a bad practice to use jQuery in ReactJS?

查看:128
本文介绍了在ReactJS中使用jQuery是一种不好的做法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我个人在ReactJS项目(或任何其他项目)中使用纯JavaScript。但是我最近一直在想,在ReactJS中使用jQuery是一种不好的做法?

I personally use pure javascript in a ReactJS project (or any other project). But I've been thinking lately that is a bad practice to use jQuery in ReactJS?

我在学习ReactJS时使用过jQuery,我不是指任何其他外部javascript文件,我的意思是:

I've used jQuery when I was learning ReactJS and I don't mean any other external javascript file, what I mean is :

        if (form.status === 200) {
         $(".element").val("");
      }

使用这种补丁工作感觉非常糟糕,后来我了解了 this.setState({});

and felt really bad using this kind of patch work, later I learned about this.setState({});

但是,在某些情况下,如此在进行ajax调用时,使用jQuery是个好主意吗?

But, given in some circumstances, such as making ajax calls, is it a good idea to use jQuery?

推荐答案

这是一个不好的做法因为React使用了一个名为a的概念虚拟DOM而不是真正的DOM。并且React不知道在此Virtual DOM之外所做的更改。当您使用jQuery或任何其他操纵DOM的库时,React会感到困惑。

It's a bad practice because React uses a concept called a Virtual DOM instead of a real DOM. And React isn't aware of the changes made outside of this Virtual DOM. When you use jQuery or any other library that manipulates the DOM, React gets confused.

如果您想将jQuery用于AJAX目的,您可以使用专门制作的库对于AJAX,如Axios或本机Fetch API。

If you want to use jQuery for AJAX purposes, you can just use a library specifically made for AJAX, like Axios or the native Fetch API.

这篇关于在ReactJS中使用jQuery是一种不好的做法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆