Skip to content

Instantly share code, notes, and snippets.

@kulor
Created May 3, 2018 15:03
Show Gist options
  • Save kulor/b1b424f6bf578cd2814a67d04c4c1d9d to your computer and use it in GitHub Desktop.
Save kulor/b1b424f6bf578cd2814a67d04c4c1d9d to your computer and use it in GitHub Desktop.
Example Redux Offline action
const followUser = userId => ({
type: 'FOLLOW_USER_REQUEST',
payload: { userId },
meta: {
offline: {
// the network action to execute:
effect: { url: '/api/follow', method: 'POST', body: JSON.stringify({ userId }) },
// action to dispatch when effect succeeds:
commit: { type: 'FOLLOW_USER_COMMIT', meta: { userId } },
// action to dispatch if network action fails permanently:
rollback: { type: 'FOLLOW_USER_ROLLBACK', meta: { userId } }
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment