How to implement redux thunk actions with offline functionality?

Viewed 396

For a project i need to implement some kind of offline redux-action queue. And i'm using redux-thunk for async actions. But i saw that libraries like redux-offline can't handle async actions with redux thunk yet.

Does anyone have an idea how i can best tackle this?

My actions look like this:

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 Answers
Related