How can I know when a redux-saga function has completed in the calling code
Asked Answered
B

1

7

React, redux, redux-saga

I dispatch an action, say CREATE_REQUESTED to the store. Redux-saga runs, and makes the async call to the server. After the saga completes, i.e. blocks for the next CREATE_REQUESTED I want to execute additional code, from the container/component from which the first CREATE_REQUESTED was initiated.

// pseudo code
class Cmp extends React.component {
   onCreateClick(id) {
     const record = {id, name: 'alabala'}
     // I am missing the .then() part
     this.props.dispatch({type: 'CREATE_REQUESTED', record}).then(created => {
        console.log(created)
     }
   }
}

Is there a way to do that? How? If not, how am I supposed to design this task?

Brodench answered 8/8, 2016 at 14:50 Comment(0)
B
4

One approach could be to pass (resolve, reject) options along with the action, and make the saga call them on succcess/failure. Seems OK.

https://github.com/yelouafi/redux-saga/issues/161

Brodench answered 8/8, 2016 at 15:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.