目前,我的redux设置(将Immutable.js用于其状态)完全按照需要运行。但是,只要打开,redux dev工具扩展就会输出以下错误:
reducer中发生错误 TypeError:n.withMutations不是函数
对于上下文,我正在使用redux-immutable来组合reducers函数,以及我的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;
};
和我的业务逻辑缩减器。
更新:使用webpack构建生产包,在生产模式下(在docker容器中)测试应用程序,并在开发模式下再次测试应用程序(在没有docker的本地计算机上)似乎解决了问题?奇...
答案 0 :(得分:1)
如果您想使用react-router-redux
,则无需自行实施减速机,
只需将routerReducer作为密钥路由(重要)从react-router-redux
导入,如下所示,并与其他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')
)
希望这是您正在尝试实施的目标