Promises in redux-saga

后端 未结 3 720
攒了一身酷
攒了一身酷 2021-02-14 12:26

I found the same question here, but without a proper answer I am looking for.

I am developing a simple application with CRUD operations. On the edit page, after the comp

3条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-14 13:11

    Another solution

    onSubmit: (values) => {
      return new Promise((resolve, reject) => {
        dispatch(someActionCreator({ values, resolve, reject }))
      });
    }
    

    In saga:

    function* saga() {
      while (true) {
        const { payload: { values, resolve, reject } } = yield take(TYPE)
        // use resolve() or reject() here
      }
    }
    

    Reference: https://github.com/redux-saga/redux-saga/issues/161#issuecomment-191312502

提交回复
热议问题