<?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: Prajwal Jain</title>
    <description>The latest articles on DEV Community by Prajwal Jain (@j836).</description>
    <link>https://dev.to/j836</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%2F462275%2Fc624e3cf-7005-4cab-87ab-845f70d0a8e4.png</url>
      <title>DEV Community: Prajwal Jain</title>
      <link>https://dev.to/j836</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/j836"/>
    <language>en</language>
    <item>
      <title>Behind the Scenes of React.</title>
      <dc:creator>Prajwal Jain</dc:creator>
      <pubDate>Wed, 26 May 2021 05:56:07 +0000</pubDate>
      <link>https://dev.to/j836/behind-the-scenes-of-react-f01</link>
      <guid>https://dev.to/j836/behind-the-scenes-of-react-f01</guid>
      <description>&lt;h1&gt;
  
  
  Behind the Scenes of React
&lt;/h1&gt;

&lt;p&gt;Aren't you guys curious🤔 about what does React do behind the scenes and how it does so many things for us..?&lt;/p&gt;

&lt;p&gt;Well, this blog comes out of my curiosity of how the developers at facebook came to create this wonderful thing which caused a revolution in the World of Web.&lt;/p&gt;

&lt;p&gt;Do you know that react has its own DOM! Ya, you got it! same as that of browser has!&lt;/p&gt;

&lt;p&gt;Okay. You may think that's great! But why would someone need an Extra DOM?&lt;br&gt;
Eventually, whatever changes are going to occur are on the browser's DOM, right?&lt;/p&gt;

&lt;p&gt;Well, that's true.. But but but...there are some crucial points we need to understand.&lt;/p&gt;

&lt;p&gt;Whenever a component's state changes, code is re rendered by DOM, and browser has to repaint each and every element on the screen. This involves a lot of mathematical and other calculations.&lt;br&gt;
And thinking at scale, our app would have multiple state changes.&lt;br&gt;
So our browser is doing unnecessary cycling of complete DOM whereas only a single elements' state has changed. Thus, More the items to repaint slower the app.&lt;/p&gt;

&lt;p&gt;And that's the reason why, React has Virtual DOM.&lt;br&gt;
It helps in minimizing the actual changes on browser DOM. How?&lt;/p&gt;

&lt;p&gt;Lets see.&lt;/p&gt;

&lt;p&gt;Initally, virtual DOM will be an exact copy of real DOM.&lt;/p&gt;

&lt;p&gt;In React, whenever a components' state changes, the changes are reflected in Virtual DOM.&lt;br&gt;
Thus, Virtual DOM has the updated state of the component.&lt;/p&gt;

&lt;p&gt;Now it checks&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;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;VirtualDOM&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;Browsers&lt;/span&gt; &lt;span class="nx"&gt;DOM&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;just&lt;/span&gt; &lt;span class="nx"&gt;chill&lt;/span&gt; &lt;span class="nx"&gt;man&lt;/span&gt;&lt;span class="o"&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="nx"&gt;update&lt;/span&gt; &lt;span class="nx"&gt;the&lt;/span&gt; &lt;span class="nx"&gt;browsers&lt;/span&gt; &lt;span class="nx"&gt;DOM&lt;/span&gt; &lt;span class="nx"&gt;only&lt;/span&gt; &lt;span class="nx"&gt;where&lt;/span&gt; &lt;span class="nx"&gt;that&lt;/span&gt; &lt;span class="nx"&gt;component&lt;/span&gt; &lt;span class="nx"&gt;has&lt;/span&gt; &lt;span class="nx"&gt;changed&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 is a high level overview of what diffing algorithm does.&lt;/p&gt;

&lt;p&gt;Thus, browsers' work has highly reduced and now it will help us loading our app faster!&lt;/p&gt;

&lt;p&gt;The process through which React updates the DOM is known as Reconciliation.&lt;br&gt;
This reconciliation has 2 phases :&lt;br&gt;
Render Phase&lt;br&gt;
Commit Phase&lt;/p&gt;
&lt;h2&gt;
  
  
  Render Phase
