首页 > 解决方案 > 如何使用离线功能实现 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 };
}

标签: reactjsreduxofflineredux-thunk

解决方案


推荐阅读