react-native - 路由 'Detail' 的组件必须是 React 组件
问题描述
我正在react native
使用“expo”在我的设备上运行模拟器的项目中工作我遇到错误并尝试解决可能多次但失败这里是我的错误链接
应用程序.js
import React from 'react';
import MovieList from './components/list';
import Detail from './components/detail';
import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
const AppNavigator = createStackNavigator({
MovieList: {screen: MovieList},
Detail: {screen: Detail},
})
const App = createAppContainer(AppNavigator);
export default App();
细节.js
import React from 'react';
import { StyleSheet, Text, View, FlatList, Image } from 'react-native';
export default function Detail() {
return (
<View>
<Text>Details</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center"
},
item: {
flex: 1,
padding: 10,
height: 50,
backgroundColor: '#282C35'
},
itemText: {
color: '#fff',
fontSize: 24
}
});
解决方案
错误在这里
const AppNavigator = createStackNavigator({
MovieList: {screen: MovieList},
Detail: {screen: **Detail**},
})
因为您将Detail声明为一个函数。StackNavigator需要组件_
例如
import React, { Component } from "react";
class Detail extends Component {
// Your Code
}
这如何工作正常使用组件而不是功能。
推荐阅读
- powershell - 从用户帐户 Powershell 复制文件夹和创建名称
- maven - 作为安装的最后一步,我将如何在 Maven 中打包 jar 之前复制文件?
- android - 未调用我的函数 getNearbyRestaurant 在 GoogleMap 上放置标记
- swift - Swift 当前视图显示图层顶部
- android - 如何使我的滚动正常工作?
- python - Boto3上传核心转储Python
- spring - 如何在 Kotlin 中使用泛型序列化 WebClient 对 Mono 的响应?
- python - 如何根据 Django admin 中的另一个模型过滤数据
- angular - Angular 9:为什么整个 rxjs 库都进入构建包?
- c# - IIS - ASP .NET MVC 项目被缓存