&lt;/h2&gt;

&lt;p&gt;The Render phase takes your JSX and turns it into a javascript representation. This is nothing but the VirtualDOM.&lt;/p&gt;
&lt;h2&gt;
  
  
  Commit Phase
&lt;/h2&gt;

&lt;p&gt;The commit phase is actually taking that representation and applying it to the real DOM.&lt;br&gt;
The commit phase is where React actually touches the DOM and makes changes.&lt;/p&gt;

&lt;p&gt;An Important Point:&lt;br&gt;
React does not commit state changes one after the other if there are multiple state changes.&lt;br&gt;
Instead,&lt;br&gt;
React goes through its virtual DOM ,creates a list of those changes that need to be made to the actual DOM and then does it all in one single process.&lt;br&gt;
In fancy words, React does batch updates.&lt;/p&gt;

&lt;p&gt;So putting all pieces together,&lt;br&gt;
Reconciliation = Render + Diffing occurs in between + Commit.&lt;/p&gt;

&lt;p&gt;If there is no change in the state then commit is not done although render has occured.&lt;/p&gt;

&lt;p&gt;Now that you have understood reconciliation lets understand how diffing works and different factors that affect diffing.&lt;/p&gt;

&lt;p&gt;React works on heuristic search. In simple terms, a heuristic search is a technique which has some previous knowledge about the search.&lt;br&gt;
So the assumptions(knowledge) that the React has is:&lt;/p&gt;

&lt;p&gt;Two elements of different types will produce different trees.&lt;br&gt;
For a stable re-render key props are required on child elements.(Refer Docs)&lt;/p&gt;

&lt;p&gt;Whenever the root elements have different types,&lt;br&gt;
for eg. initially it was&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hello React&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and then we change it to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;Hello React&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;React will destroy the old tree and build the new tree from scratch. All the children will also get destroyed.&lt;br&gt;
Destroying old tree =&amp;gt; all the state associated with it is gone.&lt;/p&gt;
&lt;h2&gt;
  
  
  DOM Elements Of The Same Type
&lt;/h2&gt;

&lt;p&gt;When comparing two React DOM elements of the same type, react only updates the changed attributes.&lt;br&gt;
Same goes when updating style.&lt;br&gt;
For eg:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&lt;/span&gt; &lt;span class="na"&gt;className=&lt;/span&gt;&lt;span class="s"&gt;"hero"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Hello React&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is changed to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&lt;/span&gt; &lt;span class="na"&gt;className=&lt;/span&gt;&lt;span class="s"&gt;"header"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Hello React&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When only the attributes are changed, DOM nodes are not recreated =&amp;gt; state is maintained =&amp;gt;component is already on the page =&amp;gt; DOM does not need to repaint the DOM styles on the view. This is what makes React super fast!&lt;/p&gt;

&lt;h2&gt;
  
  
  Component Elements Of The Same Type
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Now we are on COMPONENTS of same type. Earlier it was DOM elements of same type.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Instead of reiterating what docs has written, read react docs. It has been beautifully explained there along with simple examples.&lt;/p&gt;

&lt;p&gt;That's it from this blog!&lt;br&gt;
If you found this post useful do react to this post, which inspires me to write more. If you have any comments or corrections that could improve this post, I would be glad to receive them. Thank you for your time 👋🏼 💙.&lt;/p&gt;

</description>
      <category>react</category>
      <category>reconciliation</category>
      <category>javascript</category>
    </item>
    <item>
      <title>why use useState?</title>
      <dc:creator>Prajwal Jain</dc:creator>
      <pubDate>Tue, 25 May 2021 12:40:59 +0000</pubDate>
      <link>https://dev.to/j836/why-use-usestate-1cd9</link>
      <guid>https://dev.to/j836/why-use-usestate-1cd9</guid>
      <description>&lt;h1&gt;
  
  
  useState
&lt;/h1&gt;

