Skip to content

Instantly share code, notes, and snippets.

@jtomaszewski
Last active July 9, 2019 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtomaszewski/fd6c3c1e0696cf0b5d11c3fef6f616e2 to your computer and use it in GitHub Desktop.
Save jtomaszewski/fd6c3c1e0696cf0b5d11c3fef6f616e2 to your computer and use it in GitHub Desktop.
// Action creator function
function fetchArticles(params = {}) {
return dispatch => {
dispatch({ type: 'FETCH_ARTICLES_START', params });
ArticlesService.getArticles(params).then(
response => {
dispatch({
type: 'FETCH_ARTICLES_SUCCESS',
data: response.data
});
},
error => {
dispatch({ type: 'FETCH_ARTICLES_FAILURE', error });
}
);
};
}
// Configuration
const store = createStore(
reducer,
applyMiddleware(thunk)
);
// Usage
dispatch(fetchArticles());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment