当我尝试获取数据和componentDidMount
时收到此错误。如何解决此问题,这是在我的应用程序中获取数据的最佳位置吗?
不变违规:在“ Connect(App)”的上下文中找不到“ store”。要么将根组件包装在中,要么在连接选项中将自定义React上下文提供程序传递给Connect(App),并将相应的React上下文使用者传递给Connect(App)。
import React, { Component } from "react";
import {
Platform,
StatusBar,
StyleSheet,
View,
ImageBackground
} from "react-native";
import ApolloClient from "apollo-boost";
import { ApolloProvider } from "react-apollo";
import { Provider } from "react-redux";
import { PersistGate } from "redux-persist/integration/react";
import { connect } from "react-redux";
import store from "./config/configureStore";
import { fetchData, loadState } from "./actions/videos";
import AppNavigator from "./navigation/AppNavigator";
import NavigationService from "./navigation/actions";
const Root = () => (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<AppNavigator
ref={navigatorRef => {
NavigationService.setTopLevelNavigator(navigatorRef);
}}
/>
</PersistGate>
</Provider>
);
class App extends React.Component {
componentDidMount() {
const { fetchData } = this.props;
fetchData();
}
render() {
return (
<ImageBackground
source={require("./assets/images/TC_background.jpg")}
style={styles.container}
>
<Root />
</ImageBackground>
);
}
}
const mapDispatchToProps = dispatch => ({
fetchData: () => dispatch(fetchData())
});
const mapStateToProps = state => {};
export default connect(
mapStateToProps,
mapDispatchToProps
)(App);
var styles = StyleSheet.create({
container: {
flex: 1,
fontFamily: "lato-regular",
backgroundColor: "transparent"
},
backgroundImage: {
flex: 1,
resizeMode: "cover"
}
});
答案 0 :(得分:0)
我想你有减速机和商店,是吗?
如果您有这样的尝试
您还可以这样编写您的调度方法
export default connect(matStateToProps, mapDispatchToProps)(App)
您还可以这样编写您的调度方法
const matDispatchToProps = {
fetchData,
}