<?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 Sam Aryasa on Medium]]></title>
        <description><![CDATA[Stories by Sam Aryasa on Medium]]></description>
        <link>https://medium.com/@samaryasa?source=rss-507721916b1b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*JJl22CDGOhWHeJoAPTwV1w.jpeg</url>
            <title>Stories by Sam Aryasa on Medium</title>
            <link>https://medium.com/@samaryasa?source=rss-507721916b1b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 01:50:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@samaryasa/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[React/Redux Tips: Better Way to Handle Loading Flags in Your Reducers]]></title>
            <link>https://medium.com/stashaway-engineering/react-redux-tips-better-way-to-handle-loading-flags-in-your-reducers-afda42a804c6?source=rss-507721916b1b------2</link>
            <guid isPermaLink="false">https://medium.com/p/afda42a804c6</guid>
            <category><![CDATA[website-development]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Sam Aryasa]]></dc:creator>
            <pubDate>Thu, 08 Mar 2018 09:26:15 GMT</pubDate>
            <atom:updated>2018-03-08T11:13:41.195Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>TLDR; Use a separate reducer to store all isFetching flags instead of polluting all of your reducers.</strong></p><p>So like everyone, you are using <a href="https://reactjs.org/">React</a> for frontend, <a href="https://redux.js.org/">Redux</a> for state management, and given that your app is complex enough, then it’s very likely for you to have run into this piece of code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c77aee4cd219434305e4da36d0eadcb/href">https://medium.com/media/8c77aee4cd219434305e4da36d0eadcb/href</a></iframe><p>This code would work fine until your app requires a lot more API calls — then half of your reducer code would be code to handle isFetching/errorMessage ☹️</p><h3>Enter loading reducer</h3><p>In StashAway, we solved this by creating a loading reducer that <strong>stores all API request states</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/362ee888c09db1482e0ae250a1a04d44/href">https://medium.com/media/362ee888c09db1482e0ae250a1a04d44/href</a></iframe><p>Then we can access those loading states using a selector in our component:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f47b8b4496ad4ec57ae04ffeac86832/href">https://medium.com/media/9f47b8b4496ad4ec57ae04ffeac86832/href</a></iframe><p>Since we don’t need to maintain any isFetching flags, now our reducers will only need to care about storing data:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/083ba36a22452e834d37c3dd08c53db1/href">https://medium.com/media/083ba36a22452e834d37c3dd08c53db1/href</a></iframe><p>Ok maybe not that much simpler in this test code, but when your app requires you to make requests to more than 20+ APIs, it will make your life a tiny bit easier 😏</p><h3>Can we combine API calls?</h3><p>When building a real-world™ app, we might need to combine API calls (e.g. Only display todos page when both getUser and getTodos requests succeed). This is trivial with this approach:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a71d4b58840bb6b2053a0184cca05b0/href">https://medium.com/media/2a71d4b58840bb6b2053a0184cca05b0/href</a></iframe><h3>How about error messages?</h3><p>Handling API error messages is similar to handling loading flags, except when selecting which message to display:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a9fb20c5cb6e0d1fa89fa42423c52fc7/href">https://medium.com/media/a9fb20c5cb6e0d1fa89fa42423c52fc7/href</a></iframe><p>Just as with many things in programming, there are many ways of doing things in React/Redux. This is simply our preferred way of doing it at StashAway.</p><p>We are always trying to find ways to improve at StashAway! Feel free to tell us what do you think in the comments!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=afda42a804c6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/stashaway-engineering/react-redux-tips-better-way-to-handle-loading-flags-in-your-reducers-afda42a804c6">React/Redux Tips: Better Way to Handle Loading Flags in Your Reducers</a> was originally published in <a href="https://medium.com/stashaway-engineering">StashAway Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>