Skip to content

Instantly share code, notes, and snippets.

@paulsturgess
Last active February 8, 2017 20:40
Show Gist options
  • Save paulsturgess/2335a83355a22a6d06bf72d2f462a776 to your computer and use it in GitHub Desktop.
Save paulsturgess/2335a83355a22a6d06bf72d2f462a776 to your computer and use it in GitHub Desktop.
Example redux actions using redux-thunk middleware
import Constants from '../path/to/constants';
import Service from '../path/to/service';
const Actions = {
toggleSomething: (id) => ({
type: Constants.TOGGLE_SOMETHING,
id
}),
resourceSuccessfullySaved: (data) => ({
type: Constants.RESOURCE_SUCCESSFULLY_SAVED,
data
}),
saveResource: function(resource) {
return (dispatch) => {
return (
Service.post(
'/your/path',
resource,
(status, data) => {
if (status === 200) {
return dispatch(Actions.resourceSuccessfullySaved(data))
}
}
)
)
}
}
}
export default Actions;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment