轮询既可以放在组件的生命周期中开始出发,或使用setTimeout。或更高级的使用service worker,方法有很多,但在使用中想要避免在组件中引入过多这种逻辑,就可以使用redux-saga
来做,非常的简单高效:
// 使用saga/effects中的fork,在启动时自动调用
export default function* saga() {
yield fork(watchPollData);
}
function* watchPollData() {
while (true) {
yield delay(5000); // 延迟的毫秒数
yield put(loadDataAction());
}
}
网友评论