<?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 Pavel on Medium]]></title>
        <description><![CDATA[Stories by Pavel on Medium]]></description>
        <link>https://medium.com/@pavelkinev?source=rss-8e3d8aeecb14------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*_riSkXbc8euan0fe.</url>
            <title>Stories by Pavel on Medium</title>
            <link>https://medium.com/@pavelkinev?source=rss-8e3d8aeecb14------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 16:10:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pavelkinev/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[Request and cache data in React like a pro]]></title>
            <link>https://medium.com/@pavelkinev/request-and-cache-data-in-react-like-a-pro-8ddcb86c1ca3?source=rss-8e3d8aeecb14------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ddcb86c1ca3</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[cache]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[react-native]]></category>
            <dc:creator><![CDATA[Pavel]]></dc:creator>
            <pubDate>Mon, 07 Feb 2022 11:59:32 GMT</pubDate>
            <atom:updated>2022-02-07T11:59:32.902Z</atom:updated>
            <content:encoded><![CDATA[<p>Coming from redux, redux-sagas for handling data requests and storing the results in the store it was quite unusual how simple data management can be.</p><p>Let’s talk about <a href="https://react-query.tanstack.com/">react-query</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xQl1vVYFOFb7ud7n4cTgRQ.jpeg" /></figure><blockquote>Fetch, cache and update data in your React and React Native applications all without touching any “global state”.</blockquote><p>This is straight from their docs and it’s true. Here is the simplest example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ddc347e3fba23a6166232b380d4f4f03/href">https://medium.com/media/ddc347e3fba23a6166232b380d4f4f03/href</a></iframe><p>I intentionally avoided all the setup to focus on the functionality for now as it is described in <a href="https://react-query.tanstack.com/installation">detail in the docs</a>. Simple, right?</p><p>When you use this line for the first line in the code it makes a usual request and stores the data in the cache. Then if calling it in a different component (with the same key) it instantly gets you the data from the cache while requesting new data in the background and updating when ready.</p><blockquote>Stale while revalidate — show cached data while a new one is being loaded.</blockquote><p>So the key to performant caching here is a key which can be a string or an array of different identifiers.</p><p>Let’s check a couple more examples:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cb93e12389e720fe8e3c4d5247896a82/href">https://medium.com/media/cb93e12389e720fe8e3c4d5247896a82/href</a></iframe><p>You can use any combination of params for the key and as long as you use the same in other components you will have instant results in your app.</p><p>The library is very powerful and isn’t limited to such simple cases only:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a64d9e355a3b0297fd6d7629ff712c9b/href">https://medium.com/media/a64d9e355a3b0297fd6d7629ff712c9b/href</a></iframe><p>Now you can build your component in a linear fashion:<br>- if isLoading return a spinner or skeleton<br>- if isError show error component with text from error <br>- otherwise, render your main component with the given data.</p><p>What about POST, PATCH, and other non-GET requests? There is useMutation for the help. It has a similar API but is designed to be triggered with an event.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d3c52c1d27aa0cc51e1b35dc633d0fa5/href">https://medium.com/media/d3c52c1d27aa0cc51e1b35dc633d0fa5/href</a></iframe><p>Mutations also have quite a <a href="https://react-query.tanstack.com/reference/useMutation">rich API</a>, mostly similar to queries though.</p><p>And here is a more complex example of useMutation which also updates changed information locally.</p><p>Imagine you have a list of items that were cached with useQuery , now you want to edit one of them and update this cache to reflect new changes without calling an API again (unless you need some more data from the server of course).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/263d1f1e77e22809df829e4d8c15c7b9/href">https://medium.com/media/263d1f1e77e22809df829e4d8c15c7b9/href</a></iframe><p>Okay, I guess the basics were covered here. So I’ll stop here.</p><p>_______<br>This is my first article, so any feedback technical or language-wise is appreciated.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ddcb86c1ca3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>