&lt;p&gt;useState is a react API to change the state of elements or components.&lt;br&gt;
Why do we require a seperate hook to change a value of an element?&lt;br&gt;&lt;br&gt;
Well,Its always a bad practise to mutate the state directly.&lt;br&gt;&lt;br&gt;
Let me explain things along with the code itself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&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;useState&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;react&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./styles.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&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;setUser&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;user&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"App"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;sample program to show declarative programming&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;hr&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;
        &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;prajwal&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="nx"&gt;setUser&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="c1"&gt;// if you dont use setState line no 19 does not run =&amp;gt; function is not called =&amp;gt; rerendering does not occur.&lt;/span&gt;
          &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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;from onclick&lt;/span&gt;&lt;span class="dl"&gt;"&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="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        Click Me&lt;span class="si"&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="si"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&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="si"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;welcome &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;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;What does this code aim to do?&lt;br&gt;&lt;br&gt;
We want to display user's name instead of just user as a text when button is clicked.&lt;br&gt;&lt;br&gt;
A bad dev like me would probably do something as &lt;/p&gt;
&lt;p&gt;(which is wrong)&lt;/p&gt;
&lt;br&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./styles.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;user&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"App"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;sample program to show declarative programming&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;hr&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;
        &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;prajwal&lt;/span&gt;&lt;span class="dl"&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="nx"&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;from onclick&lt;/span&gt;&lt;span class="dl"&gt;"&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="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        Click Me&lt;span class="si"&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="si"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;this is from user&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;welcome &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;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;blockquote&gt;
&lt;p&gt;&lt;em&gt;Note: I am purposely showing the wrong approach.Sometimes looking at what is wrong helps us understanding what is correct!!&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;



&lt;p&gt;Here goes the sandbox link for the right approach.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/bqw1u"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;If you see the console.log within onClick you could see that the value of user has been updated.But Wait!Why isnt it reflecting in the view?&lt;/p&gt;

&lt;p&gt;Its because..&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;if there is no setState =&amp;gt;(implies) React does not see any state changed =&amp;gt; re-rendering of function does not occur =&amp;gt; view would no be updated.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;if you dont use setState, &lt;code&gt;{console.log(user, "this is from user")}&lt;/code&gt; does not run =&amp;gt; function is not called =&amp;gt; rerendering does not occur.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;everytime setState() is invoked,a re-render is triggered.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Conclusion:&lt;br&gt; &lt;b&gt;only when the state is changed through setState the re-rendering of function occurs.&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Thank you for reading till the end. If you notice something wrong do suggest me in the comment box.&lt;br&gt;
Do give it a like if it helped you understanding the concept.&lt;/p&gt;

</description>
      <category>usestate</category>
      <category>react</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Declarative in terms of React.</title>
      <dc:creator>Prajwal Jain</dc:creator>
      <pubDate>Tue, 25 May 2021 12:16:31 +0000</pubDate>
      <link>https://dev.to/j836/declarative-in-terms-of-react-2g1c</link>
      <guid>https://dev.to/j836/declarative-in-terms-of-react-2g1c</guid>
      <description>&lt;h1&gt;
  
  
  what is declarative in terms of react?
&lt;/h1&gt;

&lt;p&gt;if you are new to react then you might have heard about react being declarative.&lt;br&gt;
What exacly does that mean?Lets have a look.&lt;/p&gt;

&lt;p&gt;Say we have a button with us and initially a normal text of welcome user.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What we want to do?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We want to display user's name instead of just user as a text when button is clicked.&lt;/p&gt;

