Advertisement
joygabriel21

Redux Thunk

Jan 21st, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. const actionsCreator = {
  2. `fetchUsers: () => {
  3. return function (dispatch) {
  4. dispatch(actionCreators.requestUsers());
  5.  
  6. return fetch("https://jsonplaceholder.typicode.com/users")
  7. .then(
  8. response => {
  9. if (response.ok) {
  10. return response.json()
  11. }
  12. throw new Error("404");
  13. }
  14. )
  15. .then(json =>
  16. dispatch(actionCreators.requestUsersSuccess(json))
  17. ).catch(error => {
  18. console.error(error);
  19. dispatch(actionCreators.requestUsersError(error))
  20. })
  21. }
  22. }`
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement