【发布时间】:2020-02-20 06:28:25
【问题描述】:
App.js:
import React from 'react';
import Home from './screens/home';
import Navigator from './routes/drawer';
import Login from './screens/login';
export default class App extends React.Component{
render() {
if (false) {
return (
<Navigator />
);
} else {
return (
<Login />
);
}
}
}
login.js:
import React, {View, Text} from 'react';
export default class Login extends React.Component {
render() {
return (
<View style={{ padding: 20 }}>
<Text>Some text</Text>
</View>
)
}
}
这个程序给了我标题中的错误,这对 Navigator 有效,但对 Login 无效(当 if 设置为 true 而不是 false 时,程序运行正确。) Navigator 充当典型的抽屉容器,用于一个 android 应用程序,但在导入的底部,所有内容似乎都与渲染选项相同。完整的错误日志如下...
Invariant Violation: Element type is invalid: expected a string (for built in components) or a class/function (for composite components) but got: undefined.
You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named exports.
Check the render method of 'Login'.
This error is located at:
in Login...
in App...RCTView...AppContainer...
【问题讨论】:
标签: reactjs react-native mobile import