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>
)
}
}
这个程序在标题中给了我错误,这确实适用于导航器,但不适用于登录(当if设置为true而不是false时,程序会正确运行。(导航器充当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...
您的导入是错误的。
import React from 'react';
import { View, Text } from 'react-native';
react
模块内没有名为View
或Text
的导出。
检查您的Login.js文件。有些进口是错误的!
检查React Native here 内部的组件和API
解决方案
从反应中删除导入视图和文本
import React from 'react';
import { View, Text } from 'react-native';
export default class Login extends React.Component {
render() {
return (
<View style={{ padding: 20 }}>
<Text>Some text</Text>
</View>
)
}
}