【发布时间】:2018-08-10 08:52:05
【问题描述】:
我的App.js 文件是:
import React, { Component } from 'react';
import { Provider, connect } from 'react-redux';
import { createStore, bindActionCreators } from 'redux';
import {Platform, StyleSheet, Text, View} from 'react-native';
import reducers from './reducers';
class App extends Component {
render() {
return (
<Provider store={createStore(reducers)}>
<View>
<Text>12345</Text>
</View>
</Provider>
);
}
}
const mapStateToProps = state => {
console.log(state);
};
export default connect(mapStateToProps)(App);
我收到以下错误:
Invariant Violation: Could not find "store" in either the context or props of "Connect(App)". Either wrap the root component in a <Provider>, or explicitly pass "store" as a prop to "Connect(App)".
我不知道错误在哪里。我该如何解决?
【问题讨论】:
-
为什么要使用 connect(mapStateToProps)(App) 导出应用程序;它不是必需的。删除它,我认为它可以正常工作
标签: react-native redux react-redux