eyasliu / redux-async-await

redux middleware to es7 async/await syntax action and promise action
10 stars 0 forks source link

redux-thunk question #1

Open gozes opened 7 years ago

gozes commented 7 years ago

do I need use redux thunk with this middle where if my action creator calls store.dispatch/dispatch before calling an async function/arrow function?

MaxOrelus commented 7 years ago

I did it with redux-thunk and it works well.

const actionSomething = () => (dispatch, getState) => {
  dispatch(/* pending like action type */);

  try {
    const data = async () => {
      return await fetch('URL').then(response => response.data)
        .catch(err => err);
    }
  } catch (err) {
    return dispatch(/* failed like action */);
  }

  return dispatch(/* success like action */);
}