简体   繁体   中英

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? I am wondering if this is bad to meddle with plain class instances using the new keyword. If so, what is the alternative if the class is purely functional with no 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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