Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 963
Venelin Mihaylov Avatar asked Oct 30 '22 22:10

Venelin Mihaylov


1 Answers

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

like image 129
Venelin Mihaylov Avatar answered Nov 09 '22 08:11

Venelin Mihaylov