简体   繁体   English

如何像react-native一样在ReactJs中使用变量__DEV__?

[英]How to use the variable __DEV__ in ReactJs like in react-native?

In my react-native projects I use the global variable __DEV__ and I would like to use something similar in my Typescript reactJs project but when I try to use it I get this error:在我的 react-native 项目中,我使用了全局变量__DEV__并且我想在我的 Typescript reactJs 项目中使用类似的东西,但是当我尝试使用它时,我得到了这个错误:

ReferenceError: __DEV__ is not defined 

How can I achieve this?我怎样才能做到这一点?

The global variable process has an attribute that allow to achieve this:全局变量process具有允许实现此目的的属性:

const isDev = process.env.NODE_ENV === 'development';

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

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