<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Stuti Shah on Medium]]></title>
        <description><![CDATA[Stories by Stuti Shah on Medium]]></description>
        <link>https://medium.com/@stutishahofficial?source=rss-2151df630218------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Q1FEpNZHwm4qqhquJBOmnw.jpeg</url>
            <title>Stories by Stuti Shah on Medium</title>
            <link>https://medium.com/@stutishahofficial?source=rss-2151df630218------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 02:55:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@stutishahofficial/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Redux-Saga and the Quest for the Lost Side Effects]]></title>
            <link>https://medium.com/@stutishahofficial/redux-saga-and-the-quest-for-the-lost-side-effects-34a80f252baa?source=rss-2151df630218------2</link>
            <guid isPermaLink="false">https://medium.com/p/34a80f252baa</guid>
            <dc:creator><![CDATA[Stuti Shah]]></dc:creator>
            <pubDate>Fri, 28 Mar 2025 18:28:56 GMT</pubDate>
            <atom:updated>2025-03-28T18:28:56.356Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GPqO1CPRP1AymEOn7osqsg.jpeg" /></figure><p><em>you’re managing state in Redux, everything’s going great — until your API calls start piling up like cliffhangers in a bad soap opera. Actions are flying, data’s loading, and suddenly you’re knee-deep in callback hell, trying to debug why that one fetch didn’t fire.</em></p><p><em>Enter Redux-Saga, the middleware knight in shining armor that helps you tame the chaos of asynchronous tasks. It doesn’t just handle side effects — it orchestrates them, like a well-rehearsed drama. And yes, it involves actual “sagas.”</em></p><p><em>In this article, we’ll go on a mildly dramatic (but mostly educational) journey through Redux-Saga — exploring how it works, when to use it, and how it compares to other tools like Redux Toolkit. We’ll also break down its cast of characters: generator functions, effects, watcher sagas, and worker sagas.</em></p><p>🧙‍♂️ <strong>Why Redux-Saga? Because Managing Side Effects Shouldn’t Feel Like Summoning Demons</strong></p><p><em>Redux-Saga lets you write </em><strong><em>asynchronous logic like it’s synchronous</em></strong><em> — using JavaScript’s generator functions (yes, the </em><em>function* kind). With sagas, you can </em><strong><em>pause</em></strong><em>, </em><strong><em>resume</em></strong><em>, and </em><strong><em>control</em></strong><em> your flow of side effects like you’re directing a play. No tangled chains. Just clear, linear logic — even when you&#39;re dealing with retries, sequences, parallel calls, or cancellations.</em></p><p>🥊<strong> Redux-Saga vs Redux Toolkit Thunk: The Drama of Developer Choices</strong></p><p><em>Now you might be wondering: “But isn’t Redux Toolkit enough? Doesn’t it come with </em><em>createAsyncThunk and everything?” Yes, it does. And for many simple apps, </em><strong><em>Redux Toolkit</em></strong><em> (RTK) is the way to go. It reduces boilerplate, structures your code nicely, and lets you write async logic without too much ceremony.</em></p><p><em>But here’s the catch:<br>So if your app is basically “click → fetch → store data,” RTK is your friend.<br> But if your async logic looks like:</em></p><ul><li><em>Fetch A</em></li><li><em>Wait for B</em></li><li><em>Then fetch C and D in parallel</em></li><li><em>Retry E if it fails</em></li><li><em>Cancel all if user logs out</em></li></ul><p><em>…then </em><strong><em>Redux-Saga</em></strong><em> is the middleware you want. It gives you tools to model all of this cleanly — and </em><strong><em>without descending into callback chaos.</em></strong></p><p><em>Think of Redux Toolkit as a quick montage. Redux-Saga is the full cinematic universe so lets deep little deeper into this.</em></p><p>🌟 <strong>Generator Functions — The Lead Actor Who Knows When to Pause</strong></p><p><em>At the heart of Redux-Saga is the </em><strong><em>generator function</em></strong><em> — written with </em><em>function*. These are like regular JavaScript functions, but with one key difference: they </em><strong><em>can pause</em></strong><em> their execution using the </em><em>yield keyword.</em></p><p><em>Think of it like a suspenseful moment in a TV series — the scene fades to black with a “To Be Continued…” Every </em><em>yield is that cliffhanger. Redux-Saga uses these to pause and resume logic based on external events — like an action being dispatched or an API response returning. This gives you </em><strong><em>fine-grained control</em></strong><em> over your async workflow.</em></p><pre>function* mySaga() {<br>  yield doSomething(); // pause here<br>  yield doSomethingElse(); // and here<br>}</pre><p>🧙 <strong>Effects</strong> — The Magic Spells</p><p><em>Inside generator functions, instead of calling functions directly, you </em><em>yield </em><strong><em>effects</em></strong><em> — plain JavaScript objects that tell Redux-Saga what to do.</em></p><p><em>Think of effects like magical scrolls you hand off to the middleware. You’re not doing the action yourself — you’re describing </em><strong><em>what should happen</em></strong><em>, and the Saga engine makes it so.</em></p><p><em>Some of the most common effects:</em></p><ul><li><em>take(actionType) — Wait for a specific action, like a dramatic entrance.</em></li><li><em>call(fn, ...args) — Call a function (usually async) and wait for the result.</em></li><li><em>put(action) — Dispatch a Redux action, like throwing a plot twist.</em></li><li><em>all([...]) — Run multiple effects in parallel. Think &quot;multiple storylines unfolding.&quot;</em></li><li><em>fork(saga) — Start a new saga in the background. Like a spin-off series</em></li></ul><p>👀 <strong>Watcher Saga</strong> — The Ever-Alert Observer</p><p><em>The </em><strong><em>watcher saga</em></strong><em> is like that side character who’s always lurking in the background, ready to jump in when something happens. Its job? </em><strong><em>Wait for specific actions</em></strong><em> (using </em><em>take, </em><em>takeEvery, or </em><em>takeLatest) and trigger the corresponding worker saga.</em></p><pre>function* watchUserRequest() {<br>  yield takeEvery(&#39;USER_REQUESTED&#39;, fetchUserSaga);<br>}</pre><p>🛠️ <strong>Worker Saga</strong> — The Real Most Valued Player</p><p><em>When a watcher saga detects an action, it calls in the </em><strong><em>worker saga</em></strong><em> — the one that actually does the job. Worker sagas handle the async operations: API calls, state updates, and side effects.</em></p><p><em>They’re the action heroes of the saga world.</em></p><pre>function* fetchUserSaga(action) {<br>  const user = yield call(api.fetchUser, action.payload);<br>  yield put({ type: &#39;USER_RECEIVED&#39;, payload: user });<br>}</pre><p>🧪 <em>Quick Code Example (Putting it All Together)</em></p><pre>import { take, call, put } from &#39;redux-saga/effects&#39;;<br><br>function* mySaga() {<br>  yield take(&#39;MY_ACTION&#39;); // Wait for the action<br>  const result = yield call(someApiFunction); // Make API call<br>  yield put({ type: &#39;MY_ACTION_SUCCESS&#39;, payload: result }); // Dispatch result<br>}</pre><h4>🧑‍💻Curious to see the chaos in action?</h4><p>Check out my <a href="https://github.com/StutiShah01/Redux-Saga">GitHub</a> repo here — because nothing says fun like debugging side effects. 🖤</p><p>Liked this article? Smash that clap button👏</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34a80f252baa" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>