简体   繁体   English

React中的普通ES6类

[英]Normal ES6 class in React

Is it okay/bad practice for me to use a regular, plain 'ol javascript ES6 class in my React project, so that it does not extend component? 对我来说,在我的React项目中使用常规的普通'ol javascript ES6类是对的做法,是否不好,这样它就不会扩展组件? I am wondering if this is bad to meddle with plain class instances using the new keyword. 我想知道使用new关键字将其与普通类实例混在一起是否不好。 If so, what is the alternative if the class is purely functional with no UI? 如果是这样,如果该类是完全没有UI的纯函数,该怎么办?

I wouldn't say it's bad practice. 我不会说这是不好的做法。 In my projects I typically build a class for my API call methods to import into my components. 在我的项目中,我通常为API调用方法构建一个类,以将其导入到组件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM