in React JS by
Q:

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

1 Answer

0 votes
by

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
  })
}
Click here to read more about React JS
Click here to read more about Insurance

Related questions

0 votes
asked Mar 4, 2020 in React JS by JackTerrance
0 votes
asked Dec 8, 2020 in React JS by SakshiSharma
0 votes
asked Jul 2, 2019 in React JS by Venkatshastri
0 votes
asked Jun 19, 2020 in React JS by JackTerrance
0 votes
asked Mar 23, 2020 in SAP by AdilsonLima
0 votes
asked Oct 18, 2019 in C Sharp by Robin
...