【发布时间】:2019-09-11 07:19:43
【问题描述】:
我收到此错误 - “在使用 Redux connect() 时,路由 'HomeScreen' 的组件必须是 React 组件” 在应用 Redux connect() 和删除 connect() 时应用在本机反应中运行良好。
下面我已经提到了代码:
import React, { Component, Fragment } from 'react';
import { View, Text } from 'react-native';
import {connect} from 'react-redux';
class Sample extends Component {
constructor(props) {
super(props);
this.state = {
loading: true,
dataSource: {}
};
}
render() {
return (
<View>
<Text>Hi</Text>
</View>
)
}
}
const container = connect()(Sample);
export default container;
我也尝试将 React Redux 版本从 7.0.1 降级到 6.0.1,但我仍然面临同样的问题。
我也试过Solution,但问题仍然存在。
【问题讨论】:
-
你能提供你的导入吗?也很高兴看到 Home 组件
-
这是我的导入:import React, { Fragment } from 'react';导入 { SafeAreaView, StyleSheet, ScrollView, View, Text, StatusBar, } from 'react-native';从 'react-native/Libraries/NewAppScreen' 导入 { Header, LearnMoreLinks, Colors, DebugInstructions, ReloadInstructions, };从'./src/Components/Home'导入主页;
-
这些导入是否属于您使用 redux connect 导出组件的模块?因为您正在导入 Home,然后根据您的问题示例使用 redux connect 再次导出它
-
这是我的 Home 组件: class Home extends Component { constructor(props) { super(props); } componentDidMount() { this.props.getTopCategoryDetails();} render() { const { topCategory } = this.props; return (
) } }导出默认连接(mapStateToProps, mapDispatchToProps)(Home);Hi -
你在你家所在的模块中导入connect了吗?
标签: reactjs react-native redux react-redux react-native-android