<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Jad</title>
    <description>The latest articles on Forem by Jad (@a_m_h_gad).</description>
    <link>https://forem.com/a_m_h_gad</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F256642%2Faa963f71-288b-42ca-939d-31d2f14a20c6.jpg</url>
      <title>Forem: Jad</title>
      <link>https://forem.com/a_m_h_gad</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/a_m_h_gad"/>
    <language>en</language>
    <item>
      <title>Prisma ORM</title>
      <dc:creator>Jad</dc:creator>
      <pubDate>Fri, 15 Nov 2024 09:26:35 +0000</pubDate>
      <link>https://forem.com/a_m_h_gad/prisma-orm-32kd</link>
      <guid>https://forem.com/a_m_h_gad/prisma-orm-32kd</guid>
      <description></description>
      <category>prisma</category>
    </item>
    <item>
      <title>Migrate from `old way of fetching data` to react-query..</title>
      <dc:creator>Jad</dc:creator>
      <pubDate>Tue, 18 Oct 2022 12:25:45 +0000</pubDate>
      <link>https://forem.com/a_m_h_gad/migrate-from-old-way-of-fetching-data-to-react-query-k44</link>
      <guid>https://forem.com/a_m_h_gad/migrate-from-old-way-of-fetching-data-to-react-query-k44</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Fetching data is an essential part of any product developers make nowadays, as &lt;strong&gt;React developers&lt;/strong&gt; we've been doing so much to fetch some data from a server and we spend more time to keep this data synced with the one on the server.&lt;/p&gt;

&lt;p&gt;But now as things are getting faster and faster the community had to think of a faster and more opinionated way to handle fetching data for us &lt;code&gt;developers&lt;/code&gt;. one of the best tools is &lt;a href="https://react-query-v3.tanstack.com/"&gt;&lt;em&gt;react-query&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is react-query?
&lt;/h2&gt;

&lt;p&gt;per &lt;a href="https://react-query-v3.tanstack.com/overview"&gt;the docs&lt;/a&gt; react-query is &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;often described as the missing data-fetching library for React, but in more technical terms, it makes fetching, caching, synchronizing and updating server state in your React applications a breeze.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  shall we stop talking and start writing some code!.
&lt;/h2&gt;

&lt;p&gt;Before &lt;code&gt;react-query&lt;/code&gt; we used to write all this code to fetch a piece of data from a server, keeping a state (loading,failed, succeed) of each stage of fetching these data &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tUuAoHKI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f1ili8vcf8cm0uscwr95.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tUuAoHKI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f1ili8vcf8cm0uscwr95.png" alt="old way to fetch data without react-query" width="880" height="567"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;to compare between &lt;code&gt;old way&lt;/code&gt; and &lt;code&gt;react-query&lt;/code&gt;, and how it makes this simpler than before, take a look at the code below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ulJYWUIo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bxv9ekdnsmd9ctriu3d7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ulJYWUIo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bxv9ekdnsmd9ctriu3d7.png" alt="fetch code with react-query" width="880" height="327"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;How beautiful/simple is this, isn't much cleaner and readable.&lt;br&gt;
react-query simplifies and does everything on it's side and just returns the data/state that we are interested in.&lt;/p&gt;

&lt;p&gt;we just pass the url we need the data from and boom we have it, no more &lt;code&gt;useEffect()&lt;/code&gt;, &lt;code&gt;setState()&lt;/code&gt; or &lt;code&gt;async function inside useEffect()&lt;/code&gt;, and we can also track the fetching state if it still loading or failed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Important thing to notice..
&lt;/h2&gt;

&lt;p&gt;using &lt;code&gt;useEffect()&lt;/code&gt; to fetch data is somehow considered a bad practice, as per &lt;a href="https://reactjs.org/docs/hooks-effect.html"&gt;official docs&lt;/a&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;By using useEffect() hook, you tell React that your component needs to do something after render.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;which will take more time as react always seeks to finish rendering first then calls functions inside useEffect,&lt;br&gt;
But &lt;em&gt;react-query&lt;/em&gt; useQuery() solves this issues by start fetching data in parallel with rendering, which of course time saver.&lt;/p&gt;

&lt;h2&gt;
  
  
  Last but not least
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;react-query&lt;/code&gt; does more more than just fetching data from a server,it has other methods to make our life easier, as mutate, prefetching data, invalidate cached data and of course &lt;strong&gt;caching&lt;/strong&gt;, it even have it's built-in devTool I just wrote this article as an introduction for react-query.&lt;br&gt;
You can have more information about it's capabilities by reading &lt;a href="https://react-query-v3.tanstack.com/overview"&gt;the docs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I hope this gave you an overlook of this awesome tool. Feel free to leave a comment with suggestions, questions, or if you think some changes have to be done in the article.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
  </channel>
</rss>
