call(), put(), take(), and select() are all plain, serializable EFFECT DESCRIPTIONS, not direct function invocations, confirmed by manually stepping a saga generator with .next(): yield call(fakeApi, 42) produces a plain object { '@@redux-saga/IO': true, type: 'CALL', payload: {...} }, never actually calling fakeApi itself until the saga MIDDLEWARE interprets it.
reduxredux-sagaeffectsgeneratorsstate-management
Curated Video Reference
YouTube
Hand-picked video lecture to deepen your understanding of Effects (call, put, take, select)
1. What does yield call(fakeApi, 42) actually produce, confirmed by manually stepping the generator with .next()?
Interview Questions
2 questions
Cheatsheet
Download-ready reference
Cheatsheet
A SAGA = a generator function; each yield = an EFFECT (plain object)
the saga PAUSES at each yield until the MIDDLEWARE resolves it
call(fn, ...args) โ describes "call fn(...args)", NOT invoked yet
CONFIRMED: gen.next().value is a plain object,
fn referenced as DATA, never executed by yield alone
put(action) โ describes "dispatch action", NOT dispatched yet
select(selectorFn) โ reads current state via a selector, resumes IMMEDIATELY
take(actionType) โ PAUSES until a matching action is dispatched
WHO ACTUALLY DOES THE WORK: the saga MIDDLEWARE, not the generator, it reads each yielded description and performs the REAL call/dispatch,
then resumes the generator via gen.next(realResult)
โ ๏ธ NEVER bypass call()/put() with direct calls/dispatch, loses
testability AND middleware manageability (cancel, race, etc.)
โ ๏ธ call(obj.method, ...args) loses `this`, use
call([obj, obj.method], ...args) or .bind(obj) instead
TESTABLE WITHOUT A STORE: step gen.next() manually, compare yielded
plain objects, no real network call, no mocking, no store needed
(see Testing Sagas)
Middleware and createAsyncThunk covered two ways to handle async logic in Redux, hand-written middleware, and RTK's generalized single-request wrapper. redux-saga is a third approach, built on JavaScript generator functions, aimed specifically at complex async workflows: coordinating multiple requests, cancellation, retries, and long-running background processes that createAsyncThunk isn't designed for.
A saga is a generator function. Each yield inside it produces an effect, a plain, descriptive object saying "please do this," not a direct function call. The saga pauses at each yield until the saga middleware (running the generator) resolves that effect and resumes it with a result.
A saga is a GENERATOR, it PAUSES at each yielded effect until the middleware resolves it
step 1 / 4
function* fetchUserSaga(action) {
const user = yield call(api.getUser, action.payload);
yield put({ type: 'USER_LOADED', payload: user });
Confirmed by manually stepping a saga's generator with .next(), with no saga middleware, no store, no real network call involved at all: yield call(fakeApi, 42) produces a plain, inspectable JavaScript object describing "call fakeApi with argument 42", fakeApi itself is never actually invoked at this point. It's the saga middleware, running separately, that receives this description, genuinely calls fakeApi(42), waits for its result, and resumes the paused generator by calling gen.next(result), injecting the resolved value back in as the return value of the original yield call(...) expression.
function* exampleSaga(action) { const result = yield call(api.getData, action.id); // CALL a function, wait for its return/promise yield put({ type: "DATA_LOADED", payload: result }); // DISPATCH an action const currentFilter = yield select((state) => state.filter); // READ current store state const nextAction = yield take("USER_LOGGED_OUT"); // PAUSE until a specific action is dispatched}
call(fn, ...args), describes calling fn with the given arguments; if fn returns a Promise, the saga pauses until it resolves (or throws, propagating as an error the saga can try/catch).
put(action), describes dispatching action to the store; the actual store.dispatch(action) call happens inside the middleware, not inside the generator.
select(selectorFn), describes reading the current state via a selector (per Selectors & Reselect); resumes immediately with the selector's result.
Why plain descriptions matter: real functions never run during a .next() step#
Confirmed directly in the earlier snippet: calling gen.next() on a saga that yields call(fakeApi, 42) returns the effect description as step1.value, inspecting it shows fakeApi referenced as data (payload.fn), not executed. This is the exact mechanism that makes sagas independently testable (covered fully in Testing Sagas): a test can assert "this saga yields a call-fakeApi-with-42 description" by comparing plain objects, with zero real network calls, zero mocking of fetch or timers, and zero running store required.
function* mySaga() { const a = yield call(add, 1, 2); yield put({ type: "RESULT", payload: a });}const gen = mySaga();const step1 = gen.next();console.log(typeof step1.value); // is this a number, or something else?
Given add isn't even defined anywhere in this snippet, does calling gen.next() throw a ReferenceError?
Solution
"object", no error is thrown.
This directly demonstrates the confirmed effect-description behavior: yield call(add, 1, 2) never actually tries to invoke add at this point, it just builds and returns a plain object describing "call whatever add refers to, with arguments 1 and 2." Since add is only ever referenced as data inside that object (not called), the fact that it's undefined never matters until something later actually tries to execute it, and nothing in this snippet does. This is a genuinely useful property: a saga can be constructed, stepped through, and its yielded descriptions inspected, entirely independent of whether the referenced functions are real, mocked, or even defined at all.
Build a drastically simplified version of what a saga middleware does, running a generator and interpreting call/put effect objects, to see the mechanism directly:
function call(fn, ...args) { return { type: "CALL", fn, args }; // just a plain object, no invocation}function put(action) { return { type: "PUT", action }; // just a plain object, no dispatch}async function runSaga(generatorFn, dispatch) { const gen = generatorFn(); let input; while (true) { const { value: effect, done } = gen.next(input);
This makes the core mechanism concrete: call()/put() are just plain object factories, all the real work (actually calling functions, actually dispatching) happens inside runSaga's loop, which is exactly the role the real saga middleware plays, just far more robustly (handling every effect type, cancellation, errors, and more).
This builds directly on Middleware's established pattern of middleware being given access to dispatch and able to fire further actions, redux-saga is, at its core, one large middleware that knows how to run generator functions and interpret their yielded effects. It composes with Selectors & Reselect via select(), and connects to Store's single-dispatch-funnel model, since every put() effect ultimately becomes a real store.dispatch() call.
1. Calling the function directly instead of yielding call()#
function* badSaga(action) { const user = await api.getUser(action.payload); // โ direct call, bypasses the effect system entirely yield put({ type: "USER_LOADED", payload: user });}
Bypassing call() in favor of directly await-ing (note: await inside a plain generator function isn't even valid without also being async function*, an unusual combination) removes the entire benefit of the effect-description pattern, the saga is no longer testable without actually invoking the real function, and loses the middleware's ability to intercept, cancel, or otherwise manage that specific operation.
2. Dispatching directly instead of yielding put()#
function* badSaga(action, store) { // โ passing the store into a saga isn't the pattern at all const user = yield call(api.getUser, action.payload); store.dispatch({ type: "USER_LOADED", payload: user }); // โ bypasses put()}
Sagas never receive the store directly, dispatching happens exclusively through put(), kept as a describable, interceptable effect rather than a direct side effect buried inside the generator.
3. Forgetting that call()'s first argument can be a method needing its object context#
yield call(api.getUser, id); // โ if getUser uses `this` internally, it loses its `api` context when called this way
call(fn, ...args) invokes fn(...args) with no bound context by default, for a method that relies on this, use call([api, api.getUser], id) or call(api.getUser.bind(api), id) to preserve the correct context.
Always use call() and put() for anything with a side effect (function calls, dispatches) inside a saga, rather than doing it directly, this keeps every side effect as an inspectable, testable description.
Prefer select() over reaching for state through closure variables, passing state through the generator's own effect system keeps sagas consistent and testable the same way as their other effects.
Bind or array-wrap object methods passed to call() when they rely on their own this context.
Effect descriptions ({ type: "CALL", ... }) are lightweight plain objects, there's no meaningful overhead from using call/put/select/take over their direct equivalents; the cost of a saga is the actual async work it performs, identical to any other approach.
Generator-based execution does have a small amount of inherent overhead compared to plain async/await (context-switching per yield), negligible for typical app-level async flows, and irrelevant compared to real network latency.
take(actionType), describes pausing until an action of that specific type is dispatched anywhere in the app; resumes with that action object.
if (done) return;
if (effect.type === "CALL") {
input = await effect.fn(...effect.args); // THIS is where the real function actually runs
} else if (effect.type === "PUT") {
dispatch(effect.action); // THIS is where the real dispatch actually happens