The exit is inside. Then the promise response function throws an error

The following code is throwing an error:

  syncData().then((x) => yield put(loginUserSuccess(responseData)));

      

Error: Reserved keyword 'yield'.

Data sync handles asynchronous data fetching operations. I want to use yield put (provided by sagas.js) to trigger the user login success of the action user after the sync data is done.

The core of the syncData function looks like this:

  export default async function syncData(dataType) {
      await Promise.all([syncData1(), syncData2()]);
  }

      

+3


source to share


1 answer


Try to split it like this using effect call

and then effect put

:



try {
  const res = yield call(syncData) 

  yield put(loginUserSuccess(res))

} catch(e) {

  yield put(loginUserFail(e))

}

      

+2


source







All Articles