我将名为Bus的屏幕作为函数而不是React类组件进行导出,并且始终会收到一个错误屏幕,上面写着:'Invariant Violation:元素类型无效:预期为字符串(对于内置组件)或类/ function(对于复合组件),但得到:未定义。您可能忘记了从定义文件中导出组件,或者可能混淆了默认导入和命名导入。检查Bus
的渲染方法。'
对我来说毫无意义,因为我还在其他地方使用功能组件,而且效果很好!
我正在使用RN 0.60.5
我的公交页面,该错误提示我。
import React, { View, Text } from 'react';
import Maps from '../../components/Maps'
import SearchBox from '../../components/Searchbox'
import RouteDetailsBox from '../../components/RouteDetailsBox'
const Bus = () => (
<View style={{ flex: 1 }}>
<Maps />
<SearchBox />
<RouteDetailsBox />
</View>
);
export default Bus;
App.js
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
import React from 'react';
import { Provider } from 'react-redux';
import store from './src/store';
//screens
import Bus from './src/screens/bus'
const App = () => {
return (
<Provider store={store}>
<Bus />
</Provider>
);
};
export default App;
答案 0 :(得分:2)
来自
import React, { View, Text } from 'react';
到
import React from 'react';
import { View, Text} from 'react-native';