<?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>DEV Community: Simran Birla</title>
    <description>The latest articles on DEV Community by Simran Birla (@simranbirla).</description>
    <link>https://dev.to/simranbirla</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%2F514028%2F2335f9da-e9e0-4b61-8946-4f22e454b58c.png</url>
      <title>DEV Community: Simran Birla</title>
      <link>https://dev.to/simranbirla</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/simranbirla"/>
    <language>en</language>
    <item>
      <title>CRUD using Firebase In React </title>
      <dc:creator>Simran Birla</dc:creator>
      <pubDate>Mon, 07 Jun 2021 10:45:18 +0000</pubDate>
      <link>https://dev.to/simranbirla/crud-using-firebase-in-react-4imm</link>
      <guid>https://dev.to/simranbirla/crud-using-firebase-in-react-4imm</guid>
      <description>&lt;p&gt;This post will show you how to perform CRUD operations in react using a DaaS Firebase. You can perform a lot of functions once you know how to use firebase with React.&lt;/p&gt;

&lt;p&gt;While making projects in FrontEnd, I always had the questions where should I keep the data and make the project in a way that a lot of people can see the data shared by other people.So then I thought of using firebase with React, which made the project complex in functionality but not in developing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up Firebase:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Created a firebase account and create a web project in it.&lt;/li&gt;
&lt;li&gt;Install firebase tools: 
&lt;code&gt;npm install -g firebase-tools&lt;/code&gt;
&lt;code&gt;npm install firebase&lt;/code&gt; &lt;/li&gt;
&lt;li&gt;Copy your config data from firebase
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firebaseApp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;initializeApp&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;******************d4&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;authDomain&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;***********.firebaseapp.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;databaseURL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;*********.firebaseio.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;projectId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;*******************&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;storageBucket&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;************.appspot.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;messagingSenderId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;********************&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;appId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;*************:web:***********4&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;measurementId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;G-************&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;In your React app create a file firebase.js in src directory &lt;/li&gt;
&lt;li&gt;Add the below code .
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;firebase&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;firebase&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;firebaseApp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;initializeApp&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;AIzaSyBI_AQ3C2mXWKG1i-Amtzn97zfGVSDzWd4&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;authDomain&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;pin-clone-39acf.firebaseapp.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;databaseURL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://pin-clone-39acf.firebaseio.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;projectId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;pin-clone-39acf&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;storageBucket&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;pin-clone-39acf.appspot.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;messagingSenderId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;884413487053&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;appId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1:884413487053:web:5a72dde51157b87b2ed684&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;measurementId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;G-VVCRZNMW6B&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;firestore&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;auth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;provider&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GoogleAuthProvider&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;storage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;storage&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;storage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;provider&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It will initialize firebase with your configuration.&lt;br&gt;
&lt;strong&gt;firestore()&lt;/strong&gt;: Then we create the firestore() which is the database we will use &lt;br&gt;
&lt;strong&gt;auth()&lt;/strong&gt;: is used to initialize the authorization in firebase&lt;br&gt;
&lt;strong&gt;provider()&lt;/strong&gt;: This is used to initialize the google authorization in the project, you can also use facebook, twitter authorization.&lt;br&gt;
&lt;em&gt;You have to enable authorization through firebase console&lt;/em&gt;&lt;br&gt;
&lt;strong&gt;storage()&lt;/strong&gt;: Used to store information from your project to firebase databse&lt;/p&gt;
&lt;h2&gt;
  
  
  Authorization:
&lt;/h2&gt;
&lt;h3&gt;
  
  
  For sign in :
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;signInWithPopup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;provider&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SIGN IN&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;})&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;
  
  
  For sign out:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;signOut&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
       &lt;span class="p"&gt;})&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Create:
&lt;/h2&gt;
&lt;h3&gt;
  
  
  Storage
&lt;/h3&gt;

&lt;p&gt;So I used the storage for uploading an image and then acquiring the image link.We can do this with any file type.&lt;/p&gt;

&lt;p&gt;You have to create a storage using firebase console &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to storage &lt;/li&gt;
&lt;li&gt;Create a new folder &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fza6enamclb9uznjbrfu0.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fza6enamclb9uznjbrfu0.JPG" alt="firebase storage"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;upload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;storage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`/&amp;lt;name of folder&amp;gt;/&amp;lt;name of file&amp;gt;`&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above code then adds the file into firebase storage&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To get the download URL&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="nx"&gt;upload&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;state_changed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;snap&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;progress&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;snap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bytesTransferred&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;snap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;totalBytes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
      &lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;storage&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;folder&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;child&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getDownloadURL&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the state is changed ("state change")( whether the file has been uploaded successfully or not), The on() functions takes 2 functions.&lt;br&gt;
The first tells us about the file uploading stage and the second one is used when file is uploaded.&lt;br&gt;
If you want to see how much percent of upload is completed  ,&lt;code&gt;progress&lt;/code&gt; variable tells us that.&lt;/p&gt;

&lt;p&gt;Once uploaded the second callback function, takes the storage variable defined in firebase file, maps down the path to get the url of the file &lt;/p&gt;
&lt;h3&gt;
  
  
  Database:
&lt;/h3&gt;

&lt;p&gt;This is done when you want to add a document in firebase collection.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;storage&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;../firebase&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;firebase&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;firebase&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;feed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;time&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;firestore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;FieldValue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;serverTimestamp&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
    &lt;span class="na"&gt;userName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;helloworld&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
   &lt;span class="p"&gt;});&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;You must remember to have the correct path in collection().&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When you want to add a field in document then you can use the set method but remember you have to implement your whole document structure as it will overwrite everything.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Here you should know the id of the document.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;feed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;heelo&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;username&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;byeworld&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;google.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Update:
&lt;/h2&gt;

&lt;p&gt;When you want to change a field without overwriting the entire structure you use update()&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;feed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will update the value of name and every other field will remain the same.&lt;/p&gt;

&lt;h2&gt;
  
  
  Read:
&lt;/h2&gt;

&lt;p&gt;To read data, you could use &lt;br&gt;
1.get()&lt;br&gt;
2.snapshot()&lt;/p&gt;

&lt;p&gt;1.get():&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;feed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;info&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;info&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exists&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Document data:&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;info&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;data&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// info.data() will be undefined in this case&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;No such document!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2.snapshot():&lt;br&gt;
The difference between snapshot() and get() is that, get() gives the data once whereas snapshot gets the data as soon as new data is added so it is recommended that you use snapshot() with useEffect()&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`boards/&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;auth&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;uid&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;/photos`&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;onSnapshot&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;snap&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
       &lt;span class="nf"&gt;setBoard&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="nx"&gt;snap&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;docs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
          &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;photos&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;data&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
         &lt;span class="p"&gt;}))&lt;/span&gt;
      &lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Delete:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`feeds`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;doc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Deleted!!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="p"&gt;})&lt;/span&gt;
   &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;alert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;err&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see by using firebase as a database for your frontend project can help manage data and give your project an edge as you can implement functionalities such as authentication with ease.&lt;/p&gt;

</description>
      <category>react</category>
      <category>codenewbie</category>
      <category>javascript</category>
      <category>firebase</category>
    </item>
    <item>
      <title>React Rendering and Re-rendering </title>
      <dc:creator>Simran Birla</dc:creator>
      <pubDate>Fri, 11 Dec 2020 05:01:02 +0000</pubDate>
      <link>https://dev.to/simranbirla/react-rendering-and-re-rendering-1l3m</link>
      <guid>https://dev.to/simranbirla/react-rendering-and-re-rendering-1l3m</guid>
      <description>&lt;p&gt;Render technically means to provide service. &lt;br&gt;
While using react, we all have heard the word rendering thousands of times. What exactly does react render?&lt;/p&gt;

&lt;p&gt;React renders the HTML elements on the screen. It creates the DOM object.&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;How does rendering happen?&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;While writing a simple code in React we use the method render(),&lt;br&gt;
consider the example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react";
import ReactDOM from "react-dom";

