SHARE
TWEET

Redux Thunk

joygabriel21 Jan 21st, 2020 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top