reactjs - Redux 和 Sagas:无法正确连接
问题描述
我有一个使用 Saga 和 Redux Store 的项目,这是项目引导方法:
import { createStore, applyMiddleware } from 'redux';
import { Provider } from 'react-redux';
import { fork } from 'redux-saga/effects';
...
const bootstrap = async () => {
const configuration = await config.env();
init(configuration);
const rootReducer = combineReducers({
...reducers,
})
function* rootSaga() {
yield sagas.map(saga => fork(saga))
}
const sagaMiddleware = createSagaMiddleware();
const store = createStore(rootReducer, applyMiddleware(sagaMiddleware));
const App = (): Element<*> => (
<Provider store={store}>
<div>
<WorstProjectInMyLife />
</div>
</Provider>
);
sagaMiddleware.run(rootSaga);
ReactDOM.render(<App />, document.getElementById('app'));
};
bootstrap();
这就是我们向 props 发送状态的地方:
import { createSelector } from 'reselect';
const selectIsFetching = createSelector(
parentSelector,
(parentState: StateRecord = new StateRecord()) => parentState.isFetching
);
const mapStateToProps = (state: StateType) => ({
isFetching: selectIsFetching(state)
});
const mapDispatchToProps = {
...actions
};
export default connect(mapStateToProps, mapDispatchToProps)(WorstProjectInMyLife);
但是商店总是空的,所以我担心这没有正确连接。各位大佬能看一下,是不是我漏了什么?我真的已经为此苦苦挣扎了几天并且精神恍惚,因为不知道为什么这不起作用。谢谢你的帮助
解决方案
我试图设置一个类似于你的简单场景,它似乎有效。你能提供更多的上下文和代码吗?应用程序的整个状态一开始是未定义的?(记住您没有定义默认状态)父选择器是否正常工作?
推荐阅读
- regex - 正则表达式在字符串中有一个强制字符
- gyroscope - 无法使用 watchOS 5 获取核心运动更新:“[Gyro] Manually set gyro-interrupt-calibration to 800”
- php - PHP:如何发送 ssh 命令而不是等到它执行?
- clojure - Clojure 宏:从地图创建本地变量
- php - 发送 json 数据时 PHP API 的行为发生变化
- c# - 如何在 SQL Server 中创建一个列来保存不同类型的值
- google-cloud-platform - 如何通过谷歌点击部署在 GKE 中配置的外部 Prometheus 和 Grafana Dashboards 公开
- r - 将测试的输出存储在新变量、向量等中
- groovy - 如何将 Map 的流分组到 Map
>? - javascript - Event.target 仅适用于第一个孩子