javascript - Redux Dev Tools Chrome 扩展 Immutable.js 导致错误

标签 javascript redux immutable.js redux-devtools

目前,我的 redux 设置(利用 Immutable.js 来实现其状态)完全按照预期运行。但是,每当打开时,redux dev 工具扩展都会输出以下错误:

An error occurred in the reducer TypeError: n.withMutations is not a function

对于上下文,我使用 redux-immutable因为它的组合 reducer 功能可以组合我的react-router-redux reducer :

import { fromJS } from 'immutable';
import { LOCATION_CHANGE } from 'react-router-redux';

const initialState = fromJS({
  locationBeforeTransitions: null,
});

export default (state = initialState, action) => {
  if (action.type === LOCATION_CHANGE) {
    return state.merge({
      locationBeforeTransitions: action.payload,
    });
  }
  return state;
};

以及我的业务逻辑 reducer 。

更新:使用 webpack 构建生产包,在生产模式下测试应用程序(在 docker 容器中),然后在开发模式下再次测试应用程序(在没有 docker 的本地计算机上)似乎已经解决了问题?奇怪...

最佳答案

如果你想使用react-router-redux,不需要自己实现reducer, 只需从 react-router-redux 导入 routerReducer 作为关键路由(重要),如下所示,并与其他 reducer 结合使用,

import { syncHistoryWithStore, routerReducer } from 'react-router-redux'
// Add the reducer to your store on the `routing` key
const store = createStore(
  combineReducers({
    ...reducers,
    routing: routerReducer
  })
)

//To Sync navigation events with the store
const history = syncHistoryWithStore(browserHistory, store)

ReactDOM.render(
  <Provider store={store}>
    { /* Tell the Router to use our enhanced history */ }
    <Router history={history}>
      <Route path="/" component={App}>
        <Route path="foo" component={Foo}/>
        <Route path="bar" component={Bar}/>
      </Route>
    </Router>
  </Provider>,
  document.getElementById('mount')
)

希望这就是您想要实现的

关于javascript - Redux Dev Tools Chrome 扩展 Immutable.js 导致错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36950112/

相关文章:

javascript - 在不更改标记大小的情况下,使用 plotly proxy 在 plotly 中更改跟踪标记的颜色

javascript - 表达式的 Angular 惰性一次性绑定(bind)

javascript - React.js Redux reducer 不插入项目

javascript - 如何读取不可变列表中的不可变记录?

javascript - ImmutableJS 如何获取对象内部的值?

javascript - 如何捕获浏览器关闭事件并通过 JavaScript 向该事件的 Web 服务方法发出请求

javascript - 自定义属性附加事件太早了?

javascript - React 组件无法从 API 映射和渲染数组中的数据

reactjs - reducer 的测试返回不等于预期的结果

javascript - 无法将 List 模块从 immutable.js 导入 Angular 2 项目