目前,我的 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/