<?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 Krzysztof Ciombor on Medium]]></title>
        <description><![CDATA[Stories by Krzysztof Ciombor on Medium]]></description>
        <link>https://medium.com/@krzysztof.ciombor?source=rss-d5d7134eae3d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*bi-bBrClzc-vjShvKvt84A.jpeg</url>
            <title>Stories by Krzysztof Ciombor on Medium</title>
            <link>https://medium.com/@krzysztof.ciombor?source=rss-d5d7134eae3d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 22:20:52 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@krzysztof.ciombor/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[Escaping Redux pitfalls in React Native world]]></title>
            <link>https://medium.com/swmansion/escaping-redux-pitfalls-in-react-native-world-e151c008c97a?source=rss-d5d7134eae3d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e151c008c97a</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[redux]]></category>
            <dc:creator><![CDATA[Krzysztof Ciombor]]></dc:creator>
            <pubDate>Wed, 26 Sep 2018 13:39:39 GMT</pubDate>
            <atom:updated>2019-02-13T07:12:44.209Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BFxw1dvwEUHyNsmDIVzCBQ.png" /></figure><p>React is getting more and more popular these days and the big debate around the best way to handle state seems to be never-ending. The de-facto standard solution now is to use <a href="https://redux.js.org/">Redux</a> as a state container. However, just throwing in a Redux store hoping it would automagically solve all of the state management problems is very wishful thinking.</p><p>From our experience at <a href="https://swmansion.com/">Software Mansion</a> when working on React Native app audits for our clients, incorrect Redux usage is the most common reason for performance issues.</p><p>Unlike on web, in React Native apps React components stay mounted on the navigation stack when we push in new screens. Since they are kept mounted, they are also connected to the Redux store and receive updates when the global state changes, even if they are not visible and buried down in the navigation stack. The more screens we have on the stack, the more expensive state updates become — hence we want to make the updates as efficient as possible.</p><p>For our example purposes, let’s imagine a very simple e-commerce application with the usual stuff: a product list, a product details screen, search, cart view and a checkout flow.</p><h3>1. Treat Redux as a “database”</h3><p>This is by far the most common source of issues we’ve seen in Redux applications. Denormalized state, lots of unnecessary variables, inefficient data structures, all of this makes managing the state more difficult and may lead to performance problems, especially in React Native apps.</p><p>Imagine Redux being a server-side PostgreSQL instance. You wouldn’t want to store, for example, loading state there, would you?</p><p>Ideally, the Redux store for our products would look something like:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/21c716112ef176e02bad42087a6bf292/href">https://medium.com/media/21c716112ef176e02bad42087a6bf292/href</a></iframe><p>That is:</p><ul><li>Normalized — there’s no data redundancy</li><li>Contains only necessary data — there are no additional flags or properties</li><li>Uses appropriate structures — accessing product by id can be done in O(1) instead of O(n) if an array of products was to be stored</li></ul><p><strong>Example<br>Scenario</strong>: Selecting a product from product list should open that product’s details screen.<br><strong>Wrong solution</strong>: When the user clicks on a list item, we store the selected product identifier in Redux store. Then the details page retrieves the ID of the product it is supposed to display directly from the store.<br><strong>Issues</strong>: Deep linking is more challenging to achieve. Must remember to clear the currentProductId when closing product details screen.<br><strong>Solution</strong>: Clicking on a product item passes productId as a prop to details screen which is used to retrieve the appropriate product object from the Redux store.</p><h3>2. Do not store local state in Redux</h3><p>Having Redux integrated in your app does not mean you shouldn’t use <a href="https://reactjs.org/docs/react-component.html#setstate">setState</a> ever again. On the contrary, <a href="https://reactjs.org/docs/react-component.html#setstate">setState</a> is very useful for decoupling local component state from global Redux state. If you’re unsure whether a particular variable should live inside local or global state, start with component’s state. If you find yourself in a situation where this variable should be accessed by more components, first think about lifting the state up.</p><p><strong>Example<br>Scenario</strong>: Entering search phrase on Search screen updates search input component.<br><strong>Wrong solution</strong>: Search phrase is kept in Redux store and updated on every key press.<br><strong>Issues</strong>: Possibility of lots of unnecessary re-renders when the Redux state changes.<br><strong>Solution</strong>: Search phrase is kept in local component’s state and is updated on every key press re-rendering this component only.</p><h3>3. Use selector libraries</h3><p>Almost every connected component need a mapStateToProps function. To help Redux perform global state updates in an efficient way we need to make sure the same objects are returned if the part of the state our component is interested in hasn’t changed. Selector libraries like <a href="https://github.com/reduxjs/reselect">reselect</a> help with making mapStateToProps function keep this contract.</p><p>Even if the selectors themselves do not include heavy computations and simply select part of the store, it is still beneficial to create a selector. It makes the business logic separation cleaner and more maintainable.</p><p><strong>Example<br>Scenario</strong>: Retrieving products list.<br><strong>Sub-optimal solution</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c42776a9ebcf92c42aa9d040feb7fbe0/href">https://medium.com/media/c42776a9ebcf92c42aa9d040feb7fbe0/href</a></iframe><p><strong>Solution</strong>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/38b4fb6fcd303598ffc8246ea24e5f73/href">https://medium.com/media/38b4fb6fcd303598ffc8246ea24e5f73/href</a></iframe><p>There’s one more gotcha here though. Reselect is not enough when our selector logic need to be parameterized. That is when the output depends on additional parameters which are not a part of the store. For example, selecting a single product by its id passed as a component property. One way of dealing with that is to use the <a href="https://github.com/toomuchdesign/re-reselect">re-reselect</a> library:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1efd6f9c536cd0143eaeadf83a515075/href">https://medium.com/media/1efd6f9c536cd0143eaeadf83a515075/href</a></iframe><h3>4. Be careful when connecting components</h3><p>Connecting the component too high in the view hierarchy may cause an unnecessary updates cascade when something changes in the store. Instead, components that need to access Redux data should be connected by themselves.</p><p><strong>Example<br>Scenario</strong>: Displaying products list.<br><strong>Wrong solution</strong>: The main ListView container is connected to Redux and renders the list by passing product prop to each item.<br><strong>Issues</strong>: Editing single list item (for example, marking it as favorite) causes the list container to re-render and thus, all of the children components to re-render as well.<br><strong>Solution</strong>: Each list item component receives productId as its prop and is connected to Redux by itself.</p><h3>5. Persistence is tricky</h3><p>One very common use-case for Redux is to have the state automatically persisted between app runs, for example using the <a href="https://github.com/rt2zz/redux-persist">redux-persist</a> library. Some things that are worth keeping in mind when persisting Redux store:</p><ul><li>Do not keep non-serializable items inside the store (like functions or Promises). Otherwise, they will not work correctly when persisting the state.</li><li>Remember to clear the state when appropriate. For example, if the user logs out, we may need to clear all stored data to avoid leaks when another user logs in.</li><li>Configure persistence policy. Use throttle if many state modifications are executed in quick succession to avoid a performance bottleneck. Use whitelist to control which parts of the store will be persisted. Use transform for additional transformations when persisting/rehydrating the state.</li></ul><p>To sum up, when deciding on store management solution, it is good to take time to learn and consider different options instead of blindly following others. You can use Redux, but use it responsibly. Following our guidelines requires discipline, but will likely save your app from becoming utterly slow as your codebase grows.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e151c008c97a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swmansion/escaping-redux-pitfalls-in-react-native-world-e151c008c97a">Escaping Redux pitfalls in React Native world</a> was originally published in <a href="https://medium.com/swmansion">Software Mansion</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>