【问题标题】:trying to move app point of entry doesn't work (EXPO)尝试移动应用程序入口点不起作用(EXPO)
【发布时间】:2020-08-12 05:32:24
【问题描述】:

我正在尝试在我的 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 中的主文件,但错误仍然存​​在。对此问题有任何想法/其他解决方法吗?将不胜感激!

【问题讨论】:

  • 我看到 Provider 有重复导入。你能去掉一个吗?

标签: react-native redux expo redux-thunk redux-store


【解决方案1】:

我猜您的应用将包含 Navigation 文件夹。所以就这样吧。

App.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;

希望能给你一些启发

【讨论】:

    猜你喜欢
    • 2019-10-22
    • 2018-03-08
    • 2021-10-03
    • 2014-08-16
    • 1970-01-01
    • 2021-12-23
    • 2019-02-04
    • 2022-12-29
    • 2021-10-18
    相关资源
    最近更新 更多