OpenGG

async action using redux-thunk

Oct 24th, 2016
702
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const loadMeme = () =>
  2.   async(dispatch) => {
  3.     let result;
  4.     dispatch({
  5.       type: 'MEME_LOADING',
  6.     });
  7.     const offset = store.getState().meme.offset;
  8.     try {
  9.       result = await fetchMeme(offset);  // promise
  10.     } catch (e) {
  11.       return dispatch({
  12.         type: 'MEME_FAIL',
  13.       });
  14.     };
  15.     dispatch({
  16.       type: 'MEME_APPEND',
  17.       list: result.list,
  18.       offset: result.offset,
  19.     });
  20.   };
Advertisement
Add Comment
Please, Sign In to add comment