Android 未处理的JS异常:找不到";商店「;在上下文或道具中

Android 未处理的JS异常:找不到";商店「;在上下文或道具中,android,ios,react-native,redux,react-redux,Android,Ios,React Native,Redux,React Redux,它在Android上运行得很好,但在iOS上运行会在启动时失败。它给我留下了一个空白屏幕 未处理的JS异常:在“连接(t)”的上下文或道具中找不到“存储”。将根组件包装在中,或者显式地将“store”作为prop传递给“Connect(t)” 我有我的商店作为道具: import React, { Component } from 'react' import { Provider } from 'react-redux' import RootContainer from './Root' i

它在
Android
上运行得很好,但在
iOS
上运行会在启动时失败。它给我留下了一个空白屏幕

未处理的JS异常:在“连接(t)”的上下文或道具中找不到“存储”。将根组件包装在中,或者显式地将“store”作为prop传递给“Connect(t)”

我有我的
商店
作为道具:

import React, { Component } from 'react'
import { Provider } from 'react-redux'
import RootContainer from './Root'
import createStore from './Redux'
// import applyConfigSettings from './config'
// applyConfigSettings()

const store = createStore()

class App extends Component {
  render () {
    return (
      <Provider store={store}>
        <RootContainer />
      </Provider>
    )
  }
}

export default App
编辑

Redux/index.js

import { createStore, applyMiddleware, compose } from 'redux'
import { autoRehydrate } from 'redux-persist'
import createLogger from 'redux-logger'
import Config from './../config/DebugSettings'
import createSagaMiddleware from 'redux-saga'
import R from 'ramda'
import RehydrationServices from './../services/RehydrationServices'
import ReduxPersist from './../config/ReduxPersist'
import { StartupTypes } from './StartupRedux'

// creates the store
export default (rootReducer, rootSaga) => {
  /* ------------- Redux Configuration ------------- */

  const middleware = []
  const enhancers = []

  /* ------------- Saga Middleware ------------- */

  const sagaMiddleware = createSagaMiddleware()
  middleware.push(sagaMiddleware)

  /* ------------- Logger Middleware ------------- */

  const SAGA_LOGGING_BLACKLIST = ['EFFECT_TRIGGERED', 'EFFECT_RESOLVED', 'EFFECT_REJECTED', 'persist/REHYDRATE']
  if (__DEV__) {
    // the logger master switch
    const USE_LOGGING = Config.reduxLogging
    // silence these saga-based messages
    // create the logger
    const logger = createLogger({
      predicate: (getState, { type }) => USE_LOGGING && R.not(R.contains(type, SAGA_LOGGING_BLACKLIST))
    })
    middleware.push(logger)
  }

  /* ------------- Reactotron Enhancer ------------- */

  // in dev, let's bring **START** with Reactotron's store enhancer
  if (__DEV__) {
    // only bring in Reactotron in dev mode
    // const createReactotronEnhancer = require('reactotron-redux')
    //
    // // create it
    // const reactotronEnhancer = createReactotronEnhancer(console.tron, {
    //   // you can flag some of your actions as important by returning true here
    //   isActionImportant: action =>
    //     action.type === StartupTypes.STARTUP,
    //
    //   // you can flag to exclude certain types too... especially the chatty ones
    //   except: [...SAGA_LOGGING_BLACKLIST]
    // })
    // enhancers.push(reactotronEnhancer)
  }

  /* ------------- Assemble Middleware ------------- */

  enhancers.push(applyMiddleware(...middleware))

  /* ------------- AutoRehydrate Enhancer ------------- */

  // add the autoRehydrate enhancer
  if (ReduxPersist.active) {
    enhancers.push(autoRehydrate())
  }

  const store = createStore(rootReducer, compose(...enhancers))

  // configure persistStore and check reducer version number
  if (ReduxPersist.active) {
    RehydrationServices.updateReducers(store)
  }

  // kick off root saga
  sagaMiddleware.run(rootSaga)

  return store
}
export default () => {
  /* ------------- Assemble The Reducers ------------- */
  const rootReducer = combineReducers({
    data: require('./DataRedux').reducer,
  })

  return configureStore(rootReducer, rootSaga)
}

您必须为从Redux.js文件导入的createStore函数提供rootReducer。Redux存储必须有根reducer:)您也可以从他们自己的文档中看到这一点


看起来您正在使用样板启动器,其中有许多代码您还不了解,这很好。在学习Redux时,我建议浏览他们自己的文档,真正了解正在发生的事情:)

你能展示一下Redux.js文件的内部内容吗?@HenrikR我已经添加了代码我确实在使用样板文件(Ignite)。。他们在Redux文件夹中有一个index.js文件,该文件使用reducer创建存储(请参见编辑)。奇怪的是,它在安卓系统中工作,虽然我发现了问题,但我真的很愚蠢。我将
ios
文件链接到错误的文件(不是带有
提供程序的文件)。它正在工作。感谢您的帮助和官方文档的链接
export default () => {
  /* ------------- Assemble The Reducers ------------- */
  const rootReducer = combineReducers({
    data: require('./DataRedux').reducer,
  })

  return configureStore(rootReducer, rootSaga)
}