const App =()=&amp;gt;{
   return &amp;lt;div&amp;gt;
        Hello World!   
       &amp;lt;/div&amp;gt;
}

ReactDOM.render(&amp;lt;App/&amp;gt;,document.querySelector("#root");


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2tIxxGef--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y57k9p5vg9bzw6qgo67d.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2tIxxGef--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y57k9p5vg9bzw6qgo67d.JPG" alt="Initial render"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, the App component will be rendered inside the element with the id root. In react, we write JSX elements which are to be displayed on the screen as HTML elements. Once the JSX elements are written we need to display them on screen, this is done using the render() function of the ReactDOM.&lt;/p&gt;

&lt;h5&gt;
  
  
  The render function requires two parameters :
&lt;/h5&gt;

&lt;ol&gt;
&lt;li&gt;What is to be displayed 
2.Where is to be displayed.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react";
import ReactDOM from "react-dom";

ReactDOM.render("Hello World!",document.querySelector("#root");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;It displays the same results as the above.&lt;/em&gt;&lt;br&gt;
Here, Hello world is to be displayed and it is displayed inside the element with the id root.&lt;/p&gt;

&lt;p&gt;The elements in the react component are mounted on DOM in 2 steps: &lt;strong&gt;rendering&lt;/strong&gt; and &lt;strong&gt;commit&lt;/strong&gt;.&lt;br&gt;
In the rendering phase, the components written in React goes in hierarchical order and form a tree, in which the JSX elements are converted into React/javascript elements.&lt;br&gt;
Once this is created a virtual DOM is formed. Then the commit phase initiates and the virtual DOM is created into the actual DOM. This is the initial rendering.&lt;/p&gt;
&lt;h3&gt;
  
  
  What happens when re-rendering?
&lt;/h3&gt;

&lt;p&gt;Re-rendering happens when you change an element in React.&lt;br&gt;
That means if you use setState on an element, the element changes. When the element changes then that part of the element is marked in the virtual DOM (&lt;em&gt;note the real DOM does not change but rather the changes are done on virtual DOM that is the reason react is fast&lt;/em&gt;) then react creates an element for all the marked elements and changes are made in virtual DOM. Once the virtual DOM is changed then, react compares the DOM with the previous state of DOM, if there is a change then in the commit phase actual DOM is updated. &lt;br&gt;
&lt;em&gt;If the element remains the same, DOM is not updated.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--d_yHKKcA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ers0l6q9jpjvempkoo5c.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--d_yHKKcA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ers0l6q9jpjvempkoo5c.JPG" alt="Re-rendering"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Why too many re-renders happen?
&lt;/h3&gt;

&lt;p&gt;I made too many mistakes of too many re-renders when I just started using react. These were the few mistakes I made:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const [data,setData]=useState();&lt;/code&gt;&lt;br&gt;
1.When you use a setData in JSX elements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return &amp;lt;div&amp;gt;
&amp;lt;p&amp;gt;Hello world&amp;lt;p&amp;gt;
{setData(data+1)}
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The component will render, see there is setData and then set the data and again render and this will happen which will eventually give an error.&lt;/p&gt;

&lt;p&gt;2.When you use setData inside an useEffect function with data as your dependency. This is wrong, this happens because useEffect will run when you have changed data and you are changing data every time you use setData.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;useEffect(() =&amp;gt; {
       setData(data+1);
      return () =&amp;gt; {
      setData();
    }
  }, [data])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is how react renders its JSX elements. Thus it is said that "the commit phase usually very fast but rendering can be slow."&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Git merges and conflicts</title>
      <dc:creator>Simran Birla</dc:creator>
      <pubDate>Thu, 10 Dec 2020 18:13:48 +0000</pubDate>
      <link>https://dev.to/simranbirla/git-merges-and-conflicts-3m70</link>
      <guid>https://dev.to/simranbirla/git-merges-and-conflicts-3m70</guid>
      <description>&lt;p&gt;Git is a very important tool for developers all around to world . Git can do much more than just creating a repository for storing your code , like :&lt;/p&gt;

&lt;h4&gt;
  
  
  1.git branches :
&lt;/h4&gt;

&lt;p&gt;a)When you want to add a new feature to a project you create a branch. Once you create a branch the master / main branch of the repo is cloned.&lt;/p&gt;

&lt;p&gt;b)Git branch is used for adding or testing a new feature without breaking your main app.&lt;/p&gt;

