如何使用离线功能实施redux thunk操作?

时间:2019-06-04 09:05:15

标签: reactjs redux offline redux-thunk

对于一个项目,我需要实现某种离线离线操作队列。 而且我正在使用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 };
}

0 个答案:

没有答案
相关问题