Mar 4, 2020 in React JS
Q:

What are the differences between call() and put() in redux-saga?

1 Answer

0 votes
Mar 4, 2020

Both call() and put() are effect creator functions. call() function is used to create effect description, which instructs middleware to call the promise. put() function creates an effect, which instructs middleware to dispatch an action to the store.

Let's take example of how these effects work for fetching particular user data.

function* fetchUserSaga(action) {
  // `call` function accepts rest arguments, which will be passed to `api.fetchUser` function.
  // Instructing middleware to call promise, it resolved value will be assigned to `userData` variable
  const userData = yield call(api.fetchUser, action.userId)

  // Instructing middleware to dispatch corresponding action.
  yield put({
    type: 'FETCH_USER_SUCCESS',
    userData
  })
}

Related questions

0 votes
Jun 19, 2020 in React JS
  • #reduxsaga
  • #reactjs
0 votes
+1 vote
Jun 25 in Redux
0 votes
Nov 26, 2019 in React JS
...