&lt;p&gt;c)Git branch  for creating the branch &lt;br&gt;
Eg : &lt;code&gt;git branch branch1&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;d)Git checkout  entering the branch &lt;br&gt;
Eg: &lt;code&gt;git checkout branch1&lt;/code&gt;&lt;br&gt;
You are then switched to branch1 from main/master branch in your local machine.&lt;/p&gt;

&lt;p&gt;e)When you create a branch on your local machine and then try to commit and push its changes there will be an error saying that the branch has no upstream&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git push
fatal: The current branch test2 has no upstream branch.
To push the current branch and set the remote as upstream,
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;f)You resolve this by adding the command &lt;br&gt;
&lt;code&gt;git --set-upstream origin branch1&lt;/code&gt;(branch name)&lt;/p&gt;

&lt;p&gt;g)This will then take the branch that is in your local machine and add it in your github repo (that is it will create the remote branch).&lt;/p&gt;
&lt;h4&gt;
  
  
  2.Fork :
&lt;/h4&gt;

&lt;p&gt;This is used when making changes to somebody else’s repo you have no ownership on.&lt;br&gt;
Steps to fork:  You open the repo which you wish to fork &lt;br&gt;
You can see a button in the rightmost corner with the word fork on it .Click on it and then that repo will be forked.&lt;br&gt;
Once forked , a cloned repo will be created in your profile.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UFi3QV2H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7gfy84rapjop2arsi6rc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UFi3QV2H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7gfy84rapjop2arsi6rc.png" alt="Fork Button"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;While working in a forked repo ,my advice is to create a branch and make changes in it and then merge into the master/main branch in your cloned repo.This will help you detect If there are any merge conflicts.You can then remove the merge conflicts and create a Pull requests.&lt;/em&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  3.Pull requests :
&lt;/h4&gt;

&lt;p&gt;You create Pull request once you have done making changes and now you want to add them into the main branch.&lt;/p&gt;

&lt;p&gt;When you have done changes in your forked repo you can then create a pull request from the pull request tab.When created it will give you the option of the base repo(where you want to add the changes) and head repo (where you made those changes.).It also gives you the option to select the branch of both the base and head repo. &lt;/p&gt;

&lt;p&gt;Once a pull request has been created , it shows if there are any merge conflicts or not.If there are no merge conflicts then you can easily merge your changes into the project. But when you have merge conflicts you have to remove them and then only the changes can be merged.&lt;br&gt;
&lt;em&gt;You can also add a reviewer to review the changes you made.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;While creating a pull request in someone else’s repo they have to approve your Pull request.&lt;/em&gt;&lt;/p&gt;
&lt;h4&gt;
  
  
  4.Conflicts :
&lt;/h4&gt;

&lt;p&gt;While making a pull request you will encounter merge conflicts.If there are merge conflicts then the pull request will be accepted abut the branch cannot be merged into the main branch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git merge test2
Auto-merging Example
CONFLICT (content): Merge conflict in Example
Automatic merge failed; fix conflicts and then commit the result.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Reasons for conflicts:&lt;/strong&gt;&lt;br&gt;
1.When one file is edited in one PR but deleted in another.&lt;br&gt;
2.When the same line in the file has been edited in 2 different branches&lt;/p&gt;

&lt;p&gt;Once you know the reason for conflict you can solve it directly from git or using command line.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Git status&lt;/em&gt; : It will tell you that there are the merge conflicts in the branch and also will tell you in which file there are merge conflicts.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ git status
On branch main
Your branch is ahead of 'origin/main' by 1 commit.
  (use "git push" to publish your local commits)