&lt;p&gt;Lets have a look at the following code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;sample for showing that react is declarative&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;hr&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"btn-click"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Click me&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h2&amp;gt;&lt;/span&gt;welcome &lt;span class="nt"&gt;&amp;lt;span&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"user"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;user&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is what we do in vanilla javascript.&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="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#btn-click&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;click&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#user&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;prajwal&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;So we need to tell the browser each and every step which are as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;hey browser, give me the button which lies on the document whose id is ....(btn-click) in our case.&lt;/li&gt;
&lt;li&gt;Do something (step 3) when user clicks on that button.&lt;/li&gt;
&lt;li&gt;when user clicks on that button,give me that element which lies on the document and whose id is ....(user in our case)&lt;/li&gt;
&lt;li&gt;set the text as ....(prajwal in our case) on it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Some crucial points to be noted:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;we are dealing with the browser's DOM to perform our actions.This,is what we dont do in React.We never interact with DOM in React.
So after the birth of react this procedure seems more like a donkey work.&lt;/li&gt;
&lt;li&gt;We are telling browser each and every instruction and then it does something for us.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Here is the codepen link if you wish to try your hands on&lt;br&gt;
&lt;iframe height="600" src="https://codepen.io/prajwal_/embed/NWpbvBV?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;br&gt;
React has came out with a smarter approach and thats nothing but declarative!&lt;/p&gt;

&lt;p&gt;Lets see the react code..&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&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;useState&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;react&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./styles.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&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;setUser&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;user&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"App"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;sample program to show declarative programming&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;hr&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;
        &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&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;user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;prajwal&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
          &lt;span class="nx"&gt;setUser&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="c1"&gt;// if you dont use setState line no 19 does not run =&amp;gt; function is not called =&amp;gt; rerendering does not occur.&lt;/span&gt;
          &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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;from onclick&lt;/span&gt;&lt;span class="dl"&gt;"&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="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        Click Me&lt;span class="si"&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="si"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&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="si"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;welcome &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;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;Here is the code for you to play with.&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://codesandbox.io/embed/bqw1u"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Again if you dont know about useState you can read &lt;a href="https://dev.to/j836/why-use-usestate-1cd9"&gt;this&lt;/a&gt; blog.I have tried to explain things in a simpler way with the same example so that it is relatable.I do suggest you to check out &lt;a href="https://dev.to/j836/why-use-usestate-1cd9"&gt;this&lt;/a&gt; blog.&lt;/p&gt;

&lt;p&gt;In this react code,you see we only tell the react..&lt;br&gt; Hey React,I want to display something... on this element when some one clicks on the button.&lt;br&gt;
Neither we do document.querySelector nor we do .innerText..i.e. We dont deal direclty with browser's DOM.But still the work is done.How?Well,React does all of that for us.&lt;/p&gt;

&lt;p&gt;you see,We dont give set of long instructions.&lt;br&gt;
We only tell react what to do..how does react do that is react's look out.&lt;br&gt;&lt;br&gt;
Its more like saying&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR &lt;br&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;"suun react,tuze ye element pe ye text dikhana hai..kuch bhi kar kaise bhi kar bass kaam ho jaana chaiye..!"&lt;br&gt;&lt;/em&gt;&lt;br&gt;
Thats declarative!&lt;/p&gt;

&lt;p&gt;Thank you for reading till the end. If you notice something wrong do suggest me in the comment box.&lt;br&gt;
Do give it a like if it helped you understanding the concept.&lt;/p&gt;

</description>
      <category>react</category>
      <category>declarative</category>
      <category>imperative</category>
      <category>javascript</category>
    </item>
    <item>
      <title> Font Size:em,rem,pixel or percent?</title>
      <dc:creator>Prajwal Jain</dc:creator>
      <pubDate>Thu, 31 Dec 2020 16:04:04 +0000</pubDate>
      <link>https://dev.to/j836/font-size-em-rem-pixel-or-percent-3f3p</link>
      <guid>https://dev.to/j836/font-size-em-rem-pixel-or-percent-3f3p</guid>
      <description>&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%2Fwww.digitalauthority.me%2Fwp-content%2Fuploads%2F2019%2F03%2Fshutterstock_301849946.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%2Fwww.digitalauthority.me%2Fwp-content%2Fuploads%2F2019%2F03%2Fshutterstock_301849946.jpg" title="Font Size" alt="Font Size"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I still remember when I was creating my first portfolio site and was trying to make it responsive,even after creating many media queries I wasnt able to get the desired reponsiveness.I was totally frustrated.&lt;/p&gt;

&lt;p&gt;And then I came to know it was because I had used font sizes in pixels.&lt;/p&gt;

