Raymond
Raymond

Reputation: 137

How to dispatch action just when another action will be done, with sagas?

I have a timeout, which prints tick in console with 1000ms delay. This timeout start by action TICK. How can I dispatch another action with redux-saga just after timeout?

Upvotes: 1

Views: 270

Answers (1)

kind user
kind user

Reputation: 41913

If your saga, lets call it SagaA listens to the TICK action, you could use an effect called delay, so the next action will be dispatched with a timeout.

function* sagaA() {
   yield take('TICK');
   yield delay(1000);
   yield put(/* your action */); // will be fired 1s after `TICK` was dispatched
}

Upvotes: 3

Related Questions