我使用以下博客文章中的示例代码制作了一个简单的反应应用程序,我仅将其作为引用。我对 javascript 生态系统还是陌生的,并且正在尝试将几个不熟悉的工具组合在一起(以便学习它们)。
相关地,我的store.js
样子是这样的:
import { createStore, applyMiddleware, compose, } from 'redux';
import { connectRouter, routerMiddleware, } from 'connected-react-router';
import thunk from 'redux-thunk';
import { install, } from 'redux-loop';
import createHistory from 'history/createBrowserHistory';
import rootReducer from './modules';
export const history = createHistory();
const initialState = {};
const middleWare = [thunk, routerMiddleware(history),];
const composedEnhancers = compose(
applyMiddleware(...middleWare),
install()
);
const store = createStore(
connectRouter(history)(rootReducer),
initialState,
composedEnhancers
);
export default store;
这似乎工作正常,我页面上的Link
/Route
触发器工作正常。请注意,install
fromredux-loop
被称为增强器(?)的一部分,这很好。我的减速器中没有任何loop
调用,我只是将install
命令作为增强器插入,希望能够添加一些。
这是我的主要reducer
代码:
import { combineReducers, } from 'redux';
import counter from './counter';
import todo from './todo';
export default combineReducers({
counter,
todo,
});
同样,这很好用。loop
但是,如果我在减速器中插入任何位置,它就会死掉。根据文档,这是因为我们需要使用combineReducers
from redux-loop
。美好的。如果我将顶部的导入替换为import { combineReducers, } from 'redux-loop';
(根本不改变我的减速器,还没有非标准的返回),那么我会在库代码中得到一些完全无意义的错误:
ConnectedRouter.js:58 Uncaught TypeError: Cannot read property 'pathname' of undefined
at ConnectedRouter.js:58
at Object.dispatch (redux.js:221)
at dispatch (install.js:66)
at middleware.js:25
at index.js:11
at Object.onLocationChanged (ConnectedRouter.js:154)
at handleLocationChange (ConnectedRouter.js:85)
at new ConnectedRouter (ConnectedRouter.js:94)
at constructClassInstance (react-dom.development.js:11769)
at updateClassComponent (react-dom.development.js:13491)
at beginWork (react-dom.development.js:14090)
at performUnitOfWork (react-dom.development.js:16416)
at workLoop (react-dom.development.js:16454)
at renderRoot (react-dom.development.js:16533)
at performWorkOnRoot (react-dom.development.js:17387)
at performWork (react-dom.development.js:17295)
at performSyncWork (react-dom.development.js:17267)
at requestWork (react-dom.development.js:17155)
at scheduleWork (react-dom.development.js:16949)
at scheduleRootUpdate (react-dom.development.js:17637)
at updateContainerAtExpirationTime (react-dom.development.js:17664)
at updateContainer (react-dom.development.js:17691)
at ReactRoot../node_modules/react-dom/cjs/react-dom.development.js.ReactRoot.render (react-dom.de...
它持续了很多页,但问题似乎出在ConnectedRouter
; 我认为这是因为combineReducers
in将主减速器的响应类型更改为与调用redux-loop
中的不兼容的内容connectRouter(history)(rootReducer)
。createStore
这是正确的问题吗?这是可以修复的吗?这两个库可以一起使用吗?