reactjs - 如何使用离线功能实现 redux thunk 操作?
问题描述
对于一个项目,我需要实现某种离线 redux-action 队列。我正在使用 redux-thunk 进行异步操作。但是我看到像 redux-offline这样的库还不能处理带有 redux thunk 的异步操作。
有谁知道我怎样才能最好地解决这个问题?
我的动作是这样的:
export function fetchIdeasForOrganisationAction(organisation) {
const options = {
credentials: 'include',
};
return async (dispatch) => {
try {
const response = await fetch(`http://${SERVER_URL}:${SERVER_PORT}/organisations/${organisation}/shared/ideas`, options);
if (!response.ok) throw Error();
const ideas = await response.json();
dispatch(newIdeasFetched(ideas));
} catch (e) {
dispatch(noIdeasFoundAction('No ideas found '));
}
};
}
function newIdeasFetched(ideas) {
return { type: "NEW_IDEAS_FETCHED", value: ideas };
}
function noIdeasFoundAction(errorMessage) {
return { type: 'NO_IDEAS_FOUND', errorMessage };
}
解决方案
推荐阅读
- kivy - 如何摆脱 Kivymd Hot reload Viewer Error
- flutter - 如何在颤动中使用listTile将字符串放在一个圆圈内?
- react-native - react native - 为什么我的 console.log 返回 [] 但项目会在屏幕上呈现?
- python - 成功 url 在我基于类的 DeleteView 中不起作用
- python - Python Regex 检测字母之间的下划线
- php - 验证单个产品页面中“添加到购物车”上方添加的自定义字段
- javascript - 使用 Google API 自动完成用户地址字段
- python - 在 Mongoengine 中填充,参考字段
- github - GitHub Action - 从分支 A 推送到分支 B 时触发,但不分支到分支 B
- sql - 根据时间值折叠多行