replaceReducer导致reducer在redux中多次调用

时间:2018-04-28 02:30:30

标签: redux

我使用 store.replaceReducer 加载异步模块reducer。

            const reducers = store.reducers; // reducer dictionary to cache

        if (reducers.indexOf(reducer) === -1 && reducer !== defaultReducer) {

            reducers.push(reducer);
            const reducerObj = {};

            reducers.forEach((reducerItem) => {
                Object.assign(reducerObj, reducerItem);
            });

            store.replaceReducer(combineReducers(reducerObj));

事件 第一个模块中的某个操作, reducer 按预期调用。

但是当使用 replaceReducer 将新的缩减器附加到存储时,将再次调用先前的缩减器,并且每次都会在 replaceReducer 之后调用

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

实际上只有在使用开发工具时才会发生这种情况。见https://github.com/reduxjs/redux-devtools/issues/291