我有react-native + redux应用程序。在此应用程序中,我大约有10个组成部分(音乐,电影等) 但是,我无法正确地将redux连接到react-native。我遇到错误“无法在...的上下文或道具中找到商店”
我的App.js文件
import App from './src/index';
export default App;
还有我的index.js文件
import React, { Component } from 'react'
import { View } from 'react-native'
import { AppNavigator } from './nav/nav'
import { createStore, applyMiddleware } from 'redux';
import { Provider, connect } from 'react-redux';
import axios from 'axios';
import axiosMiddleware from 'redux-axios-middleware';
import reducer from './store/reducer';
import { listPosts } from './store/reducer';
const client = axios.create({
baseURL: 'https://xxxxxx.xxx',
responseType: 'json'
});
const store = createStore(reducer, applyMiddleware(axiosMiddleware(client)));
class App extends Component {
render() {
return (
<Provider store={store}>
<View style={{ flex: 1 }}>
<AppNavigator />
</View>
</Provider>
)
}
}
const mapStateToProps = state => {
let storedPosts = state.posts.map(repo => ({ key: repo.id, ...repo }));
return {
posts: storedPosts
};
};
const mapDispatchToProps = {
listPosts
};
export default connect(mapStateToProps, mapDispatchToProps)(App);