&lt;p&gt;So, my dear friends,I dont want you to waste your valuable time on such simple things like I did!&lt;br&gt;
So do read till the end.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pixels&lt;/code&gt; (&lt;code&gt;px&lt;/code&gt;) do not scale.&lt;br&gt;
It is an &lt;code&gt;absolute&lt;/code&gt; unit.&lt;/p&gt;

&lt;p&gt;Whereas &lt;code&gt;em&lt;/code&gt; , &lt;code&gt;rem&lt;/code&gt; are &lt;code&gt;relative/responsive&lt;/code&gt; units.&lt;br&gt;
They scale according to the viewport.&lt;/p&gt;

&lt;p&gt;Change in the value of &lt;code&gt;parent&lt;/code&gt; or &lt;code&gt;root&lt;/code&gt; element affects the value of relative units.&lt;br&gt;
&lt;code&gt;em&lt;/code&gt; should be used for padding,margin,line-height etc.&lt;/p&gt;

&lt;p&gt;Okay so before studying em and rem,&lt;br&gt;
Remember &lt;code&gt;default font size of browser is 16px&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Thus  &lt;code&gt;1rem = 16px by default.&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  USING EM - ELEMENT
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;For eg.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;

&lt;th&gt;Style&lt;/th&gt;

&lt;th&gt;Computed style&lt;/th&gt;

&lt;tr&gt;

&lt;td&gt;
html {
    font-size:18px;
}

section {
    font-size:14px;
    padding:3em;
}
&lt;/td&gt;
&lt;td&gt;
html {
    font-size:18px;
}

section {
    font-size:14px;
    padding:42px;
}
&lt;/td&gt;
&lt;/tr&gt; 
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;So independent of font size specified in html element em takes the font size of its local element.&lt;br&gt;
And if font size is not defined in its local element then it checks it parent's element.&lt;br&gt;
This is a part of inheritance in em units.&lt;br&gt;
We shall learn more about inheritance later in this blog.&lt;/p&gt;
&lt;h2&gt;
  
  
  USING REM - ROOT ELEMENT
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;For eg.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;

&lt;th&gt;Style&lt;/th&gt;

&lt;th&gt;Computed style&lt;/th&gt;

&lt;tr&gt;

&lt;td&gt;
html {
    font-size:18px;
}

section {
    font-size:14px;
    padding:3rem;
}
&lt;/td&gt;
&lt;td&gt;
html {
    font-size:18px;
}

section {
    font-size:14px;
    padding:54px;
}
&lt;/td&gt;
&lt;/tr&gt; 
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Independent of font size defined in local element it takes the value in the root element i.e. html&lt;/p&gt;
&lt;h3&gt;
  
  
  EFFECT OF INHERITANCE ON EM UNITS
&lt;/h3&gt;

&lt;p&gt;Inheritance changes the game in em units and also makes it quite complex.&lt;/p&gt;

&lt;p&gt;With em the child element inherits the value of its parent and up to its grandparent.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;section&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"wrapper"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    Grandparent
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        Parent
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            Child
        &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/section&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;

&lt;th&gt;Style&lt;/th&gt;

&lt;th&gt;Computed style&lt;/th&gt;

&lt;tr&gt;

&lt;td&gt;
html {
    font-size:16px;
}

.wrapper {
    font-size:1.5em;
}

.container {
    padding:2em;
}
&lt;/td&gt;

&lt;td&gt;

html {
    font-size:16px;
}

.wrapper {
    font-size:24px;//16 * 1.5//
}

.container {
    padding:48px;//24 * 2 //  
}
&lt;/td&gt;
&lt;/tr&gt;  
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;If we want to override the inherited values then we need to expicitly set the unit element to &lt;code&gt;px&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Stylesheet
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;section&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"page-wrapper"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    GrandParent
    //16px
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        Parent
        //24 * 1.5 = 36px;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            Child
            //36 * 1.5 = 54px;
        &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/section&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;html&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nc"&gt;.page-wrapper&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="m"&gt;24px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="m"&gt;1.5em&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;Here the font size of div with &lt;code&gt;.container&lt;/code&gt; class is computed based on its parent element.&lt;br&gt;
