Anthony Chung
Anthony Chung

Reputation: 1477

redux sagas - block dispatched action

If action FOO is dispatched and my saga starts a task via takeEvery(FOO),

Is it possible to mutate the action being dispatched so I have START_FOO instead of FOO reaching the reducer?

I know that I can have START_FOO reach the reducer via yield put({ type: START_FOO })

Upvotes: 1

Views: 1703

Answers (2)

Evgeniy Pozdnyakov
Evgeniy Pozdnyakov

Reputation: 73

Try the following:

  1. Ignore the FOO action in reducer, but change your state when START_FOO comes.
  2. Listen for the FOO action in saga. When it comes you could create a new (modified) payload and dispatch it with START_FOO action.

Upvotes: 0

markerikson
markerikson

Reputation: 67627

No. The Redux-Saga middleware always passes a dispatched action to the next middleware in the chain before trying to process it, so an action will always reach the reducers first. You would need some other middleware to modify the action instead. Redux-Saga effectively only views actions, and doesn't let you modify them.

Upvotes: 1

Related Questions