I'am trying to implement Redux-offline in my react-native app for this i have installed the module and i have added offline to my createStore
method :
const store = createStore(
myReducer,
compose(
offline(offlineConfig),
applyMiddleware(thunk, promiseMiddleware())
)
);
this is the action that uses redux-offline :
export const addResources = resource => ({
type: "ADD_RESOURCES",
payload: resource,
meta: {
offline: {
// the network action to execute:
effect: {
url: "https://reqres.in/api/users",
method: "POST",
json: {
body: { name: "paul rudd", movies: ["Fake data", "Fake text"] }
}
},
// action to dispatch when effect succeeds:
commit: { type: "FOLLOW_ADD_RESOURCE", meta: { resource } },
// action to dispatch if network action fails permanently:
rollback: { type: "ADD_RESOURCE_ROLLBACK", meta: { resource } }
}
}
});
for the sake of explanation i'am using a sample dummy API that accepts the creation of new users and return an id as a response.
My problem is that the commit
action never gets called after dispatching my ADD_RESOURCES
action, on the other hand therollback
gets called if i'am sending a bad request.
This is my reducer:
let tempList = state.list.concat();
switch (action.type) {
case ADD_RESOURCES:
console.log("add resources action");
return Object.assign({}, state, {
list: tempList
});
case FOLLOW_ADD_RESOURCE:
console.log(" *** FOLLOW_ADD_RESOURCE **", res);
return Object.assign({}, state, {
list: tempList
});
case ADD_RESOURCE_ROLLBACK:
console.log("ADD_RESOURCE_ROLLBACK");
return Object.assign({}, state, {
list: tempList
});
default:
return state;
}
PS: i'am testing this on Pixel 2 xl API 27 emulator, with and without wifi and 3G internet connection.
As i said the commit action never get dispatched, does anyone know what did i get wrong ?