The interesting thing here is that the parent and child in the HTML above do &lt;code&gt;not&lt;/code&gt; have the same font size irrespective  of the fact that they share the same class name.&lt;/p&gt;
&lt;h3&gt;
  
  
  PERCENT
&lt;/h3&gt;

&lt;p&gt;Use percent specifically when making site responsive.&lt;br&gt;
Also for ease of usage most programmers do the following.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;html&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="m"&gt;62.5%&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;Thus now &lt;code&gt;1rem = 10px;&lt;/code&gt;&lt;br&gt;&lt;br&gt;
This makes furhter calculations easier.  &lt;/p&gt;

&lt;h2&gt;
  
  
  CONCLUSION
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;These are just my personal recommendations based on my research and studies.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;em&lt;/code&gt; should be used for padding,margin,line-height etc.&lt;br&gt;
&lt;code&gt;em&lt;/code&gt; for those elements whose properties shall scale with the changing viewport.  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use &lt;code&gt;rem&lt;/code&gt; for everything else.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For changing viewports, use &lt;code&gt;%&lt;/code&gt; unit in font size.This makes font size responsive.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;Note:&lt;br&gt;
Guys, I have taken reference of this blog.&lt;br&gt;
&lt;a href="https://chiamakaikeanyi.dev/sizing-in-css-px-vs-em-vs-rem/#:~:text=When%20you%20use%20px%2C%20you,element%20in%20percentage%20is%20recommended." rel="noopener noreferrer"&gt;Sizing in CSS: px vs em vs rem&lt;/a&gt;&lt;br&gt;
This is really a very helpful blog!&lt;br&gt;
Do give it a read for more undertanding.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
    </item>
    <item>
      <title> git:a simple conceptual explanation for a beginner.
</title>
      <dc:creator>Prajwal Jain</dc:creator>
      <pubDate>Sun, 22 Nov 2020 16:48:05 +0000</pubDate>
      <link>https://dev.to/j836/git-a-simple-conceptual-explanation-for-a-beginner-3bfh</link>
      <guid>https://dev.to/j836/git-a-simple-conceptual-explanation-for-a-beginner-3bfh</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;small&gt;Note : This blog does not tell you in details about the commands you need to use.It just explains what they do.&lt;/small&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  An Overview
&lt;/h2&gt;

&lt;p&gt;What it basically does is saves different versions of your file.&lt;/p&gt;

&lt;p&gt;Like when you write a program,you change the file number of times.&lt;br&gt;
Git helps us to save(in better words 'track') those changes.Thats it.&lt;/p&gt;
&lt;h2&gt;
  
  
  Why we need Git
&lt;/h2&gt;

&lt;p&gt;Imagine you and your team is working on same file on a college project which is index.html&lt;/p&gt;



&lt;p&gt;So..You guys are all set to 'type' the already coded file that you have with you.&lt;br&gt;
You both log in with a common id but on different machines and start editing the same file simultaneosly.&lt;br&gt;
You would be like "Hey!From Where did this rascal piece of code is coming from..I never wrote it!!Let me delete this"&lt;br&gt;
And your friend be like "Why this shitty piece of code is getting deleted always..Coding is such a frustrating?Why did they even invent this???"&lt;/p&gt;

&lt;p&gt;And the Uparwala be watching and thinking "In naadan balkon ko git nai pata!!"&lt;/p&gt;

&lt;p&gt;Okay..Coming back!&lt;br&gt;
What do you think will happen?&lt;br&gt;
Yes!file is changed from both ends and gets corrupt.&lt;/p&gt;

&lt;p&gt;And this is only you and your friend!Imagine tech giants like flipkart where hundreds of developers are working together!How would they manage all these changes to the same file?&lt;/p&gt;

&lt;p&gt;&lt;b&gt;And thats where Git comes into picture!&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;Now lets see some terms and terminologies.&lt;/p&gt;
&lt;h2&gt;
  
  
  Terms and Terminologies
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;What is a repository?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Just a fancy name for folder.&lt;/p&gt;

