for more information see docs for take(pattern)
Spawns a saga
on each action dispatched to the Store that matches
pattern
. After spawning a task once, it blocks until spawned saga completes
and then starts to listen for a pattern
again.
In short, takeLeading
is listening for the actions when it doesn't run a
saga.
In the following example, we create a basic task fetchUser
. We use
takeLeading
to start a new fetchUser
task on each dispatched
USER_REQUESTED
action. Since takeLeading
ignores any new coming task
after it's started, we ensure that if a user triggers multiple consecutive
USER_REQUESTED
actions rapidly, we'll only keep on running with the leading
action
import { takeLeading } from redux-saga/effects
function* fetchUser(action) { ... }
function* watchLastFetchUser() { yield takeLeading('USER_REQUESTED', fetchUser) }
takeLeading
is a high-level API built using take
and call
. Here is how
the helper could be implemented using the low-level Effects
const takeLeading = (patternOrChannel, saga, ...args) => fork(function*() { while (true) { const action = yield take(patternOrChannel); yield call(saga, ...args.concat(action)); } })
for more information see docs for take(pattern)
arguments to be passed to the started task. takeLeading
will
add the incoming action to the argument list (i.e. the action will be the
last argument provided to saga
)
Spawns a saga
on each action dispatched to the Store that matches
pattern
. After spawning a task once, it blocks until spawned saga completes
and then starts to listen for a pattern
again.
In short, takeLeading
is listening for the actions when it doesn't run a
saga.
In the following example, we create a basic task fetchUser
. We use
takeLeading
to start a new fetchUser
task on each dispatched
USER_REQUESTED
action. Since takeLeading
ignores any new coming task
after it's started, we ensure that if a user triggers multiple consecutive
USER_REQUESTED
actions rapidly, we'll only keep on running with the leading
action
import { takeLeading } from redux-saga/effects
function* fetchUser(action) { ... }
function* watchLastFetchUser() { yield takeLeading('USER_REQUESTED', fetchUser) }
takeLeading
is a high-level API built using take
and call
. Here is how
the helper could be implemented using the low-level Effects
const takeLeading = (patternOrChannel, saga, ...args) => fork(function*() { while (true) { const action = yield take(patternOrChannel); yield call(saga, ...args.concat(action)); } })
for more information see docs for take(pattern)
Spawns a saga
on each action dispatched to the Store that matches
pattern
. After spawning a task once, it blocks until spawned saga completes
and then starts to listen for a pattern
again.
In short, takeLeading
is listening for the actions when it doesn't run a
saga.
In the following example, we create a basic task fetchUser
. We use
takeLeading
to start a new fetchUser
task on each dispatched
USER_REQUESTED
action. Since takeLeading
ignores any new coming task
after it's started, we ensure that if a user triggers multiple consecutive
USER_REQUESTED
actions rapidly, we'll only keep on running with the leading
action
import { takeLeading } from redux-saga/effects
function* fetchUser(action) { ... }
function* watchLastFetchUser() { yield takeLeading('USER_REQUESTED', fetchUser) }
takeLeading
is a high-level API built using take
and call
. Here is how
the helper could be implemented using the low-level Effects
const takeLeading = (patternOrChannel, saga, ...args) => fork(function*() { while (true) { const action = yield take(patternOrChannel); yield call(saga, ...args.concat(action)); } })
for more information see docs for take(pattern)
arguments to be passed to the started task. takeLeading
will
add the incoming action to the argument list (i.e. the action will be the
last argument provided to saga
)
Spawns a saga
on each action dispatched to the Store that matches
pattern
. After spawning a task once, it blocks until spawned saga completes
and then starts to listen for a pattern
again.
In short, takeLeading
is listening for the actions when it doesn't run a
saga.
In the following example, we create a basic task fetchUser
. We use
takeLeading
to start a new fetchUser
task on each dispatched
USER_REQUESTED
action. Since takeLeading
ignores any new coming task
after it's started, we ensure that if a user triggers multiple consecutive
USER_REQUESTED
actions rapidly, we'll only keep on running with the leading
action
import { takeLeading } from redux-saga/effects
function* fetchUser(action) { ... }
function* watchLastFetchUser() { yield takeLeading('USER_REQUESTED', fetchUser) }
takeLeading
is a high-level API built using take
and call
. Here is how
the helper could be implemented using the low-level Effects
const takeLeading = (patternOrChannel, saga, ...args) => fork(function*() { while (true) { const action = yield take(patternOrChannel); yield call(saga, ...args.concat(action)); } })
Spawns a
saga
on each action dispatched to the Store that matchespattern
. After spawning a task once, it blocks until spawned saga completes and then starts to listen for apattern
again.In short,
takeLeading
is listening for the actions when it doesn't run a saga.Example
In the following example, we create a basic task
fetchUser
. We usetakeLeading
to start a newfetchUser
task on each dispatchedUSER_REQUESTED
action. SincetakeLeading
ignores any new coming task after it's started, we ensure that if a user triggers multiple consecutiveUSER_REQUESTED
actions rapidly, we'll only keep on running with the leading actionimport { takeLeading } from
redux-saga/effects
function* fetchUser(action) { ... }
function* watchLastFetchUser() { yield takeLeading('USER_REQUESTED', fetchUser) }
Notes
takeLeading
is a high-level API built usingtake
andcall
. Here is how the helper could be implemented using the low-level Effectsconst takeLeading = (patternOrChannel, saga, ...args) => fork(function*() { while (true) { const action = yield take(patternOrChannel); yield call(saga, ...args.concat(action)); } })