reactjs - 警告 : Unexpected key "A" found in previou

我在 ES6 的 require.ensure()react-routergetComponent() 的帮助下动态添加组件>。一旦我为具有相同键(例如“A”)的每条记录打开单独的选项卡,我就会收到上述错误。我的动态加载是这样的:

 require.ensure([], (require) => { 
     const req = require('./components/A).default 
     const reducer= require('./modules').default
     injectReducer(store, {
         key: 'A',
         reducer
     })
     cb(null, req)
 })

我的 createstore() 代码是这样的:

export const makeRootReducer = (asyncReducers) => {
  return combineReducers({
    B,
    C,
    ...asyncReducers
  })
}
export const injectReducer = (store, { key, reducer }) => {
  if (Object.hasOwnProperty.call(store.asyncReducers, key))return
  store.asyncReducers[key] = reducer
  store.replaceReducer(makeRootReducer(store.asyncReducers))
}

现在的问题是,在打开浏览器选项卡时,除了第一次将警告显示为:

Unexpected key " A" found in previous state received by the reducer Expected to find one of the known reducer keys instead: "B", "C". Unexpected keys will be ignored.

如果我最初传递 Key 'A' combineReducers() 那么这个警告就会消失。但是这个 combineReducers() 是全局的,它将保持 reducers 的状态,所以我不想在初始加载时传递这个 Key。我该如何解决这个警告,请帮助我。

最佳答案

我今天遇到了这个问题,因为似乎没有答案我会给出对我有用的答案。

当我使用 createStore 函数设置 initialState 时出现此错误。我没有任何与初始状态树布局相匹配的缩减器,这意味着 redux 忽略了我的一些初始状态。这似乎只是树中第一级键的情况,但似乎很高兴让嵌套键通过。

因此,如果您得到这个,请确保您的 initialState 和 reducer 有一个匹配的树。这也在 the createStore documentation 中描述。 .

关于reactjs - 警告 : Unexpected key "A" found in previous state received by the reducer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41826224/

相关文章:

ipython-notebook - jupyter:没有可用的内核

.net - 如何配置 NHibernate 以使用 MS SQL 2016 (RTM)?

google-maps - 如何在 angular2 中显示带有地址的谷歌地图

sql - 如何将某个 SQL 列移动到表中的不同位置?

javascript - 谷歌登录 : disable autologin on page load

ajax - perl 中是否允许使用单个元素列表?

javafx - 使用多个值过滤 JFX TableView

python-3.x - python : How to call a variable in an

html - Bootstrap 导航栏品牌链接不起作用

javascript - 如何在 v-for 中访问对象属性名称