You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add &amp;lt;file&amp;gt;..." to mark resolution)
        both modified:   Example
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Cat &lt;/em&gt;  : this will give you the contents of file where you have the merge conflicts.&lt;br&gt;
You will see something like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;HEAD
//* some lines
====
//* some lines
&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;branch name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This line ==== is conflict divider.&lt;br&gt;
The statements between HEAD and ==== is already present in your branch where you are making changes&lt;br&gt;
And The statements between ===== and branch name are the ones that you want to add.&lt;br&gt;
So , here is your conflict , You can solve this conflict by either accepting the lines already there or by adding the new changes or adding both&lt;/p&gt;

&lt;p&gt;To solve this, &lt;br&gt;
Open code editor if your choice ,&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ou0dR30U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/sls91zo52no821huhvqn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ou0dR30U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/sls91zo52no821huhvqn.png" alt="conflicts on VScode"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I have used VS code here , you can see it shows the conflict block,It also provides you with the option of accepting current changes, Accepting incoming change , accept both the changes and compare changes.&lt;br&gt;
Once you choose the options , git add . and then git commit -m “merged resolved”.&lt;br&gt;
This can then resolve all the merge conflicts.&lt;/p&gt;

&lt;p&gt;You can solve merge conflicts directly from github too. While creating a pull request it will show that there are merge conflicts.Once pull request is created you can resolve conflicts. Github opens an editor you can then manually edit what you want to keep. Once done the marked resolved button will be active and then you can merge the branch.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--R7yhx3qs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0m1zr324ionghjc6ysri.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--R7yhx3qs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0m1zr324ionghjc6ysri.png" alt="Github Merge resolve"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Axios.js vs fetch() API </title>
      <dc:creator>Simran Birla</dc:creator>
      <pubDate>Thu, 10 Dec 2020 07:19:25 +0000</pubDate>
      <link>https://dev.to/simranbirla/axios-js-vs-fetch-api-1pib</link>
      <guid>https://dev.to/simranbirla/axios-js-vs-fetch-api-1pib</guid>
      <description>&lt;p&gt;While building projects in JS we all need to make http request for exchanging data between two end points.Most of the projects I have build in JS I have used fetch() for handling my API requests.While going through a course on reactjs on udemy I saw the use of axios. Like every beginner who has only used fetch() for handling API request my question why was axios so special.It was also mentioned that axios is used in most of industry standards for performing http request but not fetch.&lt;/p&gt;

&lt;h4&gt;
  
  
  So to give an overview of what axios and fetch are:
&lt;/h4&gt;

&lt;h3&gt;
  
  
  Fetch():
&lt;/h3&gt;

&lt;p&gt;It is an built-in method which is used for making HTTP requests.It is an upgrade from ajax method which is used in jquery.It provided a better approach for making HTTP requests in javascript.In other words it is used to “fetch” the response of a http request.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fb9ffz82p9bpj4zltct6e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fb9ffz82p9bpj4zltct6e.png" alt="Fetch syntax"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;This is an example of get method in fetch()&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Axios:
&lt;/h3&gt;

&lt;p&gt;Axios is a library which is used for making HTTP requests for node.js and XMLHTTP requests from browser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fmg1x7egj28tmza6o0i45.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fmg1x7egj28tmza6o0i45.png" alt="axios syntax"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffpl3g74jhn9fzfe0t4bj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffpl3g74jhn9fzfe0t4bj.png" alt="axios get"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;This is the syntax for axios get method.Here , I have created axios using create function with a base url in another file. Then it is imported and .get() is used for fetching data&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When reading the definitions you will know that both fetch and axios does the same thing.So which one is &lt;strong&gt;better and why&lt;/strong&gt; should be your question?&lt;/p&gt;

&lt;h2&gt;
  
  
  FETCH VS AXIOS
&lt;/h2&gt;

&lt;p&gt;Fetch was a upgrade over ajax method in jquery.When I just started to use axios ,I thought it is doing the same thing what fetch was doing but with a different syntax.But when learning further , I understood in what way fetch and axios are different.&lt;/p&gt;