&lt;p&gt;There are some commands you need to know if you are using the CLI version.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;There is something known as &lt;strong&gt;add&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is how the command is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add &amp;lt;file_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What this command does is adds all your changes to an intermediate agent.&lt;br&gt;
Yes they arent yet given in right hands.&lt;br&gt;
By running this command you only give that file which you have just changed to that middle man.&lt;br&gt;
That middle man in fancy terms is known as stagging area.&lt;br&gt;
Now how to move it safely into right hands and save changes.&lt;/p&gt;

&lt;p&gt;For that lets meet this guy.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;There is something known as &lt;b&gt;commit&lt;/b&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Remember I told you that git saves different versions of your file.&lt;br&gt;
How?Well &lt;em&gt;commit&lt;/em&gt; is the answer for that.&lt;br&gt;
For now , see &lt;em&gt;commit&lt;/em&gt; as &lt;em&gt;save changes&lt;/em&gt;.&lt;br&gt;
Replace &lt;em&gt;commit&lt;/em&gt; word with &lt;em&gt;save changes&lt;/em&gt;.&lt;br&gt;
You can also imagine it like a game checkpoint.&lt;br&gt;
You are on a mission in GTA and you know there are checkpoints..So if you are killed somehow,you would not need to start all the way from beginning.Your latest checkpoint is where you start from.&lt;/p&gt;

&lt;p&gt;The command runs like this:&lt;/p&gt;






&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git commit -m "Initial commit"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;-m stands for message.&lt;br&gt;
You change the file every now and then.&lt;br&gt;
You run and you see Oh! ';' is missing,&lt;br&gt;
Again you run Oh!I missed a brace!!&lt;br&gt;
Sometimes you add ,sometimes you delete.&lt;br&gt;
So only saving changes is useless until you get to know what changes have you made!&lt;br&gt;
And hence you have a message associated with every commit.&lt;br&gt;
Isnt that simple?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Every commit has an unique id associated with it.&lt;/p&gt;

&lt;p&gt;Push and Pull.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;First lets answer this.&lt;/p&gt;

&lt;p&gt;Where to push? To your Github Account&lt;/p&gt;

&lt;p&gt;From where to pull? From your Github Account.&lt;/p&gt;

&lt;p&gt;What to pull?Repositories&lt;/p&gt;

&lt;p&gt;What to push?Folder containing the files you are working on(index.html)&lt;/p&gt;

&lt;p&gt;Now man?What is this Github now?&lt;/p&gt;

&lt;p&gt;Imagine Github is Google Photos.&lt;/p&gt;



&lt;p&gt;Right now,the image/file  is in your phone(any local machine).&lt;/p&gt;

&lt;p&gt;You &lt;strong&gt;PUSH&lt;/strong&gt;(&lt;em&gt;Upload&lt;/em&gt;) it to &lt;strong&gt;GITHUB&lt;/strong&gt;(&lt;em&gt;google photos&lt;/em&gt;).&lt;br&gt;
And the command is:&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  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But you need to go through the &lt;a href="https://docs.github.com/en/free-pro-team@latest/github/getting-started-with-github"&gt;initial setup&lt;/a&gt; before running the command.&lt;/p&gt;

&lt;p&gt;And there are some files that you want to &lt;strong&gt;PULL&lt;/strong&gt;(&lt;em&gt;download&lt;/em&gt;) that you had earlier uploaded to your account and are not there in your local machine right now.&lt;/p&gt;

&lt;p&gt;So you &lt;strong&gt;PULL&lt;/strong&gt;(&lt;em&gt;download&lt;/em&gt;) the desired repo from your github account by&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git pull
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I think that its enough for this post.&lt;/p&gt;

&lt;p&gt;If you have read this till here..Do give it a like and tell me in comments if you really understood or not!&lt;br&gt;
Feel free to correct me if I have went wrong somewhere!&lt;br&gt;
Thank you for reading!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>git</category>
      <category>github</category>
    </item>
  </channel>
</rss>
