我正在尝试在我的 expo 应用程序中创建一个 index.js 文件:
import React from 'react';
import { AppRegistry } from 'react-native';
import App from './App';
import { Provider } from 'react-redux'
import { name as appName } from './app.json';
import {Provider} from 'react-redux';
import reducers from './reducers';
import thunk from 'redux-thunk';
let store = createStore(reducers,applyMiddleware(thunk))
const RNRedux = () => {
<Provider store={store}>
<App/>
</Provider>
}
AppRegistry.registerComponent(appName, () => RNRedux);
我这样做是因为我需要访问 App.js 文件中的商店,但我一直遇到此错误
Error: Could not find "store" in the context of "Connect(App)". Either wrap the root component in a <Provider>, or pass a custom React context provider to <Provider> and the corresponding React context consumer to Connect(App) in connect options.
我也修复了 package.json 中的主文件,但错误仍然存在。对于这个问题有什么想法/其他解决方法吗?将不胜感激!
我猜你的应用程序将包含导航文件夹。所以就这样做吧。
应用程序.js
import store from './store'
const App = () => {
render() {
return (
<Provider store={store}>
<Navigation />
</Provider>
);
}
}
export default App;
Store.js
import { createStore } from "redux";
import rootReducer from "../reducers";
const store = createStore(rootReducer)
export default store;
希望能给你带来想法