<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Frontend Development in React. Sharing my learnings, Tips, Tutorials and best practices]]></title><description><![CDATA[In-depth concepts about Frontend development in React, tips, best practices, and tutorials. Stay up-to-date with the latest trends and improve your skills today.]]></description><link>https://blog.yashodeep.dev</link><generator>RSS for Node</generator><lastBuildDate>Tue, 14 Apr 2026 01:22:59 GMT</lastBuildDate><atom:link href="https://blog.yashodeep.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Understanding State Variables and the useState Hook in React for Dynamic UIs]]></title><description><![CDATA[While learning React you might come across the terms such as state variables, useState hook and you had no idea about what state variables are in react and how it is used that you have landed on the right place.
State management is a crucial part of ...]]></description><link>https://blog.yashodeep.dev/understanding-state-variables-and-the-usestate-hook-in-react-for-dynamic-uis</link><guid isPermaLink="true">https://blog.yashodeep.dev/understanding-state-variables-and-the-usestate-hook-in-react-for-dynamic-uis</guid><category><![CDATA[hooks]]></category><category><![CDATA[React]]></category><category><![CDATA[State Management ]]></category><category><![CDATA[useState]]></category><category><![CDATA[Frontend Development]]></category><dc:creator><![CDATA[Yashodeep Nimbekar]]></dc:creator><pubDate>Tue, 25 Apr 2023 10:27:46 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1682418263607/83cb94e4-23bb-4e6f-a9f2-4af3ffb87bd7.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>While learning React you might come across the terms such as state variables, <code>useState</code> hook and you had no idea about what state variables are in react and how it is used that you have landed on the right place.</p>
<p>State management is a crucial part of building dynamic and interactive user interfaces. The state variables allow you to store and update data that can be displayed on the UI. React provides a mechanism to manage the state through the <code>useState</code> hook.</p>
<p>In this blog post, we will dive deeper into the <code>useState</code> hook, its advantages over local variables, and how it can be used to create dynamic UIs in React. We will also look at some examples of how to use the <code>useState</code> hook to manage the state in functional components. So, if you are new to React or looking to expand your knowledge on state management in React, keep reading!</p>
<ul>
<li><p>Local variables vs State Variables</p>
</li>
<li><p><code>useState</code> Hook</p>
</li>
</ul>
<hr />
<h2 id="heading-local-variables-vs-state-variables">Local variables vs State Variables</h2>
<p>If we have local variables in react then why do we need to use state variables?</p>
<p>I am sure you came across this doubt at some point in learning React, well now you will know the answer.</p>
<p>We use state variables in react because react has no idea what's happening to your local variables. So, react won't re-render any updates happening on that variable.</p>
<p>Every time we want our variable in sync with the UI, we use state variables because React keeps track of state variables.</p>
<p>Whenever that variable is updated, the whole component rerenders, i.e. React destroys the component and re-creates it again. This is called <a target="_blank" href="https://yashodeep.hashnode.dev/boosting-ui-performance-why-reacts-virtual-dom-and-jsx-make-it-a-top-choice-for-developers">Reconciliation and Diff Algorithm</a> in React which happens behind the scene.</p>
<p>hmm...now you might ask that we use state variables to keep track of the changes done to that variable but what if we want a constant variable that won't have to change or be updated in our code then what should we use?</p>
<p>In such cases as above when the value of the variable doesn't change you can use normal local variables.</p>
<hr />
<h2 id="heading-usestate-hook"><code>useState</code> Hook:</h2>
<p>We use <code>useState</code> hook in React to create state variables:</p>
<p>The useState hook is one of the most important and commonly used hooks in React. It allows you to add a state to functional components. This means you can now have functional components that can have dynamic behavior and respond to user interactions.</p>
<p><code>useState();</code> function returns an array and the first element of this array is the variable name and the second element is a set function to update the variable.</p>
<p>The hook is imported from the react vis named import.</p>
<p>Here's an example:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React, { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Counter</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> [count, setCount] = useState(<span class="hljs-number">0</span>);

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Count: {count}<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> setCount(count + 1)}&gt;Increment<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}
</code></pre>
<p>In this example, <code>useState</code> hook is imported in from the React library. The new state variable is count and the set function is setCount, which will be used to update the count variable. In the <code>useState</code> hook, we have passed the initial '0' for the count variable. But, it's not mandatory to pass the initial value, you can just keep the brackets empty if you don't want any initial value.</p>
<hr />
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this blog post, we have discussed the concept of state variables in React and the useState hook, which is used to manage state in functional components. We have also explored the difference between local variables and state variables and the advantages of using state variables over local variables. The blog also provides an example of how to use the <code>useState</code> hook to create a dynamic app in React. This blog post is perfect for beginners who are new to React and looking to understand how state management works in React.</p>
<p><a target="_blank" href="https://yashodeep.hashnode.dev/boosting-ui-performance-why-reacts-virtual-dom-and-jsx-make-it-a-top-choice-for-developers">click to learn more about diff algorithm, reconciliation, and why React is fast.</a></p>
<p>KEEP LEARNING AND BUILDING!!</p>
]]></content:encoded></item><item><title><![CDATA[Boosting UI Performance: Why React's Virtual DOM and JSX Make It a Top Choice for Developers]]></title><description><![CDATA[React is the most popular and trending JavaScript library among developers to build faster and more responsive User Interfaces. One of the major reasons the React library become so popular is because of its Speed and performance. In this blog post, w...]]></description><link>https://blog.yashodeep.dev/boosting-ui-performance-why-reacts-virtual-dom-and-jsx-make-it-a-top-choice-for-developers</link><guid isPermaLink="true">https://blog.yashodeep.dev/boosting-ui-performance-why-reacts-virtual-dom-and-jsx-make-it-a-top-choice-for-developers</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[React]]></category><category><![CDATA[JSX]]></category><category><![CDATA[reconcilliation]]></category><category><![CDATA[virtual dom]]></category><dc:creator><![CDATA[Yashodeep Nimbekar]]></dc:creator><pubDate>Thu, 20 Apr 2023 18:16:30 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1682014447701/12f934a3-54c6-476a-9217-9ab6f76ab0b1.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>React is the most popular and trending JavaScript library among developers to build faster and more responsive User Interfaces. One of the major reasons the React library become so popular is because of its Speed and performance. In this blog post, we will discuss the key reasons why React is fast including its use of virtual DOM and JSX. This post will provide valuable insights into why React is such a powerful tool for building lightning-fast user interfaces.</p>
<ul>
<li><p>Virtual DOM</p>
</li>
<li><p>Reconciliation and Diff algorithm</p>
</li>
<li><p>React Fiber</p>
</li>
<li><p>JSX</p>
</li>
<li><p>Server-side Rendering</p>
</li>
</ul>
<hr />
<h2 id="heading-virtual-dom">Virtual DOM</h2>
<p>Virtual Dom is not an actual DOM, it is the representation of the actual DOM. The earlier web development approaches required the entire HTML document to be updated each time some changes are done in UI. React keeps the virtual representation of the dom that allows it to only update the changed parts in UI. This approach is much faster and more efficient.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1682004887759/998d735d-6a65-494d-926e-48e46c40b534.jpeg" alt class="image--center mx-auto" /></p>
<hr />
<h2 id="heading-reconciliation-and-diff-algorithm">Reconciliation and Diff algorithm</h2>
<p>Reconciliation helps to make React applications fast and efficient by minimizing the amount of work that needs to be done to update the changes.</p>
<p>We need virtual DOM for Reconciliation. Reconciliation is an algorithm that React uses to differentiate one tree from another. To differentiate the tree it uses the 'Diff Algorithm' in which the current tree is compared with the new tree and the difference is reflected on the DOM, it determines what needs to be changed in the UI and what does not. After determining what needs to be updated the diff algorithm then updates only that small portion in UI without touching any other nodes.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1682005419146/d5efc90c-6720-402d-9cdf-b62498ad5c57.jpeg" alt class="image--center mx-auto" /></p>
<hr />
<h2 id="heading-react-fiber">React Fiber</h2>
<p>React Fiber uses a more flexible, asynchronous approach to update the UI. It breaks the rendering process into smaller, incremental units of work called "fiber". It also introduces the new priority-based system to prioritize certain updates over others. This increases the efficiency of React.</p>
<hr />
<h2 id="heading-jsx">JSX</h2>
<p>JSX is HTML-like code within their JavaScript code, it is not HTML inside JavaScript. This simplifies the development process and speeds up the coding process by eliminating the need for manual DOM manipulation.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">JSX</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> name = <span class="hljs-string">"It's not HTML. It's JSX"</span>;
  <span class="hljs-keyword">const</span> message = <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Hello, {name}!<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>;

  <span class="hljs-keyword">return</span> JSX;
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> JSX;
</code></pre>
<hr />
<h2 id="heading-server-side-rendering">Server-side Rendering</h2>
<p>React's server-side rendering capabilities enable it to render the initial UI on the server and then send it to the client, resulting in faster load times and improved SEO performance.</p>
<hr />
<h2 id="heading-conclusion">Conclusion</h2>
<p>This blog post discusses the reasons why React is a popular tool for building fast and efficient user interfaces. It highlights React's use of virtual DOM, reconciliation, and the diff algorithm, as well as the introduction of React Fiber to improve efficiency. Additionally, it explains JSX and its benefits, such as simplifying the development process. Finally, the post notes how React's server-side rendering capabilities can improve load times and SEO performance.</p>
]]></content:encoded></item><item><title><![CDATA[Using React Fragments for Cleaner Code]]></title><description><![CDATA[In React, when we render multiple JSX elements in a component, we basically wrap them inside a parent element. However, this approach creates unnecessary DOM nodes. To address this issue React library exports React fragments. It allows us to group to...]]></description><link>https://blog.yashodeep.dev/using-react-fragments-for-cleaner-code</link><guid isPermaLink="true">https://blog.yashodeep.dev/using-react-fragments-for-cleaner-code</guid><category><![CDATA[React]]></category><category><![CDATA[ReactComponent]]></category><category><![CDATA[fragment]]></category><category><![CDATA[clean code]]></category><dc:creator><![CDATA[Yashodeep Nimbekar]]></dc:creator><pubDate>Tue, 18 Apr 2023 18:26:22 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/UYsBCu9RP3Y/upload/528e56950a4be67f79bdbfe6fa198b80.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In React, when we render multiple JSX elements in a component, we basically wrap them inside a parent element. However, this approach creates unnecessary DOM nodes. To address this issue React library exports React fragments. It allows us to group together multiple JSX elements without adding an extra ugly div to the DOM. This makes our code cleaner and more efficient.</p>
<p>In this blog, we will learn :</p>
<ul>
<li><p>What React fragments are and how they work</p>
</li>
<li><p>The syntax for using React fragments in our components</p>
</li>
<li><p>How we can nest React fragments to group multiple elements together</p>
</li>
<li><p>The DOM representation of React fragments and how they differ from regular DOM nodes</p>
</li>
<li><p>The limitations of using React fragments, including browser compatibility and potential performance issues</p>
</li>
</ul>
<hr />
<p>React Fragment is a component that is exported by 'react'. It group a list of children without adding an extra node to DOM.</p>
<h3 id="heading-syntax">Syntax:</h3>
<p><em>&lt;React.fragment&gt;... &lt;/React.fragment&gt;</em></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> AppLayout = <span class="hljs-function">() =&gt;</span>{
   <span class="hljs-keyword">return</span>(
      <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">React.fragment</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Header</span> /&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Body</span>/&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Footer</span>/&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">React.fragment</span>&gt;</span></span>
   );
};
</code></pre>
<p>React. fragments are treated as empty tags. So instead of writing a long ass name just write:- <strong>"&lt;&gt;...&lt;/&gt;", this is the shortened syntax of react fragment.</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> AppLayout = <span class="hljs-function">() =&gt;</span>{
   <span class="hljs-keyword">return</span>(
      <span class="xml"><span class="hljs-tag">&lt;&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Header</span> /&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Body</span>/&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Footer</span>/&gt;</span>
      <span class="hljs-tag">&lt;/&gt;</span></span>
   );
};
</code></pre>
<hr />
<h3 id="heading-nesting-in-react-fragments">Nesting in React fragments</h3>
<p>React fragments can also be nested as:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> AppLayout = <span class="hljs-function">() =&gt;</span>{
   <span class="hljs-keyword">return</span>(
      <span class="xml"><span class="hljs-tag">&lt;&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Header</span> /&gt;</span>
        <span class="hljs-tag">&lt;&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">Body</span>/&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">Footer</span>/&gt;</span>
        <span class="hljs-tag">&lt;/&gt;</span></span>
      &lt;/&gt;
   );
};
</code></pre>
<hr />
<h3 id="heading-dom-representation">DOM Representation:</h3>
<p><strong>DOM without React fragments:</strong> has an extra ugly div</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1681839812598/92b91638-7b27-4e2b-a532-07f8004dcc1b.png" alt class="image--center mx-auto" /></p>
<p><strong>DOM with React fragments:</strong> Cleaner Code</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1681839826035/3ebcc2c1-4808-4c04-8448-b280a6db3bfb.png" alt class="image--center mx-auto" /></p>
<hr />
<h3 id="heading-limitations-of-react-fragment">Limitations of React Fragment:</h3>
<p>As there are many benefits of using fragments, there are a few limitations of reacting fragments too such as:</p>
<ol>
<li><p><strong>Browser Compatibility:</strong> React Fragments are not supported by all browsers specially older versions of browsers may not work with react fragments. You may need to use a polyfill function to support older browsers.</p>
</li>
<li><p><strong>Debugging:</strong> It can be difficult to debug issues with component rendering or performance as it doesn't have a direct representation in the DOM, so it can be hard to see what's happening under the hood.</p>
</li>
<li><p><strong>Performance:</strong> While React fragments can help to reduce the number of unnecessary DOM nodes in our application, they can also impact performance if used excessively. If we have too many nested React fragments, it can lead to a more complex virtual DOM and slower rendering times.</p>
</li>
</ol>
<hr />
]]></content:encoded></item></channel></rss>