How to get action.params from saga

Amio.io picture Amio.io · Jul 27, 2016 · Viewed 9.6k times · Source

I am using redux-saga. In the code yield* ReduxSaga.takeEvery('MY_ACTION', updatePorts); how can I access the action to get its fields.

For example I have an action creator:

function status(){
  type: 'MY_ACTION',
  status: true
} 

How can I access action.status from my saga? Or do I have to access data only via getState() and select?

Answer

Kokovin Vladislav picture Kokovin Vladislav · Jul 27, 2016
const actionCreator=()=>({
  type: 'MY_ACTION',
  status:true
})

 function* updatePorts(action) {
  console.log(action.status)
}

function* watchUpdatePorts() {
  yield* takeEvery('MY_ACTION', updatePorts)
}

https://github.com/redux-saga/redux-saga/tree/master/docs/api#takeeverypattern-saga-args