【发布时间】:2025-12-26 06:25:12
【问题描述】:
我正在尝试使用 saga 中间件和异步操作以及 react-router-redux 和选择器建立一个 react redux 存储。
对于某些 sagamiddleware 无法读取未定义的属性 getState。我不知道为什么。
我的*目录结构是:
./src/app.js
./src/sagas/index.js and imported sagas into this file
./src/Containers/App/actions.js constants.js appReducer.js selectors.js
./src/Containers/App/toplevelcomponenthere
app.js
import sagas from './sagas';
import createReducer from './reducers.js';
const sagaMiddleware = createSagaMiddleware();
const createStoreWithMiddleware = applyMiddleware(reduxRouterMiddleware,
sagaMiddleware(...sagas))(createStore);
const store = createStoreWithMiddleware(createReducer);
const reduxRouterMiddleware = syncHistoryWithStore(browserHistory)
//add selectors and history
import { selectLocationState } from './Containers/App/selectors';
const history = syncHistoryWithStore(browserHistory, store, {
selectLocationState: selectLocationState(),
});
class Base extends Component {
render() {
return (
<Provider store={store}>
{children}
</Provider>
)
}
}
【问题讨论】:
-
你能用
getState添加代码 -
@KevinKloet getState 在 redux-saga 内部中断,请参见此处github.com/yelouafi/redux-saga/blob/… 代码行 1898
标签: javascript reactjs redux redux-saga