&lt;h3&gt;
  
  
  Let’s compare fetch and axios with the following points:
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Received Response &lt;/li&gt;
&lt;li&gt;Error handling &lt;/li&gt;
&lt;li&gt;Timeout handling &lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  1. Received Response:
&lt;/h4&gt;

&lt;p&gt;This difference is the easiest to understand . When you make a fetch request you have to use 2 then() or 2 awaits .But when using axios you just have to do that once.&lt;/p&gt;

&lt;p&gt;The first .then() in &lt;strong&gt;fetch&lt;/strong&gt; is used for receiving the information which has the response headers.When fetch() is used a promise is generated ,to resolve the promise we use .then(). Once we have the response we have to make the body of response received readable which is done using the json() method. This also returns a promise so we use .then() , to resolve that promise.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;axios&lt;/strong&gt; , the response received is already in string format because axios takes care of it. It handles low level work in turn reducing our work.Thus , it returns one promise where the body of the response is readable by us.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fnrr9jwmrcb9m6knca05p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fnrr9jwmrcb9m6knca05p.png" alt="fetch response"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;final response of fetch's get method&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fi50l2fz7f4s5tp477m7m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fi50l2fz7f4s5tp477m7m.png" alt="Axios response"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Response of axios's get method&lt;/em&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  2.Error handling:
&lt;/h4&gt;

&lt;p&gt;If we receive an error while accessing data through fetch() , the requests gets processed unlike ajax and shows error.In axios the request gets process and it is caught in the catch() block as an error.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fkw63ucr190qrtiqw3zl3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fkw63ucr190qrtiqw3zl3.png" alt="Error fetch"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here , we see the request gets processed even if it has status of 404 , fetch treats the request received as a good response rather than a error and thus it does not enter the catch block.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Faowrrgblewfgv8t457re.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Faowrrgblewfgv8t457re.png" alt="Code Axios"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F30o44w5fko5898da2klh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F30o44w5fko5898da2klh.png" alt="Axios error"&gt;&lt;/a&gt;&lt;br&gt;
&lt;code&gt;Error Error:Request Failed with an error code of 404&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Whereas , while using axios if there is an error or the status code falls in 4xx or 5xx category it is treated as an error.&lt;/p&gt;

&lt;h4&gt;
  
  
  3.Timeouts :
&lt;/h4&gt;

&lt;p&gt;When you want to manually set a timeout in requests it is very easy to do so with help of axios , you simply add it in the headers section.But in fetch() there is whole lot of process to go through.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvdvjra1u5b72dhji71dv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fvdvjra1u5b72dhji71dv.png" alt="Axios timeout code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fisdlzu9mmqojtkwqxk1i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fisdlzu9mmqojtkwqxk1i.png" alt="Fetch Timeout code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see you simply have to add timeout in the headers body of axios. You can add timeout in fetch as well with the help of abortController(), it requires a lot more syntax and is not as simple as axios.&lt;/p&gt;

&lt;p&gt;Not only these , axios has a slight edge over fetch in performing  many different actions. If you want to see how much upload or download is done in your application axios has a built in onDownloadProgress method.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxbpkmyinkxzcx51wbikj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxbpkmyinkxzcx51wbikj.png" alt="Download Progress"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Sample code for showing onDownloadProgress&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3ulh2y883lc7se30qmip.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F3ulh2y883lc7se30qmip.png" alt="response of download progress"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;response of onDownloadProgress&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The onDownloadProgress then returns a ProgressEvent object. With the help of size of the object and loaded object in the ProgressEvent object we could calculate how much percent of file is left to complete.&lt;br&gt;
Axios can also cancel request and can add interceptors in the request for login , authentication purposes.&lt;/p&gt;

&lt;p&gt;Thus , if you want to make a small scale app where data will be fetched and displayed you don’t need to install axios library you could just use fetch(), but when you want to do a lot more with HTTP requests it is better to use axios then fetch().&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>api</category>
    </item>
  </channel>
</rss>
