[英]npm module to use both in a react.js project and in a react native project: how to define the different behaviour in the code?
假设在模块的 index.js 中工作,我应该定义类似的东西
if (we are in a react.js project){
do this;
} else if (we are in react native project){
do this;
}
如何确定模块是在 reactjs 项目中还是在 react native 项目中使用?
看到这个答案。 它说你可以这样做:
if (typeof document != 'undefined') {
// React
}
else if (typeof navigator != 'undefined' && navigator.product == 'ReactNative') {
// React Native
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.