<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Aditya Tyagi</title>
    <description>The latest articles on Forem by Aditya Tyagi (@adityatyagi).</description>
    <link>https://forem.com/adityatyagi</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%2F277831%2F20a43347-1d49-45e9-8de8-b65de85fa9c5.jpeg</url>
      <title>Forem: Aditya Tyagi</title>
      <link>https://forem.com/adityatyagi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/adityatyagi"/>
    <language>en</language>
    <item>
      <title>Logical CSS: Padding And Margins In Multi-lingual Web-Apps</title>
      <dc:creator>Aditya Tyagi</dc:creator>
      <pubDate>Fri, 14 Apr 2023 11:02:21 +0000</pubDate>
      <link>https://forem.com/adityatyagi/logical-css-padding-and-margins-in-multi-lingual-web-apps-4j4p</link>
      <guid>https://forem.com/adityatyagi/logical-css-padding-and-margins-in-multi-lingual-web-apps-4j4p</guid>
      <description>&lt;p&gt;There are two modules of CSS properties — Logical and Physical. If you are working on a multi-lingual web-app, then logical CSS properties will come real handy.&lt;/p&gt;

&lt;p&gt;Physical properties refer to the physical aspects of the viewports — height/width of the viewport.&lt;/p&gt;

&lt;p&gt;On the other hand, logical CSS properties works according to the flow of content. The values of such properties change with the change of:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/writing-mode" rel="noopener noreferrer"&gt;writing mode&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/direction" rel="noopener noreferrer"&gt;text direction&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The Need For Logical CSS
&lt;/h2&gt;

&lt;p&gt;Consider this example of a button with an icon on the left. Sample button with an icon and a margin between the icon and button text is shown below.&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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A980%2F1%2AAEy1GxhwhoTs3kE6sPAUDg.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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A980%2F1%2AAEy1GxhwhoTs3kE6sPAUDg.png" alt="Sample button with an icon and a margin between the icon and button text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All is good till we are dealing with languages that are left-to-right. With languages like Arabic/Hebrew, which are right-to-left, the button will look something like this (Button with language right-to-left):&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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A748%2F1%2Axv5ob4gYEipuTW8OZL2LuA.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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A748%2F1%2Axv5ob4gYEipuTW8OZL2LuA.png" alt="Button with language right-to-left"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, the icon has the margin on the wrong side. If you want to check, you can use the  &lt;code&gt;dir&lt;/code&gt;  attribute for  &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt;  tag to change the writing direction.&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;button&lt;/span&gt; &lt;span class="na"&gt;dir=&lt;/span&gt;&lt;span class="s"&gt;"rtl"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;  
    &lt;span class="nt"&gt;&amp;lt;svg&amp;gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;  
    &lt;span class="nt"&gt;&amp;lt;span&amp;gt;&lt;/span&gt;Sample Button&lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;  
&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To fix this, in addition to providing automatic support for internationalization, and creating a more robust front-end, we have &lt;strong&gt;&lt;em&gt;CSS Logical Properties.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Defination
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;CSS Logical Properties and Values is a module of  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS" rel="noopener noreferrer"&gt;CSS&lt;/a&gt;  introducing logical properties and values that provide the ability to control layout through logical, rather than physical, direction and dimension mappings.&lt;/p&gt;

&lt;p&gt;The module also defines logical properties and values for properties previously defined in CSS 2.1. Logical properties define direction‐relative equivalents of their corresponding physical properties.&lt;br&gt;&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Logical_Properties" rel="noopener noreferrer"&gt;- MDN Web Docs&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The thing to note in the above detailed (also verbose) defination is:  &lt;em&gt;Logical properties define direction‐relative equivalents of their corresponding physical properties.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Some of the Logical CSS properties are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; margin-block&lt;/li&gt;
&lt;li&gt; margin-block-start&lt;/li&gt;
&lt;li&gt; margin-block-end&lt;/li&gt;
&lt;li&gt; margin-inline&lt;/li&gt;
&lt;li&gt; margin-inline-start&lt;/li&gt;
&lt;li&gt; margin-inline-end&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The above combination exists for  &lt;code&gt;padding&lt;/code&gt;  too. To go through a complete list of these Logical CSS properties, explore  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Logical_Properties" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Physical CSS Properties: Rewind
&lt;/h2&gt;

&lt;p&gt;If you are fimiliar with the workings and  &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Shorthand_properties#margin_and_padding_properties" rel="noopener noreferrer"&gt;short-hands&lt;/a&gt;  for  &lt;code&gt;margin&lt;/code&gt;  and  &lt;code&gt;padding&lt;/code&gt;  , then you know that the values go clockwise. For example:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;margin: 1px 2px 3px 4px;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;sets position 1, 2, 3 and 4 in clock-wise direction.&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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A158%2F0%2AhSyElQS1vhqAAVHX.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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A158%2F0%2AhSyElQS1vhqAAVHX.png" alt="Clockswise positions to explain shorthands for margin and padding"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Clockswise positions to explain shorthands for margin and padding&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding The Basics Of Logical CSS Properties
&lt;/h2&gt;

&lt;p&gt;For this, we’ll consider going over the 4 basic properties:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; padding-inline and padding-block&lt;/li&gt;
&lt;li&gt; margin-inline and margin-block&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The margin and padding here are “flow relative” and not “direction relative”. This means, historically when we applied&lt;code&gt;margin-top&lt;/code&gt;  to a block, it added margin-top according to the physical aspect of the viewport — irrespective of the language direction/writing-mode. This causes an issue like:&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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A1400%2F1%2ACPJDQAbeIi0KCjuhexbkHQ.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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A1400%2F1%2ACPJDQAbeIi0KCjuhexbkHQ.png" alt="Example of physical margin-top"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But what should actually happen when the direction or writing-mode changes:&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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A1400%2F1%2ABEa6glZqpAb1VccS6ELijA.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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A1400%2F1%2ABEa6glZqpAb1VccS6ELijA.png" alt="Example of logical margin-block-start"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Block Flow
&lt;/h2&gt;

&lt;p&gt;The block flow is the direction in which the next “block” element will be placed. For example, if there are two  &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;  tags, so where the adjacent  &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;  will be placed is determined by the block flow.&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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A1400%2F1%2A18srIzzgYCyZ4Jcp9du9YA.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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A1400%2F1%2A18srIzzgYCyZ4Jcp9du9YA.png" alt="Block Flow"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding Inline Flow
&lt;/h2&gt;

&lt;p&gt;The inline flow is the direction in which the next “inline” element will be placed. i.e. how the words flow in a sentence. For example, if there are two  &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt;  tags, so where the adjacent  &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt;  will be placed is determined by the inline flow.&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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A1400%2F1%2AVn_UFfIp6gQdfkvRqU9dog.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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A1400%2F1%2AVn_UFfIp6gQdfkvRqU9dog.png" alt="Inline Flow"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With logical properties,  &lt;code&gt;margin-top&lt;/code&gt;  becomes  &lt;code&gt;margin-block-start&lt;/code&gt;  , irrespective of the writing mode or direction. This helps to create a more inclusive front-end and hence the block flow has appropriate margins.&lt;/p&gt;

&lt;h2&gt;
  
  
  Box Model for Logical CSS Properties
&lt;/h2&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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A1400%2F0%2Aac-ViFSQw4Zf3qiZ" 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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A1400%2F0%2Aac-ViFSQw4Zf3qiZ" alt="Box Model for Logical CSS Properties"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Image Credits:  &lt;a href="https://web.dev/" rel="noopener noreferrer"&gt;Box-model for logical CSS properties:&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Smart readers must have accounted for similarities with inline as well:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;text-align: right;&lt;/code&gt;  becomes  &lt;code&gt;text-align:end&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This helps us to align the text on the basis of “reading direction” and not to the physical right of the viewport.&lt;/p&gt;

&lt;p&gt;For  &lt;code&gt;direction: ltr&lt;/code&gt;  and  &lt;code&gt;text-align: end&lt;/code&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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A1400%2F1%2AROmf0INu2f9wJCj9f06T9Q.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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A1400%2F1%2AROmf0INu2f9wJCj9f06T9Q.png" alt="Direction left to right"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For  &lt;code&gt;direction:rtl&lt;/code&gt;  and and  &lt;code&gt;text-align: end&lt;/code&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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A1400%2F1%2AericVir0wfecoNY8nU1RdA.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%2Fmiro.medium.com%2Fv2%2Fresize%3Afit%3A1400%2F1%2AericVir0wfecoNY8nU1RdA.png" alt="Direction right to left"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Support
&lt;/h2&gt;

&lt;p&gt;The properties having a suffix of  &lt;code&gt;start&lt;/code&gt;  and  &lt;code&gt;end&lt;/code&gt;  (&lt;code&gt;margin-block-start&lt;/code&gt;  and  &lt;code&gt;margin-block-end&lt;/code&gt;) have strong compatibility and are a good choice for desktop and mobile both. But the properties which lack the suffix like  &lt;code&gt;margin-block&lt;/code&gt;  and  &lt;code&gt;margin-inline&lt;/code&gt;  are good for desktop but not for mobile.&lt;/p&gt;

&lt;p&gt;You can explore  &lt;a href="https://caniuse.com/?search=margin-block" rel="noopener noreferrer"&gt;CANIUSE.COM&lt;/a&gt;  to check complete support.&lt;/p&gt;

&lt;p&gt;Thanks for reading ❤&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Want to connect?&lt;br&gt;&lt;br&gt;
Follow me on&lt;/em&gt; &lt;a href="https://twitter.com/secondbestcoder" rel="noopener noreferrer"&gt;&lt;em&gt;Twitter&lt;/em&gt;&lt;/a&gt; &lt;em&gt;and&lt;/em&gt; &lt;a href="https://www.linkedin.com/in/aditya-tyagi-03b4189a/" rel="noopener noreferrer"&gt;&lt;em&gt;LinkedIn&lt;/em&gt;&lt;/a&gt; &lt;em&gt;or reach out in the comments below!&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>css</category>
    </item>
    <item>
      <title>Code Reviews Should Not Suck!</title>
      <dc:creator>Aditya Tyagi</dc:creator>
      <pubDate>Thu, 21 Jul 2022 07:10:50 +0000</pubDate>
      <link>https://forem.com/adityatyagi/code-reviews-should-not-suck-5c3j</link>
      <guid>https://forem.com/adityatyagi/code-reviews-should-not-suck-5c3j</guid>
      <description>&lt;h2&gt;
  
  
  How to raise a pull request (PR) as a beginner
&lt;/h2&gt;

&lt;p&gt;Code Reviews are one of the major things that a developer has to do on a daily basis. For some, the experience of reviewing code can be delightful but for others it can be quite stressful!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;According to Stack Overflow, the number one cause of stress in a developer’s life is code reviews.&lt;br&gt;&lt;br&gt;
- Just Kidding!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Code reviews or Pull Requests (PR) reviews is the process of collaborating on a piece of code to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Approve changes&lt;/li&gt;
&lt;li&gt; Request changes&lt;/li&gt;
&lt;li&gt; Comment on the changes&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The process is important to ensure a healthy codebase. Without a formal PR review process, you’ll end up with a pandora box of surprises! Sometimes these surprises makes to production!&lt;/p&gt;

&lt;p&gt;There are certain things that make the PR reviewing process difficult. Let’s go into detail about some prominent issues and how to avoid them.&lt;/p&gt;

&lt;h2&gt;
  
  
  No Clear Reviewer or Assignee or Title
&lt;/h2&gt;

&lt;p&gt;Whenever you receive a PR to review and there is no assignee/reviewer added, it becomes difficult to track all the updates and changes to the PR. Therefore before opening a PR, always add details of the reviewer and assignee.&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%2Fmiro.medium.com%2Fmax%2F390%2F1%2Arvz_-rp-9aABUSU8xKB8pw.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%2Fmiro.medium.com%2Fmax%2F390%2F1%2Arvz_-rp-9aABUSU8xKB8pw.png" alt="Missing reviewer and assignee"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Check out the &lt;a href="https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/requesting-a-pull-request-review" rel="noopener noreferrer"&gt;official docs&lt;/a&gt; to understand how to add reviewer and assignee to your PR.&lt;/p&gt;

&lt;p&gt;Ensure the title of your PR is self-explanatory as this will appear in git history when the PR is merged. Do not add vague and gibberish things that make sense to you, but not others!&lt;/p&gt;

&lt;h2&gt;
  
  
  Delayed Reviews
&lt;/h2&gt;

&lt;p&gt;Everybody is busy with their work. Understandable. But we need to understand our position when we are a reviewer for a PR. The assignee might be waiting for a review/go-ahead on a PR so that they can continue with their work.&lt;/p&gt;

&lt;p&gt;In bigger teams, it is often seen that PRs are in review for far too long. Not hours, but days. Teams must come to a Service Level Agreement (SLA) for reviewing PRs. This is the time elapsed between a PR is raised and it is reviewed. For some it can be 1 hour, but for other it can be 5. This sets the right expectations for all stakeholders.&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%2Fmiro.medium.com%2Fmax%2F700%2F0%2Avnlt26UOvvNWRUgR.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%2Fmiro.medium.com%2Fmax%2F700%2F0%2Avnlt26UOvvNWRUgR.png" alt="Image by GitHub for Slack Reminders on PRs"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One of the major tools that I am a fan of is &lt;strong&gt;Slack Reminders.&lt;/strong&gt; You can set alerts for all your PRs and it will send little reminders on a slack channel. You can read more about it here: &lt;a href="https://docs.github.com/en/organizations/organizing-members-into-teams/managing-scheduled-reminders-for-your-team" rel="noopener noreferrer"&gt;Managing scheduled reminders for your team&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Missing Details — Pull Request Templates
&lt;/h2&gt;

&lt;p&gt;In this remote-first world, the conversations and the work happen asynchronously. Thus, it is highly possible that the reviewer of your PR is sitting in a different time-zone.&lt;/p&gt;

&lt;p&gt;Now, if your PR has inadequate information, then the PR review will get delayed by minimum 24 hours. Hence, your PR needs to have all the necessary information.&lt;/p&gt;

&lt;p&gt;If you are confused and do not know what a PR template should entail, check this little take on pull requests:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Bad pull requests are unclear. They don’t have clear answers to &lt;strong&gt;“why are we doing this?”&lt;/strong&gt; and &lt;strong&gt;“why are we doing it like this?”&lt;/strong&gt;. They are usually unreasonable in size and include multiple changes to multiple subsystems. The reader is typically unsure if the pull request is mergeable, nor does he have any metric to help answer this question.&lt;br&gt;&lt;br&gt;
- &lt;a href="https://twitter.com/igor_sarcevic" rel="noopener noreferrer"&gt;Igor Šarčević&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;By “necessary information” I mean all the details the reviewer of the PR will need to test out the PR. This can be:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Module for which the PR makes changes to&lt;/li&gt;
&lt;li&gt; Some background — Why and How&lt;/li&gt;
&lt;li&gt; JIRA Ticket attached to the PR&lt;/li&gt;
&lt;li&gt; Necessary testing steps&lt;/li&gt;
&lt;li&gt; Any specific environment changes the reviewer should do to review the PR&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It is difficult and an unrealistic expectation to have from developers adding these details every-time they raise a PR. Hence, use another feature — &lt;a href="https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/creating-a-pull-request-template-for-your-repository" rel="noopener noreferrer"&gt;PR Templates&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Pull Request Templates are helpful in reminding developers to fill the necessary details before submitting the PR. It can be as simple as having a reminder to “self-review” the PR and as complex as adding an &lt;code&gt;.env&lt;/code&gt; file and testing steps.  &lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;This small template can save you hours of back-and-forth with the assignee of the PR and hence speed up the process. To see how it changes the whole experience of PR reviewing, I have filled a PR template below.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;See how easy it becomes to review the PR now. At least, start with the review.&lt;/p&gt;

&lt;h2&gt;
  
  
  Repeated/Skipped/Ignored Reviews
&lt;/h2&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%2Fmiro.medium.com%2Fmax%2F660%2F0%2A9FxtBqjiWCSbAmxW" 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%2Fmiro.medium.com%2Fmax%2F660%2F0%2A9FxtBqjiWCSbAmxW" alt="Clean code by Yuva Krishna Memes"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This happens majorly with the developers who have just joined the workforce and hence tend to repeat the same mistakes they have already been pointed out. This makes PR reviewing a task and a bad one!&lt;/p&gt;

&lt;p&gt;So, if you are a newbie and are getting review fixes around best practices or logic in one of your PRs, please ensure the subsequent PRs do not have the same mistakes. This point can be eliminated by a simple but thorough self-review.&lt;/p&gt;

&lt;p&gt;The other side of this is when the reviewer gave you a substantial number of reviews and you skip them. Skipping them is still an honest mistake, but if you ignored it on purpose, that is just not acceptable. You need to understand and acknowledge the amount of time and hard-work the reviewer has invested. The reviewer wants to learn. Ignoring the ones you think are not substantial is just not cool!&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%2Fmiro.medium.com%2Fmax%2F700%2F1%2A9NdfLdAgFn5VJci3O5Ks-w.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%2Fmiro.medium.com%2Fmax%2F700%2F1%2A9NdfLdAgFn5VJci3O5Ks-w.png" alt="Acknowledge the PR review"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The remedy to this is having an “acknowledgement system” for all the reviews. Whenever you fix the PR reviews and comments given, just leave a 👍 (thumbs-up emoji) or “Done” on that conversation. It won’t take more than a minute, but will go a long way in this two-way communication.&lt;/p&gt;

&lt;h2&gt;
  
  
  Singleton Purpose Of The Pull Request
&lt;/h2&gt;

&lt;p&gt;One of the thumb rules that you have to follow is not to cover too many fixes and random things in a single pull request. Keep the work in the PR scoped to what the PR was intended for.&lt;/p&gt;

&lt;p&gt;There are times when the perfectionist developer with ADHD in you cannot stand code smells. Just because it’s a minor fix, you try to squeeze those fixes in your PR too. Yes, you did a great job, but that was not the job you were given. The PR should be precise.&lt;/p&gt;

&lt;p&gt;These little things (a.k.a habits) do improve the code base but at the cost of increased time of PR reviews. You can inform your reviewer about these code-smells. Do not increase the scope of the PR unnecessarily.&lt;/p&gt;

&lt;h2&gt;
  
  
  No PR Should Be More Than 400 Lines Of Code — Scientifically Backed
&lt;/h2&gt;

&lt;p&gt;There are companies who instantly reject PRs if it has more than 500 lines of code. &lt;a href="https://twitter.com/igor_sarcevic" rel="noopener noreferrer"&gt;Igor Šarčević&lt;/a&gt; very beautifully puts this point across with his take on &lt;a href="https://morningcoffee.io/pull-requests-are-a-reflection-of-your-engineering-culture.html" rel="noopener noreferrer"&gt;Pull Requests are a reflection of your engineering culture&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The longer we stare at something, the more blind to it we become. After an hour of looking at the same thing our brain becomes saturated and less effective at spotting issues.&lt;/p&gt;

&lt;p&gt;Based on this data and the finding that review efficiency falls after 90 minutes, they concluded that a reviewer will be &lt;strong&gt;&lt;em&gt;most effective reviewing no more than 400 lines of code in one go&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;- &lt;a href="https://tekin.co.uk/2020/05/proof-your-thousand-line-pull-requests-create-more-bugs" rel="noopener noreferrer"&gt;Proof your thousand-line pull requests result in more bugs&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Yes, there can be instances where you would not be able to follow this cardinal rule of 400 lines of code. But believe me, you can. &lt;a href="https://tekin.co.uk/2020/05/proof-your-thousand-line-pull-requests-create-more-bugs" rel="noopener noreferrer"&gt;Proof your thousand-line pull requests result in more bugs&lt;/a&gt; post underlines the ways we can spilt the PR with more than 400 lines of code and still not break the PRs.&lt;/p&gt;

&lt;p&gt;In brief:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Separate out refactoring&lt;/li&gt;
&lt;li&gt; Lay out the foundation of PR in 1 part&lt;/li&gt;
&lt;li&gt; Use feature flags&lt;/li&gt;
&lt;li&gt; Commit by portion of code and not based on time is another analogy by &lt;a href="https://twitter.com/vanamerongen" rel="noopener noreferrer"&gt;Pauline Vos&lt;/a&gt; in her talk Git Legit (&lt;a href="https://dev.to/paulinevos/atomic-commits-will-help-you-git-legit-35i7"&gt;Atomic commits will help you git legit&lt;/a&gt;). If you are interested in reading more on Atomic Commits, &lt;a href="https://www.aleksandrhovhannisyan.com/blog/atomic-git-commits/" rel="noopener noreferrer"&gt;check this out&lt;/a&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Mind Your Tone Of Writing
&lt;/h2&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%2Fmiro.medium.com%2Fmax%2F700%2F0%2ANxf1VbefJtP7nr15" 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%2Fmiro.medium.com%2Fmax%2F700%2F0%2ANxf1VbefJtP7nr15" alt="Photo by Max van den Oetelaar on Unsplash"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Be polite. Be respectful. Be mindful. Everyone is learning here and everyone commits mistakes (pun intended). Hence, mind your tone of writing while you are giving out reviews or you are replying on the given review.&lt;/p&gt;

&lt;p&gt;DO NOT USE ALL CAPS to show you are frustrated and are shouting (imaginary)&lt;/p&gt;

&lt;p&gt;Give compliments wherever it’s due.&lt;/p&gt;

&lt;p&gt;Thank your reviewer once a long PR is getting merged after 3–4 back and forth. Thank the reviewer if you have learnt anything new.&lt;/p&gt;




&lt;p&gt;Thanks for reading ❤&lt;/p&gt;

&lt;p&gt;If this blog was able to bring value, please follow me &lt;a href="https://dev.to/adityatyagi"&gt;here&lt;/a&gt;! Your support keeps me driven!&lt;/p&gt;

&lt;p&gt;Originally published on &lt;a href="https://adityatyagi.com/index.php/2022/07/20/code-reviews-should-not-suck/" rel="noopener noreferrer"&gt;adityatyagi.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Want to connect?&lt;br&gt;
Follow me on &lt;a href="https://twitter.com/secondbestcoder" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; and &lt;a href="https://www.linkedin.com/in/aditya-tyagi-03b4189a/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; or reach out in the comments below!&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Responsive Font-Sizes In React Apps</title>
      <dc:creator>Aditya Tyagi</dc:creator>
      <pubDate>Sun, 03 Jul 2022 08:05:33 +0000</pubDate>
      <link>https://forem.com/adityatyagi/responsive-font-sizes-in-react-apps-4lo1</link>
      <guid>https://forem.com/adityatyagi/responsive-font-sizes-in-react-apps-4lo1</guid>
      <description>&lt;h2&gt;
  
  
  Best CSS practice to ensure consistent styling in web applications
&lt;/h2&gt;

&lt;p&gt;We live in a mobile-first world and hence as a front-end developer it is our job to ensure that the web-apps we are building are mobile-friendly. With the rise of hybrid frameworks, things that are developed for web are easily translated to Android and iOS applications.&lt;/p&gt;

&lt;p&gt;This shift in the development community has not only reduced the cost of shipping products but has also increased the speed at which these products are being shipped. Having responsive apps thus becomes far more important today. There are a ton of ways to &lt;a href="https://adityatyagi.com/index.php/2022/02/06/4-ways-to-style-react-components-a-beginners-guide/" rel="noopener noreferrer"&gt;style your react apps&lt;/a&gt; but for making your web apps responsive, you need to have your fundamentals clear!&lt;/p&gt;

&lt;h2&gt;
  
  
  Pre-requisite to understanding responsive layouts
&lt;/h2&gt;

&lt;p&gt;Copy-pasting this little hack will serve the purpose but that is not how true developers work, and if you are reading this, I know you are are legit developer! So, please understand the underlying principles first and then implement it.&lt;/p&gt;

&lt;p&gt;With this little hack, you can ensure consistent:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Spacing&lt;/li&gt;
&lt;li&gt; Fonts&lt;/li&gt;
&lt;li&gt; Image sizes&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;across your web app. This one little hack will require you to use a CSS pre-processor like &lt;a href="https://sass-lang.com/" rel="noopener noreferrer"&gt;SCSS or SASS&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;As a pre-requisite, you need to understand relative CSS length units&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;code&gt;px&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; &lt;code&gt;em&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; &lt;code&gt;rem&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; &lt;code&gt;vh&lt;/code&gt; / &lt;code&gt;vw&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; &lt;code&gt;vmin&lt;/code&gt; / &lt;code&gt;vmax&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;Relative length units are relative to something else, perhaps the size of the parent element’s font, or the size of the viewport. The benefit of using relative units is that with some careful planning you can make it so the size of text or other elements scales relative to everything else on the page.&lt;br&gt;&lt;br&gt;
- &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units#numbers_lengths_and_percentages" rel="noopener noreferrer"&gt;MDN Web Docs&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There are 18 relative CSS length units and you can read about them &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units#numbers_lengths_and_percentages" rel="noopener noreferrer"&gt;here&lt;/a&gt;. But for this little hack, all we need to understand &lt;code&gt;rem&lt;/code&gt; .&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS REM — What is REM in CSS?
&lt;/h2&gt;

&lt;p&gt;Any CSS value that is measured in &lt;code&gt;rem&lt;/code&gt; is measured &lt;strong&gt;&lt;em&gt;relative to font-size of the root element.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;TLDR: Using &lt;code&gt;rem&lt;/code&gt; and &lt;code&gt;em&lt;/code&gt; units is better than using px.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;rem&lt;/code&gt; stands for &lt;strong&gt;root em&lt;/strong&gt; and it means “root element’s font size”. As web developers we need to understand that our apps will be used by all types of users — young, old, specially abled, and thus we need to take care of accessibility. &lt;code&gt;rem&lt;/code&gt; helps us to maintain that accessibility.&lt;/p&gt;

&lt;p&gt;Why not &lt;code&gt;px&lt;/code&gt; ? The disadvantage with using &lt;code&gt;px&lt;/code&gt; with everything like padding, margin and font-sizes is that the UI &lt;em&gt;does not scale proportionately&lt;/em&gt;. This is where &lt;code&gt;rem&lt;/code&gt; shines. It helps the UI to &lt;em&gt;scale&lt;/em&gt; &lt;em&gt;proportionately.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The root font-size is 16px. So, when we encounter a value of &lt;code&gt;1rem&lt;/code&gt; , we mean &lt;code&gt;16px&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  When to use &lt;code&gt;rem&lt;/code&gt; and when to use other relative CSS units?
&lt;/h2&gt;

&lt;p&gt;I personally use &lt;code&gt;rem&lt;/code&gt; for font-sizes and &lt;code&gt;em&lt;/code&gt; for &lt;code&gt;margin&lt;/code&gt; and &lt;code&gt;padding&lt;/code&gt; . You care read more about it &lt;a href="https://www.aleksandrhovhannisyan.com/blog/use-rems-for-font-size/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;There are solid reasons to use &lt;code&gt;rem&lt;/code&gt; and not &lt;code&gt;em&lt;/code&gt; for font-sizes. While re-searching about this blog post (yes, I do my homework!), I came across this very detailed analysis on &lt;code&gt;rem&lt;/code&gt; on font-sizes. Please go through it once and thank me later!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.aleksandrhovhannisyan.com/blog/use-rems-for-font-size/" rel="noopener noreferrer"&gt;Use Rems for Font Size to Respect User Preferences&lt;/a&gt; by &lt;a href="https://www.linkedin.com/in/aleksandr-hovhannisyan-ba154b120/" rel="noopener noreferrer"&gt;Aleksandr&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How To Use REM In CSS
&lt;/h2&gt;

&lt;p&gt;There are multiple ways to use &lt;code&gt;rem&lt;/code&gt; in your front-end applications. This is not something specific to React. You can use it with any web-applications.&lt;/p&gt;

&lt;p&gt;Some of them, from the same &lt;a href="https://www.aleksandrhovhannisyan.com/blog/use-rems-for-font-size/" rel="noopener noreferrer"&gt;article&lt;/a&gt; above are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Work out the math by hand (e.g., &lt;code&gt;24 / 16 = 1.5rem&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;  Use a CSS calc expression (e.g., &lt;code&gt;calc(1rem * 24 / 16)&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;  Use a CSS preprocessor like Sass and write a custom &lt;code&gt;to-rems&lt;/code&gt; utility function.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.aleksandrhovhannisyan.com/blog/62-5-percent-font-size-trick/" rel="noopener noreferrer"&gt;Use the 62.5% font size trick to make the math easier&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here, we’ll be discussing the third in the list i.e &lt;strong&gt;Use a CSS preprocessor like Sass and write a custom&lt;/strong&gt; &lt;code&gt;to-rems&lt;/code&gt; &lt;strong&gt;utility function.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As I have already pointed out that we need to use a CSS preprocessor for this. I am going with &lt;a href="https://sass-lang.com/" rel="noopener noreferrer"&gt;SASS&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This is a utility function wherein you just pass the value in &lt;code&gt;px&lt;/code&gt; and the function returns the &lt;code&gt;rem&lt;/code&gt; equivalent.&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%2Fmiro.medium.com%2Fmax%2F1260%2F1%2AVIR1MPPHT9Yo5-IdzUgXEg.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%2Fmiro.medium.com%2Fmax%2F1260%2F1%2AVIR1MPPHT9Yo5-IdzUgXEg.png" alt="pxToRem function"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Consider this situation:&lt;/p&gt;

&lt;p&gt;You are working with a UI/UX designer and the designer provides you with a Figma file. Your job is to convert Figma designs in front-end code, but in a responsive manner. Now the font-size values can vary for different designs and screens and hence you cannot have a pre-determined CSS variables. This is where the CSS utility method &lt;code&gt;pxToRem&lt;/code&gt; will come handy!&lt;/p&gt;

&lt;p&gt;You can use this function like this:&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%2Fmiro.medium.com%2Fmax%2F1260%2F1%2AXzMaMVdu-gvhARbdfeZHZQ.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%2Fmiro.medium.com%2Fmax%2F1260%2F1%2AXzMaMVdu-gvhARbdfeZHZQ.png" alt="Using utility function"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Need for a utility function
&lt;/h2&gt;

&lt;p&gt;Getting &lt;code&gt;rem&lt;/code&gt; values for &lt;code&gt;px&lt;/code&gt; values like 16px, 32px, 8px is easy for a root font-size of 16px. It will be 1rem, 2rem, 0.5rem.&lt;/p&gt;

&lt;p&gt;But what if we want to capture font-size values of 15px, 35px, 7px? I certainly cannot divide 15/16 and come to a floating value with proper rounding off at a moments notice. But it might be easy for you. So, kudos to the “genius” in you!&lt;/p&gt;

&lt;p&gt;Not everyone is a genius like you! I certainly am not!&lt;/p&gt;

&lt;p&gt;Now, for dumb people like me who are not math wizards and are able to do the calculation on the fly, we need a simple utility function.&lt;/p&gt;

&lt;p&gt;But for a math wizard/genius like you, all you need to do is divide the value in &lt;code&gt;px&lt;/code&gt; you want to convert in &lt;code&gt;rem&lt;/code&gt; by the root font-size.&lt;/p&gt;

&lt;p&gt;So, if the root font-size is &lt;code&gt;16px&lt;/code&gt; then the utility function can give back &lt;code&gt;rem&lt;/code&gt; values pretty easily. All we have to pass is the font-size values from the Figma designs.&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%2Fmiro.medium.com%2Fmax%2F1260%2F1%2AHiFy8hMXT-Hv3lH5N011Yw.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%2Fmiro.medium.com%2Fmax%2F1260%2F1%2AHiFy8hMXT-Hv3lH5N011Yw.png" alt="Using utility function"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Not To Use EM For Font-Sizes in CSS?
&lt;/h2&gt;

&lt;p&gt;I’d like to cover this part as well so that you can appear smart in-front of your peers when they attack you with this questions!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;So, &lt;code&gt;em&lt;/code&gt; calculates the value relative to its parent element with an explicit &lt;code&gt;font-size&lt;/code&gt; Therefore it will take the relative value from it’s &lt;strong&gt;closest common ancestor with any &lt;em&gt;explicit&lt;/em&gt; font size value&lt;/strong&gt;. So even if it’s container or container’s container had an explicit font size set, it will use that value&lt;br&gt;&lt;br&gt;
- &lt;a href="https://dev.to/ortonomy/comment/1fbpg"&gt;A very thoughtful comment&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let me show via an example, where things can go south when using &lt;code&gt;em&lt;/code&gt; for font-sizes:&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%2Fmiro.medium.com%2Fmax%2F1260%2F1%2AuALGkyyfdWWpv-8PGwvLeg.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%2Fmiro.medium.com%2Fmax%2F1260%2F1%2AuALGkyyfdWWpv-8PGwvLeg.png" alt="HTML file with parent-child elements"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we give a &lt;code&gt;font-size&lt;/code&gt; to the parent element. The child element will consider parent’s i.e &lt;strong&gt;closest common ancestor with an &lt;em&gt;explicit&lt;/em&gt; font size value&lt;/strong&gt; as its base for the calculation of &lt;code&gt;rem&lt;/code&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%2Fmiro.medium.com%2Fmax%2F1260%2F1%2AACgkRMBVHhbc9VwDgOx3pQ.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%2Fmiro.medium.com%2Fmax%2F1260%2F1%2AACgkRMBVHhbc9VwDgOx3pQ.png" alt="CSS file where child gets parent’s font-size as base for em value"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But, this can create an issue as you can see here. Different parent elements can have different explicit values for font-sizes and hence it will lead to different results for the same &lt;code&gt;0.5em&lt;/code&gt; values in children elements.&lt;/p&gt;

&lt;p&gt;The issue becomes even more serious with nesting:&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%2Fmiro.medium.com%2Fmax%2F1260%2F1%2ASoxYGKqP6R1u2VYmB3CROA.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%2Fmiro.medium.com%2Fmax%2F1260%2F1%2ASoxYGKqP6R1u2VYmB3CROA.png" alt="Nested child"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If we give font-size to &lt;code&gt;parent&lt;/code&gt; and &lt;code&gt;sub-parent&lt;/code&gt; , the child will get the nested value in terms of &lt;code&gt;em&lt;/code&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%2Fmiro.medium.com%2Fmax%2F1260%2F1%2AMuWJbY4-3smpRsMjG73deg.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%2Fmiro.medium.com%2Fmax%2F1260%2F1%2AMuWJbY4-3smpRsMjG73deg.png" alt="Problems with nested child when using em"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hence, we cannot use &lt;code&gt;em&lt;/code&gt; for font-sizes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Other ways to use REM in CSS for responsive web apps
&lt;/h2&gt;

&lt;p&gt;The above is just one of the ways to use &lt;code&gt;rem&lt;/code&gt; for your web applications. There are other ways as well. Please feel free to explore them here.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;a href="https://www.aleksandrhovhannisyan.com/blog/62-5-percent-font-size-trick/" rel="noopener noreferrer"&gt;The 62.5% Font Size Trick&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; Work out the math by hand (e.g., &lt;code&gt;24 / 16 = 1.5rem&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt; Use a CSS calc expression (e.g., &lt;code&gt;calc(1rem * 24 / 16)&lt;/code&gt;).&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Thanks for reading ❤&lt;/p&gt;

&lt;p&gt;If this blog was able to bring value, please follow me &lt;a href="https://dev.to/adityatyagi"&gt;here&lt;/a&gt;! Your support keeps me driven!&lt;/p&gt;

&lt;p&gt;Originally published on &lt;a href="https://adityatyagi.com/index.php/2022/07/02/responsive-font-sizes-in-react-apps/" rel="noopener noreferrer"&gt;adityatyagi.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Want to connect?&lt;br&gt;
Follow me on &lt;a href="https://twitter.com/secondbestcoder" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; and &lt;a href="https://www.linkedin.com/in/aditya-tyagi-03b4189a/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; or reach out in the comments below!&lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>react</category>
    </item>
    <item>
      <title>Everyday GIT</title>
      <dc:creator>Aditya Tyagi</dc:creator>
      <pubDate>Thu, 30 Jun 2022 10:18:22 +0000</pubDate>
      <link>https://forem.com/adityatyagi/everyday-git-1hkc</link>
      <guid>https://forem.com/adityatyagi/everyday-git-1hkc</guid>
      <description>&lt;h2&gt;
  
  
  Might not be for you, but might be exactly what you need!
&lt;/h2&gt;

&lt;p&gt;Not another git cheatsheet you say?? There are a ton of git cheatsheets already there are it is highly unlikely that i’ll ever refer to a cheat sheet when I can just google that sh** in 5 min and go through 5 Stack Overflow answers. Copy-paste random things until something works!&lt;/p&gt;

&lt;h2&gt;
  
  
  Why another Git Cheatsheet?
&lt;/h2&gt;

&lt;p&gt;I beg to differ. I say this because most of the git cheat-sheets out there are very generic and have commands that I will rarely use. In my 4 years of dev career, which is pretty small as compared to some of the veterans out there, but still have managed to narrow down to the following git commands.&lt;/p&gt;

&lt;p&gt;These are the commands that I use daily, almost. Some of these are the ones that come handy when I f*** up and f*** up bad. Some of these are just because I am too lazy to type.&lt;/p&gt;

&lt;p&gt;Why a blog? Why a publicly available blog?&lt;/p&gt;

&lt;p&gt;This is majorly a self-note blog post. A reference point for me. No matter where I am, and irrespective of the organisation I am working for, this blog post will the go-to point.&lt;/p&gt;

&lt;p&gt;What’s in it for you?&lt;/p&gt;

&lt;p&gt;Nothing special but everything you want. To be honest, bookmark it, or ignore it if you feel it’s too much. But the following are the commands that I have used and I am positive that I’ll be using it more!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_TZVjkj8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/450/1%2APHRg1zjcUYALnD41hySVFg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_TZVjkj8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/450/1%2APHRg1zjcUYALnD41hySVFg.jpeg" alt="Not another GIT Cheatsheet" width="450" height="525"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Useful GIT resources
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Wce-0oWB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/630/1%2A2wvwCbuH-P3VlYGu_X9N_w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Wce-0oWB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/630/1%2A2wvwCbuH-P3VlYGu_X9N_w.png" alt="Find the complete table here" width="630" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://adityatyagi.com/index.php/2022/01/08/everyday-git/"&gt;Find the complete table here&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  ReadMe and Markdown
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt; &lt;a href="https://github.com/adam-p/markdown-here/wiki/Markdown-Here-Cheatsheet"&gt;ReadMe and Markdown Cheatsheet&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Git Alias
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CAh0PhVm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/469/1%2Aoy3SI_AFTke3Hb5A_srNWg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CAh0PhVm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/469/1%2Aoy3SI_AFTke3Hb5A_srNWg.jpeg" alt="Git Alias" width="469" height="447"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Git Alias are nothing but &lt;code&gt;git&lt;/code&gt; shortcuts. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; cherry-pick
st &lt;span class="o"&gt;=&lt;/span&gt; status &lt;span class="nt"&gt;-s&lt;/span&gt;
cl &lt;span class="o"&gt;=&lt;/span&gt; clone
ci &lt;span class="o"&gt;=&lt;/span&gt; commit
co &lt;span class="o"&gt;=&lt;/span&gt; checkout
br &lt;span class="o"&gt;=&lt;/span&gt; branch
diff &lt;span class="o"&gt;=&lt;/span&gt; diff &lt;span class="nt"&gt;--word-diff&lt;/span&gt;
dc &lt;span class="o"&gt;=&lt;/span&gt; diff &lt;span class="nt"&gt;--cached&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A progammer uses simple commands like fetch, pull, merge, rebase, push on a daily basis and like a 1000 times. There are commands that are simple, yet verbose to type. Git Alias helps to create shortcuts for these git scripts.&lt;/p&gt;

&lt;p&gt;You can add alias one at a time:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.co checkout
&lt;span class="nv"&gt;$ &lt;/span&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.br branch
&lt;span class="nv"&gt;$ &lt;/span&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.ci commit
&lt;span class="nv"&gt;$ &lt;/span&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.st status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or you can add all at once. To setup git alias, we need to edit the &lt;code&gt;.gitconfig&lt;/code&gt; file and add the aliases there. The path of this file can vary depending on the operating system you are working on.&lt;/p&gt;

&lt;p&gt;Generally,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; MacOS: &lt;code&gt;~/.gitconfig&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Linux: &lt;code&gt;~/.gitconfig&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Windows: It can be different based on system settings. &lt;a href="https://stackoverflow.com/questions/2114111/where-is-the-global-git-config-data-stored"&gt;A starting point&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To quickly open, try running &lt;code&gt;git config --global --edit&lt;/code&gt; in terminal and it is highly possible that it will open in your default editor.&lt;/p&gt;

&lt;p&gt;There are literally a ton of aliases that you can use and what works for me, might not work for you. Thus, will drop few links here where in you can select the aliases that works for you.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;a href="https://www.durdn.com/blog/2012/11/22/must-have-git-aliases-advanced-examples/"&gt;Must Have Git Aliases: Advanced Examples by Nicola Paolucci&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; Sample &lt;code&gt;.gitconfig&lt;/code&gt; file: Check &lt;a href="https://github.com/durdn/cfg/blob/master/.gitconfig"&gt;here&lt;/a&gt; or &lt;a href="https://gist.github.com/johnpolacek/69604a1f6861129ef088"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The most powerful feature of git alias is positional parameters. Positional parameters, in simple words are the values to your alias functions. Yes, functions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;my_alias &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"!f() { 〈your complex command〉 }; f"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can write alias functions that take arguments (just like normal functions) and run the script with them. The only thing you have to take care of is the order in which you pass parameters while invoking alias.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  $1 to mean the first parameter passed to the command.&lt;/li&gt;
&lt;li&gt;  $2 to mean the second parameter passed to the command. (and so on for $3,
$4, etc.)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, if you want to delete branch locally and remotely but don’t want to remember the long git script&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git branch -d localBranchName &amp;amp;&amp;amp; git push origin --delete remoteBranchName&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can create a git alias function&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;delAll &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"!f() { &lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;
         git branch -D &lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt; &amp;amp;&amp;amp; git push origin --delete &lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;&lt;span class="s2"&gt;; &lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;
       }; f"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, all you have to do is pass the branch name you want to delete locally and on remote. You can fire this beauty by:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git delall mybranchName&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Multiple Git SSH accounts
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt; &lt;a href="https://devconnected.com/how-to-clone-a-git-repository/#Specifying_the_SSH_key_to_use"&gt;Specifying the SSH key to use&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Special Mentions
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt; &lt;a href="https://www.conventionalcommits.org/en/v1.0.0/"&gt;Conventional Commits: A specification for adding human and machine readable meaning to commit messages&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Thanks for reading ❤&lt;/p&gt;

&lt;p&gt;If this blog was able to bring value, please follow me &lt;a href="https://dev.to/adityatyagi"&gt;here&lt;/a&gt;! Your support keeps me driven!&lt;/p&gt;

&lt;p&gt;Originally published on &lt;a href="https://adityatyagi.com/index.php/2022/01/08/everyday-git/"&gt;adityatyagi.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Want to connect?&lt;br&gt;
Follow me on &lt;a href="https://twitter.com/secondbestcoder"&gt;Twitter&lt;/a&gt; and &lt;a href="https://www.linkedin.com/in/aditya-tyagi-03b4189a/"&gt;LinkedIn&lt;/a&gt; or reach out in the comments below!&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Why NextJs should not be ignored.</title>
      <dc:creator>Aditya Tyagi</dc:creator>
      <pubDate>Wed, 29 Jun 2022 06:33:59 +0000</pubDate>
      <link>https://forem.com/adityatyagi/why-nextjs-should-not-be-ignored-28gk</link>
      <guid>https://forem.com/adityatyagi/why-nextjs-should-not-be-ignored-28gk</guid>
      <description>&lt;h2&gt;
  
  
  A brief introduction to a full-stack framework backed with React syntax
&lt;/h2&gt;

&lt;p&gt;The NextJs official website’s landing page terms NextJs as “&lt;strong&gt;The React Framework for Production”&lt;/strong&gt;. It is by &lt;a href="https://vercel.com/dashboard"&gt;Vercel&lt;/a&gt;. I encountered NextJs while I was pursuing to become a full-stack developer with 4+ years of hands-on experience in front-end web technologies.&lt;/p&gt;

&lt;p&gt;NextJs is a layer on top of React extending its capabilities. React does not need NextJs, but NextJs needs React. Therefore, to be good at NextJs, one needs to go through React concepts! React is a Javascript library while NextJs is a React framework.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TLDR&lt;/strong&gt;: I was blown away with the number of features NextJs comes right out-of-the-box!&lt;/p&gt;

&lt;p&gt;Some of the features that you might like are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Server-side rendering (SSR)&lt;/li&gt;
&lt;li&gt; Static site generation (SSG)&lt;/li&gt;
&lt;li&gt; API routes&lt;/li&gt;
&lt;li&gt; Built-in Image optimization&lt;/li&gt;
&lt;li&gt; Automatic code splitting by route&lt;/li&gt;
&lt;li&gt; Dynamic Static Regeneration&lt;/li&gt;
&lt;li&gt; Server components (experimental)&lt;/li&gt;
&lt;li&gt; Automatic link prefetching&lt;/li&gt;
&lt;li&gt; Built-in head/meta tag component&lt;/li&gt;
&lt;li&gt; Built-in scroll restoration&lt;/li&gt;
&lt;li&gt; Middleware support&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is indeed a long list of features that you might/might-not know about, but I can guarantee you that once you are well versed with each of these, it will be hard for you to ignore NextJs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Products using NextJs
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WQoQEQsy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/630/1%2ALOY_i1W4oLGHVVBL8ony6A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WQoQEQsy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/630/1%2ALOY_i1W4oLGHVVBL8ony6A.png" alt="Products using NextJs" width="630" height="330"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You won’t believe what all products have already switched to this beast. Let me list a few down here, but for a more exhaustive list and to have your jaw dropped, check &lt;a href="https://nextjs.org/showcase"&gt;this&lt;/a&gt; out!&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; TikTok&lt;/li&gt;
&lt;li&gt; Hulu&lt;/li&gt;
&lt;li&gt; Nike&lt;/li&gt;
&lt;li&gt; AT&amp;amp;T&lt;/li&gt;
&lt;li&gt; GoPro&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If the data is not changing multiple times every single second, then it is a contender for NextJs. NextJs can be used for the use-cases such as:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Landing pages&lt;/li&gt;
&lt;li&gt; Small static websites&lt;/li&gt;
&lt;li&gt; Marketing websites&lt;/li&gt;
&lt;li&gt; E-commerce websites&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Comparison with other frameworks
&lt;/h2&gt;

&lt;p&gt;The official website gives a catchy intro as:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Next.js gives you the best developer experience with all the features you need for production: hybrid static &amp;amp; server rendering, TypeScript support, smart bundling, route pre-fetching, and more. No config needed.&lt;br&gt;&lt;br&gt;
&lt;a href="https://nextjs.org/"&gt;- NextJs&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The best part of diving into NextJs (as a seasoned ReactJs developer) is that the syntax and the underlying principles are same (almost). The learning curve is not steep and one can grab the basics in a couple of days.&lt;/p&gt;

&lt;p&gt;The JS world is ever-so-growing and one can find it overwhelming just to keep up with the number of frameworks and new stuff coming out! This makes our job, as front-end developers even more complicated as we need to take decisions by weighing the pros-and-cons of frameworks!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--B1avG34J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/630/1%2A2hhfV2if5UsW363P7cqSCA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--B1avG34J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/630/1%2A2hhfV2if5UsW363P7cqSCA.jpeg" alt="A framework comparison matrix by reactjsconsulting.com" width="630" height="354"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A framework comparison matrix by &lt;a href="https://www.reactjsconsulting.com/"&gt;reactjsconsulting.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see above, NextJs checks most of the boxes in comparison with other frameworks!&lt;/p&gt;


&lt;blockquote class="ltag__twitter-tweet"&gt;
      &lt;div class="ltag__twitter-tweet__media"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZQ_oBzdU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/media/FVtX_PwXwAAIElX.jpg" alt="unknown tweet media content"&gt;
      &lt;/div&gt;

  &lt;div class="ltag__twitter-tweet__main"&gt;
    &lt;div class="ltag__twitter-tweet__header"&gt;
      &lt;img class="ltag__twitter-tweet__profile-image" src="https://res.cloudinary.com/practicaldev/image/fetch/s--6imGwZGk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://pbs.twimg.com/profile_images/1525874017630035970/veQQouGw_normal.jpg" alt="Cory House profile image"&gt;
      &lt;div class="ltag__twitter-tweet__full-name"&gt;
        Cory House
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__username"&gt;
        @housecor
      &lt;/div&gt;
      &lt;div class="ltag__twitter-tweet__twitter-logo"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ir1kO05j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-f95605061196010f91e64806688390eb1a4dbc9e913682e043eb8b1e06ca484f.svg" alt="twitter logo"&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__body"&gt;
      Here are 7 ways to create a React app in 2022. This feature matrix shows some key differences at a glance.&lt;br&gt;&lt;br&gt;List includes:&lt;br&gt;&lt;a href="https://twitter.com/vite_js"&gt;@vite_js&lt;/a&gt; &lt;br&gt;&lt;a href="https://twitter.com/nextjs"&gt;@nextjs&lt;/a&gt; &lt;br&gt;&lt;a href="https://twitter.com/remix_run"&gt;@remix_run&lt;/a&gt; &lt;br&gt;&lt;a href="https://twitter.com/GatsbyJS"&gt;@GatsbyJS&lt;/a&gt; &lt;br&gt;&lt;a href="https://twitter.com/RedwoodJS"&gt;@RedwoodJS&lt;/a&gt; &lt;br&gt;&lt;a href="https://twitter.com/ShopifyDevs"&gt;@ShopifyDevs&lt;/a&gt; Hydrogen&lt;br&gt;&lt;br&gt;&lt;a href="https://twitter.com/hashtag/react"&gt;#react&lt;/a&gt; 
    &lt;/div&gt;
    &lt;div class="ltag__twitter-tweet__date"&gt;
      16:24 PM - 20 Jun 2022
    &lt;/div&gt;


    &lt;div class="ltag__twitter-tweet__actions"&gt;
      &lt;a href="https://twitter.com/intent/tweet?in_reply_to=1538920643571458048" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fFnoeFxk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-reply-action-238fe0a37991706a6880ed13941c3efd6b371e4aefe288fe8e0db85250708bc4.svg" alt="Twitter reply action"&gt;
      &lt;/a&gt;
      &lt;a href="https://twitter.com/intent/retweet?tweet_id=1538920643571458048" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--k6dcrOn8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-retweet-action-632c83532a4e7de573c5c08dbb090ee18b348b13e2793175fea914827bc42046.svg" alt="Twitter retweet action"&gt;
      &lt;/a&gt;
      &lt;a href="https://twitter.com/intent/like?tweet_id=1538920643571458048" class="ltag__twitter-tweet__actions__button"&gt;
        &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SRQc9lOp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/twitter-like-action-1ea89f4b87c7d37465b0eb78d51fcb7fe6c03a089805d7ea014ba71365be5171.svg" alt="Twitter like action"&gt;
      &lt;/a&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/blockquote&gt;


&lt;p&gt;A tweet thread by &lt;a href="https://twitter.com/housecor"&gt;Cory House&lt;/a&gt; for comparing frameworks&lt;/p&gt;

&lt;p&gt;I’ll go through some of the features of NextJs in brief to give you an idea of what’s in store for you if you give NextJs a shot! I will not go into detail in this post as I am planning to cover topics from NextJs in detail in my upcoming blog posts!&lt;/p&gt;

&lt;h2&gt;
  
  
  Developer Experience &amp;amp; Community
&lt;/h2&gt;

&lt;p&gt;I have created a project in NextJs and have developed multiple enterprise level React projects. There are certain things that I liked about NextJs and on some I’ll pick React. But to be very honest, they both have great documentations. The developer experience is not taking a hit and one compliments the other.&lt;/p&gt;

&lt;p&gt;The speed of coding and the ease of coding — both are great! NextJs has gained popularity in the last couple of months, if not years and has seen a very closely knit community!&lt;/p&gt;

&lt;p&gt;Join the discord community for NextJs &lt;a href="https://discord.com/invite/nextjs"&gt;here&lt;/a&gt; with 40,356 members. The community is active and helpful. NextJs also boasts some great GitHub stats as well:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Forks: 18.9K&lt;/li&gt;
&lt;li&gt; Stars: 88.4K&lt;/li&gt;
&lt;li&gt; Commits: 11.5K&lt;/li&gt;
&lt;li&gt; Contributors: 2K&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Community:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;a href="https://discord.com/invite/nextjs"&gt;Discord&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; &lt;a href="https://www.reactiflux.com/"&gt;Reactiflux on Discord&lt;/a&gt; — has a NextJs channel&lt;/li&gt;
&lt;li&gt; &lt;a href="https://www.reddit.com/r/nextjs/"&gt;Reddit&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can read the developer experience in detail &lt;a href="https://blog.logrocket.com/next-js-vs-react-developer-experience/#how-nextjs-different-react"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Performance
&lt;/h2&gt;

&lt;p&gt;Web apps built using NextJs are extremely fast because the pages are already pre-rendered on the server before reaching the client. This is the underlying principle for Static Site Generation (SSG) or Server Side Rendering (SSR) — both features of NextJs.&lt;/p&gt;

&lt;p&gt;In SSG, the page is generated during build-time and not when the client requests for it. This static page is then re-used for every incoming requests from a static server like CDN (Content Delivery Network) making your apps super-fast!&lt;/p&gt;

&lt;p&gt;The main difference is in the underlying architecture. NextJs runs on server while React apps like Create-React-App (CRA) runs on client’s browsers. This burdens the client-side to not only download heavy bundles but also render them using the complete V8 engine (Chrome’s JS Engine) as all that downloaded code is NodeJs code.&lt;/p&gt;

&lt;p&gt;One thumb-rule to always keep in mind is that HTML is faster than JavaScript!&lt;/p&gt;

&lt;p&gt;The performance of the apps also shoots because of multiple in-built features like Image Optimization where the images are pre-processed in the best formats for web apps i.e &lt;a href="https://www.manuelkruisz.com/blog/posts/image-optimization-in-nextjs"&gt;WebP&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;SSR on the other hand is responsible for data-fetching and rendering at request time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Better Search Engine Optimization
&lt;/h2&gt;

&lt;p&gt;React apps are Single Page Applications or SPA. They are by nature bad at Search Engine Optimization or SEO. NextJs introduces Server Side Rendering or SSR. SSR is preparing the content of the web page on the server and not on the client.&lt;/p&gt;

&lt;p&gt;The SSR is SEO friendly. SPA’s in general are not SEO friendly. This is because SPAs are hard to crawl by Googlebot and hence is difficult to render content for SEO purposes. A study has proven that the new SPA’s are not being crawled by search engines like Google properly.&lt;/p&gt;

&lt;p&gt;The SPA’s take some time to print the content on the page, but by then the &lt;a href="https://developers.google.com/search/docs/beginner/intro-indexing"&gt;Googlebot (Google’s SEO crawler)&lt;/a&gt; is already done with its work. You can read more about SEO in SPAs &lt;a href="https://proxify.io/articles/single-page-app-spa-seo#1-javascript-code-should-run-fast-and-flawless"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What happens when you use React without server-side rendering is that the crawler halts on the very first page because it can’t see any hyperlinks to follow. It sends the page to the indexer, which then has to render the page and extracts the hyperlinks, which will then be added to the crawler’s queue. Then the crawler will eventually crawl the next set of pages, and again will stop there because all the links are invisible until the JavaScript is rendered. So it has to wait for the indexer to come back with a new set of URLs to crawl. Etc.&lt;/p&gt;

&lt;p&gt;It makes the crawl process incredibly slow and inefficient. And that is why websites built on React (and similar JavaScript platforms) perform worse in Google than websites that primarily serve plain HTML to the crawler. The latter type of website will be crawled much more efficiently; plain HTML websites can be crawled very efficiently, newly added and changed content will be crawled and indexed much quicker, and Google is much better able to evaluate the crawl priority of individual pages on such websites.&lt;br&gt;&lt;br&gt;
-&lt;/p&gt;

&lt;p&gt;in &lt;a href="https://medium.com/free-code-camp/seo-vs-react-is-it-neccessary-to-render-react-pages-in-the-backend-74ce5015c0c9"&gt;SEO vs. React: Web Crawlers are Smarter Than You Think&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When the app is not an SSR app, the search engine crawler just sees the root &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; where the app will be rendered once the JS is downloaded by the browser. Then it has to show a loading state by the time API hit is in progress and is getting the data. This adds to the delay on the user side.&lt;/p&gt;

&lt;p&gt;In SSR, the page is completely ready to be shown on the front-end from the go! It allows us to pre-render React pages and components on a server.&lt;/p&gt;

&lt;p&gt;You can do it on the client side using &lt;a href="https://reactjs.org/docs/react-dom-server.html"&gt;ReactServerDOM&lt;/a&gt;. It can be done in ReactJS as well, but it requires additional effort and is a bit complex to get it going. On the other hand, NextJs has it in-built. Automatic page re-rendering is something that is great for SEO and initial load.&lt;/p&gt;

&lt;p&gt;The search engine sees what are users looking at when SSR is in place. This is not the case when an application is created using ReactJs only. Because of SSR, the users have a better user experience (UX) as there are no flickering or loading states. It blends client-side to server side. Fetch data on the server and render finished pages.&lt;/p&gt;

&lt;h2&gt;
  
  
  File Based Routing in NextJs
&lt;/h2&gt;

&lt;p&gt;NextJS defines pages and routes with files and folders instead of code.&lt;/p&gt;

&lt;p&gt;In React, we have to use an external routing library (&lt;a href="https://reactrouter.com/"&gt;react-router-dom&lt;/a&gt;) to implement “&lt;strong&gt;in-page&lt;/strong&gt;” routing. For every route added to the list, we have a corresponding page too.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kmLNldru--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/630/1%2AMn76JNe6vum8G-dpYultaA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kmLNldru--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/630/1%2AMn76JNe6vum8G-dpYultaA.png" alt="For every route added to the list, we have a corresponding page too." width="630" height="379"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Routing in ReactJs&lt;/p&gt;

&lt;p&gt;In NextJs, you have a dedicated folder &lt;strong&gt;&lt;em&gt;pages&lt;/em&gt;&lt;/strong&gt; and inside that the order of the files and folders defines the routing of the NextJs app. The structure of the &lt;strong&gt;&lt;em&gt;pages&lt;/em&gt;&lt;/strong&gt; folder defines the paths and routes the app supports. It is less code, less work, and highly understandable. It mimics the way we had old static sites (index.html/about.html/contact.html)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--b9bmvpUx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/630/1%2AU7xRtvQqgcw9A8oLnbTlpw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--b9bmvpUx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/630/1%2AU7xRtvQqgcw9A8oLnbTlpw.png" alt="The structure of the pages folder defines the paths and routes the app supports." width="630" height="289"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Routing in NextJs apps&lt;/p&gt;

&lt;p&gt;As you can see, the “&lt;strong&gt;pages&lt;/strong&gt;” folder has a sub-folder “&lt;strong&gt;news&lt;/strong&gt;”. The news folder has &lt;strong&gt;“index.js”&lt;/strong&gt; file and a &lt;strong&gt;[newsId].js&lt;/strong&gt; file.&lt;/p&gt;

&lt;p&gt;For routing:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;index.js&lt;/em&gt;&lt;/strong&gt; will create a route &lt;strong&gt;/news&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;[newsId].js&lt;/em&gt;&lt;/strong&gt; will create a route &lt;strong&gt;/news/:newsId&lt;/strong&gt; where newsId is the route parameter.&lt;/p&gt;

&lt;p&gt;A nested folder structure basically means nested routes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configurations for NextJs
&lt;/h2&gt;

&lt;p&gt;React recommends using Create-React-App or CRA for its projects, but there are certain things that are not required out-of-the-box for small-scale React apps. NextJs is a bit opinionated and helps developers work a certain way.&lt;/p&gt;

&lt;p&gt;React doesn’t offer great configurability, unless you &lt;a href="https://create-react-app.dev/docs/available-scripts/#npm-run-eject"&gt;eject the app&lt;/a&gt; from CRA. On the other hand, everything is configurable in NextJs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Full Stack Capabilities of NextJs
&lt;/h2&gt;

&lt;p&gt;Below are some of the capabilities added to your project when you choose to go with NextJs:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Can add backend (server-side) code to Next/React apps&lt;/li&gt;
&lt;li&gt; Storing data, getting data, authentication etc. can be added to your NextJs project&lt;/li&gt;
&lt;li&gt; No different REST api project. One project can have both.&lt;/li&gt;
&lt;li&gt; If we see the app that is created by the NextJs CLI command, it does not gives us &lt;code&gt;index.js&lt;/code&gt;file, as SSR is in-built. NextJS allows us to determine WHEN a page should be pre-rendered.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can learn more about why you should not ignore NextJs here:&lt;/p&gt;

&lt;p&gt;Why I Don’t Use React JS Anymore! React JS vs Next JS by &lt;a href="https://twitter.com/codedamncom"&gt;Codedamn&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/_otTkX0RApI"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ni31mE9z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://img.youtube.com/vi/_otTkX0RApI/hqdefault.jpg" alt="Watch the video" width="480" height="360"&gt;&lt;/a&gt;  &lt;/p&gt;




&lt;p&gt;Thanks for reading ❤&lt;/p&gt;

&lt;p&gt;If this blog was able to bring value, please follow me &lt;a href="https://dev.to/adityatyagi"&gt;here&lt;/a&gt;! Your support keeps me driven!&lt;/p&gt;

&lt;p&gt;Originally published on &lt;a href="https://adityatyagi.com/index.php/2022/06/22/why-nextjs-should-not-be-ignored/"&gt;adityatyagi.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Want to connect?&lt;br&gt;
Follow me on &lt;a href="https://twitter.com/secondbestcoder"&gt;Twitter&lt;/a&gt; and &lt;a href="https://www.linkedin.com/in/aditya-tyagi-03b4189a/"&gt;LinkedIn&lt;/a&gt; or reach out in the comments below!&lt;/p&gt;

&lt;p&gt;My name is Aditya. I am a Senior Software Engineer - II (Frontend). I blog about web development!&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
    </item>
    <item>
      <title>How to debug a React App</title>
      <dc:creator>Aditya Tyagi</dc:creator>
      <pubDate>Mon, 27 Jun 2022 05:49:19 +0000</pubDate>
      <link>https://forem.com/adityatyagi/how-to-debug-a-react-app-4gm0</link>
      <guid>https://forem.com/adityatyagi/how-to-debug-a-react-app-4gm0</guid>
      <description>&lt;h2&gt;
  
  
  Debug React apps like a pro!
&lt;/h2&gt;

&lt;p&gt;While working as a front-end developer for last 4+ years, one thing I have witnessed junior developers constantly struggle with is proper debugging skills. I believe debugging is a skill and developers who are good at it can bring immense value. As with any other skill, one can learn debugging. All one needs to understand the tools at one’s disposal to debug React app.&lt;/p&gt;

&lt;p&gt;This little handy guide is not only about debugging React apps, but any JavaScript based app. Some principles here are generic to programming while the others are targeted towards debugging JavaScript applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Re-read the error messages
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Caog8G5_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1040/1%2AvbSlIJHd0aC923hKcHM1nA.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Caog8G5_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1040/1%2AvbSlIJHd0aC923hKcHM1nA.jpeg" alt="Old lady reading meme" width="578" height="432"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Old lady reading meme&lt;/p&gt;

&lt;p&gt;Debugging is no rocket science. Sometimes developers just panic and what could have been resolved within 5 minutes, take 30. I say this because I have spent 30 minutes.&lt;/p&gt;

&lt;p&gt;The maintainers of programming language, library and frameworks have worked hard to make error messages self explanatory. Therefore, when you debug, the very first step is to read the error message and then re-read it.&lt;/p&gt;

&lt;p&gt;I want to lay emphasis on &lt;strong&gt;re-reading&lt;/strong&gt; the error message because usually the solution is screaming at you. Skimming through the error message is not what you should do. Read it. Slowly. Understand it and then move forward.&lt;/p&gt;

&lt;p&gt;The error message lays out the entire &lt;a href="https://www.freecodecamp.org/news/understanding-the-javascript-call-stack-861e41ae61d4/"&gt;call-stack&lt;/a&gt;. How the error bubbled up and at which line number the error was thrown, everything is out there. Going through the error call-stack will help you analyze the code flow and warnings. Reading and making sense of the error call-stack is an essential skill a developer must work on as it can help one work with legacy code-bases which are an amalgamation of hundreds of files and thousands of lines of code!&lt;/p&gt;

&lt;p&gt;For example, if we have a &lt;code&gt;button&lt;/code&gt; element which calls a function &lt;code&gt;showAlert&lt;/code&gt; but we forget to define such a function, the app will throw an error.&lt;/p&gt;

&lt;p&gt;React is kind enough to show the error at two places:&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The dev-tools&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The console of the dev-tools of all the browsers will show this error.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--g8D-2Inc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1260/1%2AcATMSKixR9z0p0UDjFuJ7Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--g8D-2Inc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1260/1%2AcATMSKixR9z0p0UDjFuJ7Q.png" alt="React throwing error in dev-tools console" width="768" height="260"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;React throwing error in dev-tools console&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The web page&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;React ensures that the error is more human readable on the web-page. You can clearly see below where the error was thrown and hence this will be the starting point to debug React app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--itStNexO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1188/1%2AcH7cAEyX9m6VSlxxyQFzJg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--itStNexO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1188/1%2AcH7cAEyX9m6VSlxxyQFzJg.png" alt="React error message on the web-page" width="660" height="446"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;React error message on the web-page&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I cannot stress enough on how important it is to read and then re-read the error message. You need to understand it completely before you even start exploring Stack Overflow and Google.&lt;/p&gt;

&lt;p&gt;One thing that I have experienced is that Google is pretty good at its job as a search engine. It will give you back the results for the question you asked. Now if you have mis-understood the error and are trying to ask Google wrong questions, it will give you answers which will take you down the rabbit hole of copy-pasting different solutions until something works!&lt;/p&gt;

&lt;h2&gt;
  
  
  Learn to use your IDE
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---HH5ZQ4b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1260/1%2AMj2_i7eXnacPTuCXQwXuZg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---HH5ZQ4b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1260/1%2AMj2_i7eXnacPTuCXQwXuZg.png" alt="Queen Elizabeth II insists on cutting cake with a sword at G7 event" width="880" height="494"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Queen Elizabeth II insists on cutting cake with a sword at G7 event&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Today, Integrated Development Environments (IDE) are very powerful. They hint you what’s wrong right in your code, even before you &lt;strong&gt;Save&lt;/strong&gt; it. Not understanding the tools you have slows you down and makes you inefficient at your job. Understanding how your IDE works is so important that programmers and content creators out there have created full fledged courses on the very topic. Some of my favourites around VS Code are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;a href="https://www.youtube.com/watch?v=VqCgcpAypFQ"&gt;Visual Studio Code Tutorial for Beginners — Introduction&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; &lt;a href="https://www.youtube.com/watch?v=WPqXP_kLzpo"&gt;Visual Studio Code Crash Course&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can use VS Code extensions/plugins for effective debugging as well. For JavaScript, plugins like &lt;a href="https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint"&gt;ESLint by Microsoft&lt;/a&gt; are a must. If you want your project to ship with an ES Lint, then you can do that as well by using a &lt;a href="https://www.digitalocean.com/community/tutorials/linting-and-formatting-with-eslint-in-vs-code"&gt;NPM library&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you find yourself relying too much on plugins and external NPM libraries, please remember this:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;To a man with a hammer, everything looks like a nail.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;– &lt;strong&gt;Mark Twain&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;React apps with proper ESLinting and IDE, will even fail to compile, eventually throwing the error in the terminal:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8rCbftE2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1013/0%2Aw9YNsXmMCAMekcO8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8rCbftE2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1013/0%2Aw9YNsXmMCAMekcO8.png" alt="React app failing to compile due to undefined variable" width="563" height="245"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;React app failing to compile due to undefined variable&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Working with Breakpoints
&lt;/h2&gt;

&lt;p&gt;This is one of the most helpful and yet one of the most under-utilized piece of debugging tool developers use. In software development, a breakpoint is an intentional stopping or pausing place in a program which is added to debug the code. One can work with breakpoints in multiple ways, but the two most prominent are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Breakpoints via Dev Tools in the browser&lt;/li&gt;
&lt;li&gt; Using the debugger in the IDE like VSCode&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Breakpoints via Dev Tools in the browser
&lt;/h2&gt;

&lt;p&gt;Open the Chrome dev tools. I am using Google Chrome as my primary browser, but dev tools are present in all browsers. Go to &lt;code&gt;Sources&lt;/code&gt;. Go to the &lt;code&gt;Page&lt;/code&gt; tab and the &lt;code&gt;localhost:3000&lt;/code&gt; dropdown. There you’ll see all your files and you can add debuggers to your JS files right then and there.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lWpUf_cI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/792/0%2A1wKu1ZkfERevFfxt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lWpUf_cI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/792/0%2A1wKu1ZkfERevFfxt.png" alt="Location of all the files of your app in dev tools" width="440" height="735"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Location of all the files of your app in dev tools&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Here, I’ll be adding a breakpoint on the &lt;code&gt;testDebugger&lt;/code&gt; function, just before it consoles the value of the variable &lt;code&gt;a&lt;/code&gt;. As soon as you click the button, it will stop the execution of the app on the very breakpoint. You can then use the panel of buttons on the top-right corner (in Red box) to move around the function.&lt;/p&gt;

&lt;p&gt;For a more detailed tutorial, you can refer &lt;a href="https://www.youtube.com/watch?v=H0XScE08hy8"&gt;Debugging JavaScript — Chrome DevTools 101&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you look closely below, you’ll be able to see all the breakpoints, the call stack and the file on the left panel.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GaQmgGp4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1260/0%2An8D4R7XtYDLcTHQ-.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GaQmgGp4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1260/0%2An8D4R7XtYDLcTHQ-.png" alt="Debugger in Chrome Dev Tools to debug React app" width="880" height="369"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Debugger in Chrome Dev Tools to debug React app&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Using the debugger in the IDE like VSCode
&lt;/h2&gt;

&lt;p&gt;Today the IDEs come with in-built debuggers. You do not have to rely on the dev tools in the browser. The workings of the VSCode debugger is similar to debugger in dev tools. To understand it, you can refer the following two resources:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;a href="https://www.youtube.com/watch?v=tC91t9OvVHA"&gt;The New Way To Debug JavaScript in VS Code — No Extension Required&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; &lt;a href="https://www.youtube.com/watch?v=7qZBwhSlfOo"&gt;How to Use a Debugger — Debugger Tutorial&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This is how the debugger will look like in the VSCode:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Yellow: Debugger&lt;/li&gt;
&lt;li&gt; Blue: The breakpoint&lt;/li&gt;
&lt;li&gt; Pink: List of all breakpoints&lt;/li&gt;
&lt;li&gt; Red: Variables&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Yuepx1hk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1260/0%2AFE2H3e7F4JBUMbwr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Yuepx1hk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1260/0%2AFE2H3e7F4JBUMbwr.png" alt="VSCode Debugger in action" width="880" height="474"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;VSCode Debugger in action&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  React Developer Tools
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en"&gt;React Developer Tools&lt;/a&gt; is a browser extension that helps to debug React apps. It is present in other browsers as well, but I’ll recommend you to get comfortable with the Chrome extension. This extension makes the process to debug React app easy and consistent!&lt;/p&gt;

&lt;p&gt;From the official docs:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;React Developer Tools is a Chrome DevTools extension for the open-source React JavaScript library. It allows you to inspect the React component hierarchies in the Chrome Developer Tools.&lt;/p&gt;

&lt;p&gt;– &lt;a href="https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en"&gt;React Developer Tools (Chrome Web Store)&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once you enable this extension, you’ll see two new additions to your dev tools:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Components&lt;/li&gt;
&lt;li&gt; Profiler&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The Components will show only React components and not the entire DOM like the &lt;code&gt;Elements&lt;/code&gt; tab shows.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WWChFyAU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1260/0%2AheFAsPmMMfDUcAFJ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WWChFyAU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1260/0%2AheFAsPmMMfDUcAFJ.png" alt="Demo of React Dev Tools chrome extension" width="790" height="359"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Demo of React Dev Tools chrome extension&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You can learn here with examples:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;a href="https://www.youtube.com/watch?v=rb1GWqCJid4"&gt;Intro to React Dev Tools&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; &lt;a href="https://www.youtube.com/watch?v=4U37IRrt_zQ"&gt;React Developer Tools | Components &amp;amp; Profiler&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Reach out for help!
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jizWJrxX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1260/0%2ADA3o0puX2q1S0Zib.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jizWJrxX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/1260/0%2ADA3o0puX2q1S0Zib.jpeg" alt="Baby Yoda Meme" width="708" height="352"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Baby Yoda Meme&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Sometimes the error message is cryptic or we cannot make sense of it. Even after struggling to find a working solution, trying everything from Stack Overflow and doubting your entire life, you aren’t able to debug. In such cases, pause. Take a deep breath and ask for help!&lt;/p&gt;

&lt;p&gt;If you are a junior developer working in a company, then reach out to the senior developers. Sometimes all you need is a fresh perspective to the whole situation. If you are a self-taught developer and are building something all by yourself (kudos to you!), reach out to the very welcoming developer community on Twitter and Discord. The community, combined with &lt;a href="https://adityatyagi.com/index.php/2021/05/15/one-must-have-skill-as-a-software-engineer/"&gt;this one skill&lt;/a&gt; can help you debug any bug!&lt;/p&gt;

&lt;p&gt;Few developers know, the programming community on Discord is amazing! All you have to do is ask the relevant question in the relevant channel and you’ll get the solution. If not, the solution, there will be 1 kind soul to help you move forward with your quest to debug React app.&lt;/p&gt;

&lt;p&gt;Some of the Discord communities I follow:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;a href="https://discord.gg/rTnFySNq"&gt;Reactiflux&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; &lt;a href="https://academind.com/community"&gt;Academind&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; &lt;a href="https://discord.com/invite/EVsW3mj"&gt;Blue Collar Coder&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you are still stuck, call it a day. Sleep on it and tackle it with a fresh mind the next day. You’ll be surprised how often the answers are just in front of us.&lt;/p&gt;

&lt;p&gt;Thank you for your time. I hope I was able to bring value.&lt;/p&gt;

&lt;p&gt;I’m reachable on some social media channels, so consider checking me on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;a href="https://twitter.com/secondbestcoder"&gt;&lt;strong&gt;Twitter&lt;/strong&gt;&lt;/a&gt; especially if you’re into programming and software development in general.&lt;/li&gt;
&lt;li&gt;  &lt;a href="https://www.linkedin.com/in/aditya-tyagi-03b4189a/"&gt;&lt;strong&gt;LinkedIn&lt;/strong&gt;&lt;/a&gt; if you want to get in touch for some collaboration opportunity.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>react</category>
      <category>webdev</category>
    </item>
    <item>
      <title>4+ years of cracking technical interviews</title>
      <dc:creator>Aditya Tyagi</dc:creator>
      <pubDate>Fri, 24 Jun 2022 15:06:32 +0000</pubDate>
      <link>https://forem.com/adityatyagi/4-years-of-cracking-technical-interviews-24o0</link>
      <guid>https://forem.com/adityatyagi/4-years-of-cracking-technical-interviews-24o0</guid>
      <description>&lt;h2&gt;
  
  
  A framework to solve any technical interview question
&lt;/h2&gt;

&lt;p&gt;I have been working as a Senior Software Engineer — II (Frontend) from quite some time now and have been on both sides of the interview table. I have given a lot of technical interviews and have taken the same amount (if not more).&lt;/p&gt;

&lt;p&gt;From white-boarding the data structures and algorithmic questions to pair-programming with my interviewer, its been an eye-opening &amp;amp; humbling experience of how draining these interviews can get!&lt;/p&gt;

&lt;p&gt;Therefore, over these last 4 years, I have come up with this little framework that has helped me crack multiple roles in various tech companies.&lt;/p&gt;

&lt;p&gt;There are 5 major parts to this problem solving approach&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Understand the problem&lt;/li&gt;
&lt;li&gt; Explore concrete examples&lt;/li&gt;
&lt;li&gt; Break it down&lt;/li&gt;
&lt;li&gt; Solve or Simplify&lt;/li&gt;
&lt;li&gt; Look back and refactor&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let’s go through each one of them in detail:&lt;/p&gt;

&lt;h2&gt;
  
  
  Understand The Problem
&lt;/h2&gt;

&lt;p&gt;As soon as you are given the question, do not start slapping the keyboard and declaring variables. Breathe. Read the question and then re-read it.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“It is foolish to answer a question that you do not understand.”&lt;br&gt;&lt;br&gt;
- &lt;strong&gt;“How to Solve it” by George Polya&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then, try to note down answers to the following questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Can I restate the problem in my own words?&lt;/li&gt;
&lt;li&gt; What are the inputs that go into the problem? This is the place where you can ask the interviewer for the edge cases with respect to inputs.&lt;/li&gt;
&lt;li&gt; What are the outputs that should come from the solution to the problem?&lt;/li&gt;
&lt;li&gt; Can the outputs be determined from the inputs? In other words, do I have enough information to solve the problem?&lt;/li&gt;
&lt;li&gt; How should I label the important pieces of data (variables declaration) that are part of the problem?&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Explore Concrete Examples
&lt;/h2&gt;

&lt;p&gt;Coming up with examples can help you understand the problem better. These examples also provide sanity checks that your solution works the way it should work.&lt;/p&gt;

&lt;p&gt;This can help you to understand the nature of inputs and outputs more clearly and reveal any corner/edge cases.&lt;/p&gt;

&lt;p&gt;These are nothing but user stories or unit tests for the problem statements.&lt;/p&gt;

&lt;p&gt;For example, consider this question:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Write a function&lt;/em&gt; &lt;strong&gt;&lt;em&gt;charCount&lt;/em&gt;&lt;/strong&gt; &lt;em&gt;which takes a string and returns count of each character in the string?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The examples of this can be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;charCount("aaa");        // Output -&amp;gt; {a:3}
charCount("hello");      // Output -&amp;gt; {h:1, e: 1, l: 2, o: 1}

// Check examples for empty inputs
charCount(""); // Output -&amp;gt; { }

// Check examples for invalid inputs
charCount(1234);         // Output -&amp;gt; { } 

// Check examples for invalid inputs
charCount(false);        // Output -&amp;gt; { }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Break It Down
&lt;/h2&gt;

&lt;p&gt;This is one of the most important, yet most ignored/skipped step. You need to keep the interviewer on the same page throughout your problem solving journey.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Communicate while breaking the problem down&lt;/li&gt;
&lt;li&gt; Ask questions like &lt;strong&gt;“Does this sound good?”&lt;/strong&gt; or &lt;strong&gt;“Am I going the right path?”&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt; Write comments and not the actual code.&lt;/li&gt;
&lt;li&gt; Explicitly write out the steps you need to take. You need to just write the pseudo-code or steps that you will be taking to solve the problem.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The process of breaking down the problem compels you to think about the code you will write before you write it and helps you catch any lingering conceptual issues or misunderstandings. This is an important step to follow and will help you immensely before you dive in and have to worry about the details like syntax of the code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Solve or Simplify
&lt;/h2&gt;

&lt;p&gt;By the time you arrive at this step, you should already have the pseudo-code written. All you have to do is just write the code now.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Defeat Them in Detail: The Divide and Conquer Strategy.&lt;br&gt;&lt;br&gt;
Look at the parts and determine how to control the individual parts, create dissension and leverage it.&lt;br&gt;&lt;br&gt;
- &lt;strong&gt;Robert Greene&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you are &lt;strong&gt;“stuck”&lt;/strong&gt; and are not able to proceed, do not worry. Try to break down the problem into smaller problems. Try to identify a simpler problem and then solve it. This will also give you a psychological sense of achievement and thus help you proceed with the problem “emotionally”.&lt;/p&gt;

&lt;p&gt;Yes, emotionally. There have been times when I started sweating, mouth went dry while solving a DSA question. One has to be in a balanced mental state to come down to a solution as this is a mental game!&lt;/p&gt;

&lt;p&gt;To simplify:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Find the core difficulty in what you are trying to do&lt;/li&gt;
&lt;li&gt; Temporarily &lt;strong&gt;ignore&lt;/strong&gt; the difficulty&lt;/li&gt;
&lt;li&gt; Write a simplified solution&lt;/li&gt;
&lt;li&gt; Then incorporate that difficulty back in&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Look Back And Refactor
&lt;/h2&gt;

&lt;p&gt;This is the last piece, but the piece of this framework that will distinguish between a great candidate from a good one!&lt;/p&gt;

&lt;p&gt;For refactoring, ask yourself:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Can I check the result?&lt;/li&gt;
&lt;li&gt; Can I derive the result differently?&lt;/li&gt;
&lt;li&gt; Can I understand the solution at a glance? Is the solution readable?&lt;/li&gt;
&lt;li&gt; Can I use the same method for some other problem?&lt;/li&gt;
&lt;li&gt; Can I improve the performance of the solution?&lt;/li&gt;
&lt;li&gt; Can I think of other ways to refactor?&lt;/li&gt;
&lt;li&gt; How have other people solved the same problem? This is something that comes in “Looking Back” area of the framework!&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;All the very best for your interview (if you have any coming up).&lt;/p&gt;




&lt;p&gt;Thanks for reading ❤&lt;/p&gt;

&lt;p&gt;If this blog was able to bring value, please follow me on Medium! Your support keeps me driven!&lt;/p&gt;

&lt;p&gt;Originally published on &lt;a href="https://adityatyagi.com/index.php/2022/06/12/4-years-of-cracking-technical-interviews/"&gt;adityatyagi.com&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Want to connect?
&lt;/h3&gt;

&lt;p&gt;Follow me on &lt;a href="https://twitter.com/secondbestcoder"&gt;Twitter&lt;/a&gt; and &lt;a href="https://www.linkedin.com/in/aditya-tyagi-03b4189a/"&gt;LinkedIn&lt;/a&gt; or reach out in the comments below!&lt;/p&gt;

&lt;p&gt;My name is Aditya. I am a Senior Software Engineer - II (Frontend). I blog about &lt;strong&gt;web development&lt;/strong&gt;!&lt;/p&gt;

</description>
      <category>interview</category>
      <category>programming</category>
      <category>career</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>How to Write Cleaner React code</title>
      <dc:creator>Aditya Tyagi</dc:creator>
      <pubDate>Tue, 08 Feb 2022 10:50:29 +0000</pubDate>
      <link>https://forem.com/adityatyagi/how-to-write-cleaner-react-code-3af5</link>
      <guid>https://forem.com/adityatyagi/how-to-write-cleaner-react-code-3af5</guid>
      <description>&lt;p&gt;After getting my hands dirty with over 10 production level React projects, one thing that was consistent with most of them was the use of unnecessary HTML elements/tags. It is highly important that your code is easier to maintain, write, read and debug. As a thumb rule, you can follow this to identify if your code follows clean code guidelines:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--acYsafvQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642774860439/E1kyVf1Ai.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--acYsafvQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642774860439/E1kyVf1Ai.jpeg" alt="Clean Code in React by Aditya Tyagi.jpeg" width="640" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These tags were polluting the DOM for no reason at all. But they introduced these tags to overcome the drawback of JSX in React. The drawback is that JSX should always return a single root HTML element.&lt;br&gt;
In other words, this is invalid JSX:&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="c1"&gt;// The parenthesis helps to write multi-line HTML&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;

  &lt;span class="c1"&gt;// 1st div block&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;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello!&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;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Good to see you here.&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&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="c1"&gt;// 2st div block&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;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Sibling element&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;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;I will break JSX element&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Because of this drawback, many developers add &lt;code&gt;div&lt;/code&gt; tags to wrap enormous blocks of code. Hence, resolving the drawback of JSX.&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;

  &lt;span class="c1"&gt;// The wrapper&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;

      // 1st div block
      &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;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello!&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;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Good to see you here.&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&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;

      // 2st div block
      &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;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Sibling element&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;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;I will break JSX element&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&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;&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, this works for minor projects. I am guilty of going this route as well. Won’t lie. But then as I started working on gigantic React oriented projects, I found the DOM code filled with div tags throughout. This sooner or later resulted in a “div soup“&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hzCZFZMi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642774051982/1FqnIauWy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hzCZFZMi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642774051982/1FqnIauWy.png" alt="div soup in react.png" width="768" height="454"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a div soup?
&lt;/h2&gt;

&lt;p&gt;An example will make it much clearer than me slapping the keyboard to vomit out explanatory paragraphs!&lt;/p&gt;

&lt;p&gt;Consider this piece of 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;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="c1"&gt;// This div does nothing but wraps the two children&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;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;This is heading&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;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;This is a sub-heading&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result of this in the DOM will be:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NXEA5sqQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642774095042/O7gvgGVCD.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NXEA5sqQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642774095042/O7gvgGVCD.png" alt="DOM.png" width="300" height="104"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is a minor example. Real React apps are way more complex. You can have a deeply nested parent-children relationships between components. For example:&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;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="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;This is heading&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;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;This is a sub-heading&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&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="nc"&gt;Child1&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="nc"&gt;Child2&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="nc"&gt;Child3&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="nc"&gt;Child4&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="nc"&gt;Child3&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="nc"&gt;Child2&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="nc"&gt;Child1&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where the children are:&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="c1"&gt;// Every React JSX element inherently receives the "props" argument&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Child1&lt;/span&gt; &lt;span class="o"&gt;=&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="o"&gt;=&amp;gt;&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="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h3&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;I am child 1&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h3&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/* Anything that is passed between &amp;lt;Child1&amp;gt; and &amp;lt;/Child1&amp;gt; */&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="si"&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;children&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;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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Child2&lt;/span&gt; &lt;span class="o"&gt;=&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="o"&gt;=&amp;gt;&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="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h3&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;I am child 2&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h3&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;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&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;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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Child3&lt;/span&gt; &lt;span class="o"&gt;=&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="o"&gt;=&amp;gt;&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="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h3&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;I am child 3&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h3&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;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&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;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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Child4&lt;/span&gt; &lt;span class="o"&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="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;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h3&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;I am child 4&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h3&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will produce DOM:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nRTnTqbH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642774145165/5W0gK69Kr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nRTnTqbH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642774145165/5W0gK69Kr.png" alt="image-1.png" width="357" height="396"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you carefully check the generated DOM, you’ll see a ton of div tags which serves has no purpose but to wrap the code and overcome the JSX limitation. Eventually, this will cause a div soup.&lt;/p&gt;

&lt;p&gt;This can exponentially increase the time of debugging and hence can affect faster delivery and bug-fixes!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rZ5Y-hhO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642774161690/Pn-oF3ZHp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rZ5Y-hhO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642774161690/Pn-oF3ZHp.png" alt="Ratio-of-Time-Spent-Reading-Code-Versus-Writing.png" width="880" height="612"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Avoid a DIV soup
&lt;/h2&gt;

&lt;p&gt;Eagle-eyed readers must have noticed the solution in the problematic code itself. All we have to do is create a wrapper React component which returns the passed component without the &lt;code&gt;div&lt;/code&gt;&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="c1"&gt;// Wrapper component that returns any DOM element passed between &amp;lt;Wrapper&amp;gt; and &amp;lt;/Wrapper&amp;gt;&lt;/span&gt;
&lt;span class="c1"&gt;// The props inherently have the children property on it&lt;/span&gt;
&lt;span class="c1"&gt;// All react JSX elements should be Capitalized as a naming convention &lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Wrapper&lt;/span&gt; &lt;span class="o"&gt;=&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&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;children&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;Refactoring the previous 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="c1"&gt;// Every React JSX element inherently receives the "props" argument&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Child1&lt;/span&gt; &lt;span class="o"&gt;=&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Wrapper&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;h3&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;I am child 1&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h3&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/* Anything that is passed between &amp;lt;Child1&amp;gt; and &amp;lt;/Child1&amp;gt; */&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="si"&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;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Wrapper&lt;/span&gt;&lt;span class="p"&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;Child2&lt;/span&gt; &lt;span class="o"&gt;=&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Wrapper&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;h3&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;I am child 2&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h3&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;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Wrapper&lt;/span&gt;&lt;span class="p"&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;Child3&lt;/span&gt; &lt;span class="o"&gt;=&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Wrapper&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;h3&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;I am child 3&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h3&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;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Wrapper&lt;/span&gt;&lt;span class="p"&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;Child4&lt;/span&gt; &lt;span class="o"&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Wrapper&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;h3&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;I am child 4&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h3&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="nc"&gt;Wrapper&lt;/span&gt;&lt;span class="p"&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;and&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;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="nc"&gt;Wrapper&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;This is heading&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;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;This is a sub-heading&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&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="nc"&gt;Child1&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="nc"&gt;Child2&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="nc"&gt;Child3&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="nc"&gt;Child4&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="nc"&gt;Child3&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="nc"&gt;Child2&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="nc"&gt;Child1&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="nc"&gt;Wrapper&lt;/span&gt;&lt;span class="p"&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;This will remove the unnecessary &lt;code&gt;div&lt;/code&gt; tags and hence prevent the soup!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--oKXbHMFJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642774236440/tTD8r8GFA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--oKXbHMFJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642774236440/tTD8r8GFA.png" alt="Clean React Code.png" width="400" height="178"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  React Fragments
&lt;/h2&gt;

&lt;p&gt;It will be difficult and an added effort to introduce this Wrapper component in every React project, and we developers try to avoid exactly such situations.&lt;/p&gt;

&lt;p&gt;Introducing React Fragments.&lt;/p&gt;

&lt;p&gt;According to the official documentation:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A common pattern in React is for a component to return multiple elements. Fragments let you group a list of children without adding extra nodes to the DOM.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://reactjs.org/docs/fragments.html"&gt;ReactJs.org&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can do this in two ways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Using &lt;a href="https://reactjs.org/docs/fragments.html"&gt;&lt;code&gt;React.Fragment&lt;/code&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Using a &lt;a href="https://reactjs.org/docs/fragments.html#short-syntax"&gt;short syntax&lt;/a&gt; of &lt;code&gt;React.Fragment&lt;/code&gt; which is &lt;code&gt;&amp;lt;&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;/&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let me show you via our code above with this:&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;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="nc"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Fragment&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;This is heading&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;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;This is a sub-heading&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&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="nc"&gt;Child1&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="nc"&gt;Child2&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="nc"&gt;Child3&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="nc"&gt;Child4&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="nc"&gt;Child3&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="nc"&gt;Child2&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="nc"&gt;Child1&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="nc"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Fragment&lt;/span&gt;&lt;span class="p"&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;Using a short-hand is much better for lazy developers like me:&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;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&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;This is heading&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;h2&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;This is a sub-heading&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h2&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="nc"&gt;Child1&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="nc"&gt;Child2&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="nc"&gt;Child3&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="nc"&gt;Child4&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="nc"&gt;Child3&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="nc"&gt;Child2&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="nc"&gt;Child1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

    &lt;span class="p"&gt;&amp;lt;/&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 final code will look like this:&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Child1&lt;/span&gt; &lt;span class="o"&gt;=&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h3&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;I am child 1&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h3&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/* Anything that is passed between &amp;lt;Child1&amp;gt; and &amp;lt;/Child1&amp;gt; */&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="si"&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;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;/&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;Child2&lt;/span&gt; &lt;span class="o"&gt;=&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h3&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;I am child 2&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h3&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;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;/&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;Child3&lt;/span&gt; &lt;span class="o"&gt;=&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h3&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;I am child 3&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h3&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;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;/&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;Child4&lt;/span&gt; &lt;span class="o"&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="p"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h3&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;I am child 4&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h3&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;/&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;This will help you get the same results, avoiding the &lt;code&gt;div&lt;/code&gt; soup.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SxPPRUIy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642774432346/e13UuCEwtF.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SxPPRUIy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1642774432346/e13UuCEwtF.png" alt="Avoid div soup.png" width="300" height="170"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>react</category>
      <category>webdev</category>
    </item>
    <item>
      <title>How to be better at your software development job - A Guide</title>
      <dc:creator>Aditya Tyagi</dc:creator>
      <pubDate>Thu, 17 Sep 2020 17:04:38 +0000</pubDate>
      <link>https://forem.com/adityatyagi/how-to-be-better-at-your-software-development-job-a-guide-1e8e</link>
      <guid>https://forem.com/adityatyagi/how-to-be-better-at-your-software-development-job-a-guide-1e8e</guid>
      <description>&lt;p&gt;I have been working as a software engineer for the last 2 years now. I was lucky enough to land a job in an MNC (Multinational corporation) early on and currently working as a Frontend Engineer in my third job and second startup. During these years, I have been exposed to working on client-sites, in teams of all sizes (3-20 people), and various environments like in-office as well as remote!&lt;/p&gt;

&lt;p&gt;While working all these years, I came to a few conclusions to become better at your software development jobs. This is for everyone – people employed as software developers and developers who are preparing to land a job in the next couple of months. So, let’s begin…&lt;/p&gt;

&lt;h1&gt;
  
  
  Being Pro-Active
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WCQzryFz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/048uoahcj27141z7j5xs.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WCQzryFz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/048uoahcj27141z7j5xs.jpg" alt="HiRes (19)" width="880" height="560"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is no point of controlling fire when you could have prevented it in the first place. In other words, be pro-active. Now what that means?&lt;/p&gt;

&lt;p&gt;Being a pro-active developer means NOT delaying to convey your fuck-ups. That’s pretty much it. Now, these fuck-ups can be as small as an ugly git merge to as big as wrong estimations on a piece of work. When you are pro-active, it gives your team (and your manager) to put a contingency plan in place.&lt;/p&gt;

&lt;p&gt;Pro-active also means to convey the updates on your tasks, without being asked. Always consider your team members and managers to be super-busy and hence, try to convey them as much as you can, when you can. Keeping them in-loop will help you ensure everyone is on the same page. Yes, it will take some extra effort, but believe me, having everyone on the same page prior to a &lt;a href="https://www.scrum-institute.org/Daily_Scrum_Meeting.php"&gt;SCRUM Call&lt;/a&gt; is a boon.&lt;/p&gt;




&lt;h1&gt;
  
  
  Over Communication
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1MLO5kke--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/b4k01nn7up357mm33nd6.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1MLO5kke--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/b4k01nn7up357mm33nd6.jpg" alt="7-ways-to-communicate-customer-feedback-blog" width="880" height="352"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I am not one of those who think being an affluent speaker in a language like English makes you a superior developer. But, being understood, and conveying your point clearly in a message in one go is a super-power and that indeed makes you a superior developer.&lt;/p&gt;

&lt;p&gt;The latter is possible only when:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You are absolutely clear what you want to convey.&lt;/li&gt;
&lt;li&gt;You know how to frame a message that compliments that clarity of thought&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Over-communication is always better than zero or under communication (if that is even a word).&lt;/p&gt;

&lt;p&gt;Now, what do I mean by Over Communicating? It means stating the obvious. At times we withhold a piece of information on purpose just because we have a preconceived notion about other developer’s understanding. Refrain from practicing this. When you are working with humans, nothing is “obvious”. Ensure that the message is loud and clear and the fellow developer understood your message.&lt;/p&gt;

&lt;h2&gt;
  
  
  A tip:
&lt;/h2&gt;

&lt;p&gt;Whenever you are unsure about being on the same page, always request the fellow developer to explain your message to you (like you double-check the order while ordering in a restaurant by asking the waiter to repeat the order). That is how you’ll be 100% sure that your message has been conveyed successfully!&lt;/p&gt;

&lt;p&gt;Another domain where over-communicating helps is testing. When you are submitting a module to the testing team, ensure that you attach a list of things to test and explain the functionality/feature you built, saving tester the guess work! This also helps you in hindsight as the tester does not poke you time and again for clarifications.&lt;/p&gt;

&lt;p&gt;On the other hand if you are a tester, ensure that while raising a bug you also communicate the steps to reproduce the bug saving developer from treasure hunting the bug! &lt;/p&gt;




&lt;h1&gt;
  
  
  Clean Code
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EPnyvrZb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lombreh2oruc7ap622ox.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EPnyvrZb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lombreh2oruc7ap622ox.jpg" alt="photo-1515879218367-8466d910aaa4" width="880" height="588"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Everyone knows how important writing clean code is, but most of us ignore the sheer importance of it in the long run. But wait, karma is a bitch, right?&lt;/p&gt;

&lt;p&gt;It is highly probable that the shit code you are writing today which is in a “working” condition comes biting you in the ass 3 months down the line. This happened to me, and believe me I am writing this because the scar (from that bite) stays!&lt;/p&gt;

&lt;p&gt;Clean code is so important that people have dedicated books on the topic. So a few things that I always follow are:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Indentation&lt;/strong&gt; - Ensure the entire team has the same indentation settings. 1 Tab = 4 Spaces or 1 Tab = 2 Spaces. Decide and stick to it.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comments&lt;/strong&gt; - There are lover letters/snippets to your future self as well as the next developer working on your module.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Missing semi-colon&lt;/strong&gt; - This is just a &lt;a href="https://en.wikipedia.org/wiki/Newbie"&gt;noob&lt;/a&gt; mistake!  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use &lt;a href="https://medium.com/imdoneio/5-ways-using-todo-comments-will-make-you-a-better-programmer-240abd00d9e4"&gt;TODO&lt;/a&gt;&lt;/strong&gt; - Leave hints/tips and breadcrumbs for yourself and the fellow developer working after you. Complete the TODO before raising the &lt;a href="https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/about-pull-requests"&gt;PR&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Debugging messages&lt;/strong&gt; - Check for all the console.log() messages before submitting your code. And if you are lazy (like me), &lt;a href="https://adityatyagi.com/index.php/2020/03/25/remove-all-console-log-in-one-go/"&gt;click here&lt;/a&gt; to learn how to remove all console.log() messages in one-go! Also, remove all debuggers as well!  &lt;/p&gt;




&lt;h1&gt;
  
  
  Punctuality
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OnlLoGvU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/777mittqox655a82f723.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OnlLoGvU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/777mittqox655a82f723.jpg" alt="photo-1508962914676-134849a727f0" width="880" height="587"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;This is one of the most talked about but yet remains the most underrated aspect of working in a team. Even if you are one of the most bad-ass developer, you have to respect everyone’s time. Just because you are good at what you do doesn’t give you “GET-OUT-OF-JAIL” card for free!&lt;/p&gt;

&lt;p&gt;So be on the morning SCRUM calls, be punctual with your work commitments and don’t just take an off abruptly on a weekday (I mean too often).&lt;/p&gt;

&lt;p&gt;Sometimes your fellow developers are waiting for you to push your code! Don’t be a jerk for keeping them waiting – on purpose!  &lt;/p&gt;




&lt;h1&gt;
  
  
  Be Organized – Google Sheets
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CvQW_zyn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8xtxh7iz8ba28o6e4ykx.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CvQW_zyn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/8xtxh7iz8ba28o6e4ykx.jpg" alt="thorhammer-ft" width="880" height="461"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is my &lt;a href="https://i.ytimg.com/vi/YWog8N3v9XA/maxresdefault.jpg"&gt;Mjölnir&lt;/a&gt;. Google Sheets have helped me organize my workday and my work-flow in general. The number of things to keep a track off can hinder your general programming and hence it is important to be on top of it – all the time. Also, the number of things to follow increases significantly when you are working remotely with 20 other people! For example:  &lt;/p&gt;

&lt;h2&gt;
  
  
  Work-From-Home (WFH) checklist
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NE_nLO41--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/18w761f3zvdtnxrw4dei.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NE_nLO41--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/18w761f3zvdtnxrw4dei.png" alt="image" width="880" height="264"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;This helps me to make sure I do everything when I start my day and when I end my day. &lt;a href="https://docs.google.com/spreadsheets/d/1YtHGe3oqprt_l6urnrfAW2kim2GA7VBlnoMWLkkdFoQ/edit?usp=sharing"&gt;Get the WFH checklist&lt;/a&gt;  &lt;/p&gt;

&lt;h2&gt;
  
  
  Sprint Tracker
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_bi_88vt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bek4hv75d2lkir6eeusn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_bi_88vt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bek4hv75d2lkir6eeusn.png" alt="image-1-1536x408" width="880" height="234"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;If you have worked in a product based company and JIRA, the term Sprint will not be alien to you. But for others, a Sprint is a development cycle adhering to a fixed time period, post which the team has a feature implemented. &lt;a href="https://www.atlassian.com/agile/tutorials/sprints#:~:text=Jira%20Sprints%20Tutorial,implemented%20a%20working%20product%20increment.&amp;amp;text=You%20are%20new%20to%20agile%20software%20development%20or%20Jira%20Software"&gt;Details here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The Sprint tracker is something personal and works like a charm for the work-flow being followed at my work-place. It is important to understand that the workflow can be different for different teams and different projects. So, my advice to you will be to develop a Sprint tracker for yourself. &lt;a href="https://docs.google.com/spreadsheets/d/1CC0LQTvHCnUf1HaLBTZjN7ogK6tBuE8eo96jYLyIm_A/edit#gid=0"&gt;Get Sprint Tracker template&lt;/a&gt;  &lt;/p&gt;

&lt;h2&gt;
  
  
  Important R&amp;amp;D Links
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NK6FOpNc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/sy42smv8lunrxse4xx9c.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NK6FOpNc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/sy42smv8lunrxse4xx9c.png" alt="image-2-1536x772" width="880" height="442"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now this is “My Thing”. Some of you will definitively think this is just STUPID. But to be honest with you, this has helped me leaps and bounds and have increased my developments speed. One thing that I am sure off is that the problem I solved after 3 hours and if that problem comes again, I don’t want to again go through the agony of finding that 1 StackOverflow answer or that 1 Medium article.&lt;/p&gt;

&lt;p&gt;So, every-time I stumble upon something new, I just make a note of it. Now because I work in startup, it also gives me the opportunity of working with a ton of frameworks. So, I have dedicated tabs for them!  &lt;/p&gt;




&lt;h1&gt;
  
  
  Burn Out
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NLRnO6XA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7bme5fbxhj9bbe29x8k1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NLRnO6XA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7bme5fbxhj9bbe29x8k1.jpg" alt="burnout" width="880" height="627"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Do not work so much that you collapse. You’ll be replaced within 2 days once you aren’t fit to work anymore. Get this thing into your head.&lt;/p&gt;

&lt;p&gt;Keep your sanity intact. Do not try to outwork yourself or anyone in your company as a matter of fact! Take your Saturdays and Sundays. Breathe.  &lt;/p&gt;

&lt;h1&gt;
  
  
  In Conclusion…
&lt;/h1&gt;

&lt;p&gt;I’ll be updating this article as I progress with my career as a software developer because improving at your skill and productivity is a continuous process!&lt;/p&gt;

&lt;p&gt;Rest, to my fellow experienced software developers, please feel free to suggest your productivity hacks down below in the comments!&lt;/p&gt;




&lt;p&gt;Originally published at &lt;a href="https://adityatyagi.com/"&gt;adityatyagi.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>productivity</category>
    </item>
    <item>
      <title>Pick colors: LIKE A BOSS</title>
      <dc:creator>Aditya Tyagi</dc:creator>
      <pubDate>Sun, 14 Jun 2020 11:21:21 +0000</pubDate>
      <link>https://forem.com/adityatyagi/pick-colors-like-a-boss-49ci</link>
      <guid>https://forem.com/adityatyagi/pick-colors-like-a-boss-49ci</guid>
      <description>&lt;p&gt;&lt;strong&gt;Disclaimer&lt;/strong&gt;: Windows only  &lt;/p&gt;

&lt;p&gt;As a front-end developer, one of the most important work is to get the design right. Now there are times when the client is a bit low on budget and cannot provide a professionally designed app with colors-scheme and shit!&lt;/p&gt;

&lt;p&gt;There are times when you are asked to do a hot-fix for a production ready app wherein you just have to match the color according to the design.&lt;/p&gt;

&lt;p&gt;So, whenever I am developing on Windows, and there is a need to pick colors from an image, browser, website, practically ANYTHING, my go-to tool is: &lt;a href="http://colorcop.net/"&gt;COLORCOP&lt;/a&gt;  &lt;/p&gt;

&lt;h2&gt;
  
  
  Color from a desktop icon
&lt;/h2&gt;

&lt;p&gt;Picking color from the Winamp logo&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HuLpGHTO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wuo1zfd7gcvgbdxcd2nc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HuLpGHTO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/wuo1zfd7gcvgbdxcd2nc.png" alt="Alt Text" width="282" height="340"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;h2&gt;
  
  
  Color from browser
&lt;/h2&gt;

&lt;p&gt;Picking Purple color from the Broswer – RegEx text&lt;br&gt;&lt;br&gt;
 &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZSYNxuIW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/c6flyddcl10x47w0ak81.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZSYNxuIW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/c6flyddcl10x47w0ak81.png" alt="Alt Text" width="880" height="465"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;With Colorcop, you can pick colors off any surface, literally ANY SURFACE. As you can see in the image above, we are picking colors off of an icon – a fucking icon! Now, how cool is this shit!  &lt;/p&gt;




&lt;h1&gt;
  
  
  In an alternate universe…
&lt;/h1&gt;

&lt;p&gt;For MacOS or Linux users, stick to Chrome/Firefox extensions like &lt;a href="https://chrome.google.com/webstore/detail/colorzilla/bhlhnicpbhignbdhedgjhgdocnmhomnp"&gt;ColorZilla&lt;/a&gt;. But obviously, just Google ColorCop alternatives for MacOS or Linux and if you do stumble on anything concrete, ping me here!  &lt;/p&gt;




&lt;p&gt;Originally published at &lt;a href="https://adityatyagi.com/index.php/2020/06/11/pick-colors-like-a-boss/"&gt;adityatyagi.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
    </item>
    <item>
      <title>Understanding tabindex – keyboard accessibility</title>
      <dc:creator>Aditya Tyagi</dc:creator>
      <pubDate>Sun, 07 Jun 2020 09:22:06 +0000</pubDate>
      <link>https://forem.com/adityatyagi/understanding-tabindex-keyboard-accessibility-glm</link>
      <guid>https://forem.com/adityatyagi/understanding-tabindex-keyboard-accessibility-glm</guid>
      <description>&lt;p&gt;As a web developer, you are required to ensure that your users have the best of experience while using your product. Traversing your website with a keyboard is one of the fastest ways. Not only this, filling a form which is keyboard accessible takes 1/2 the time, if compared to filling the form using a mouse-keyboard duo.&lt;/p&gt;

&lt;p&gt;But the thing is, accessibility is for the people who are either using screen readers or are using assistive technologies. My main aim here is to put down notes on &lt;code&gt;tabindex&lt;/code&gt; and how it plays a major role in making your forms and DOM (Document Object Model) keyboard accessible.&lt;/p&gt;

&lt;h1&gt;
  
  
  How to find active element?
&lt;/h1&gt;

&lt;p&gt;One of the problems while making a form keyboard accessible with &lt;code&gt;tabindex&lt;/code&gt; was to find out where the fuck I actually was in the DOM while pressing the TAB key. At times it drove me nuts but then I had to find a better a solution. Turns out, its pretty simple.&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;activeElement&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Fire up the chrome/firefox developer tools in your browser and once you are done TAB-bing through the form and want to know which element is in focus, use “document.activeElement” and press Enter.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Firefox developer tools
&lt;/h3&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%2Fnftpofoxrtoyeuv7nz69.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%2Fnftpofoxrtoyeuv7nz69.png" alt="Alt Text"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;The most amazing thing about this is that when you hover on active element thrown by the developer tools, you’ll see something like in the picture above, and below!  &lt;/p&gt;

&lt;h3&gt;
  
  
  Chrome developer tools
&lt;/h3&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%2F7p9ru6e85jabd7oqf17o.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%2F7p9ru6e85jabd7oqf17o.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  Understanding &lt;code&gt;tabindex&lt;/code&gt; and how it works
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;tabindex&lt;/code&gt; is used for 2 major reasons:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;to check if the element is focusable&lt;/li&gt;
&lt;li&gt;at what point/in what order the element comes into focus
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Focus order
&lt;/h2&gt;

&lt;p&gt;There are 6 HTML elements which has the ability to focus by default i.e. you don’t have to explicitly put tabindex attribute.  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; with &lt;code&gt;href&lt;/code&gt; attribute&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt; with &lt;code&gt;href&lt;/code&gt; attribute&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt; without the &lt;code&gt;type="hidden"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;lt;textarea&amp;gt;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;&amp;lt;select&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This means, these 6 elements will have the focus during the TAB-ing behavior and the screen readers will be able to read these elements without any extra help!  &lt;/p&gt;




&lt;h1&gt;
  
  
  Important note for Frontend Developers
&lt;/h1&gt;

&lt;p&gt;The order will highly depend on the order in which these elements are coded in .html files.&lt;/p&gt;

&lt;p&gt;For example, if you want to use &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt; under the same parent, and you want the &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt; to have focus before the &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt;, then make sure you &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt; has been coded before &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; in the .html file.&lt;/p&gt;

&lt;h3&gt;
  
  
  position:absolute
&lt;/h3&gt;

&lt;p&gt;Therefore, if you are positioning elements with &lt;code&gt;position: absolute&lt;/code&gt; then make sure the absolutely positioned element is AFTER the element you want focused on! I learnt this the hard way so want to give you a heads up!&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="c"&gt;&amp;lt;!-- First in order --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;I will be first in focus&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- Second in order --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"javascript:void(0)"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;I will be focused second&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Testing playground: You’ll learn it better when you see it in practice! So stop being a lazy-ass and try these examples on &lt;a href="https://codepen.io/pen/" rel="noopener noreferrer"&gt;CodePen&lt;/a&gt; here.  &lt;/p&gt;
&lt;/blockquote&gt;




&lt;h1&gt;
  
  
  tabindex values: -1, 0, +1
&lt;/h1&gt;

&lt;p&gt;The tabindex values can be negative, 0 or positive.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Negative:&lt;/strong&gt; When the element has negative focus, neither it will be read by screen readers nor it will come in the TAB-ing sequence. A negative tabindex (say -1) will remove the element from the ordering sequence completely. A negative value is a negative value. This means, there is no difference between -1 and -145 or -9999.&lt;/p&gt;

&lt;p&gt;If you want to purposefully ignore an element in the TAB-ing sequence, just give it a negative tabindex.&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;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Sample Button 1&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- This will be ignored --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; &lt;span class="na"&gt;tabindex=&lt;/span&gt;&lt;span class="s"&gt;"-1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;I will be ignored&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Sample Button 2&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Testing playground: You’ll learn it better when you see it in practice! So stop being a lazy-ass and try these examples on &lt;a href="https://codepen.io/pen/" rel="noopener noreferrer"&gt;CodePen&lt;/a&gt; here.  &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;2. Zero:&lt;/strong&gt; This is the default value. The 6 elements we talked about, will have &lt;code&gt;tabindex="0"&lt;/code&gt; by default when the DOM gets built in the browser. But if you want to focus on a non-focusable element like &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; or &lt;code&gt;&amp;lt;span&amp;gt;&lt;/code&gt;, you can explicitly give it a &lt;code&gt;tabindex&lt;/code&gt; attribute with value 0. Once you do that, the element will follow the default TAB-ing order.&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;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Sample Button 1&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- Making non-focusable element focusable --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;tabindex=&lt;/span&gt;&lt;span class="s"&gt;"0"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Please focus on me&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Sample Button 2&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Testing playground: You’ll learn it better when you see it in practice! So stop being a lazy-ass and try these examples on &lt;a href="https://codepen.io/pen/" rel="noopener noreferrer"&gt;CodePen&lt;/a&gt; here.  &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
&lt;strong&gt;3. Positive:&lt;/strong&gt; The positive &lt;code&gt;tabindex&lt;/code&gt; will place the element having a positive &lt;code&gt;tabindex&lt;/code&gt; in the order sequence and the order will be decided based on the value. The TAB-ing will happen in the ascending order.&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;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; &lt;span class="na"&gt;tabindex=&lt;/span&gt;&lt;span class="s"&gt;"2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Sample Button 1&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;&amp;lt;!-- This will be ignored, even though it has a tab-index --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; &lt;span class="na"&gt;tabindex=&lt;/span&gt;&lt;span class="s"&gt;"1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Sample Button 2&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; &lt;span class="na"&gt;tabindex=&lt;/span&gt;&lt;span class="s"&gt;"3"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Sample Button 3&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Testing playground: You’ll learn it better when you see it in practice! So stop being a lazy-ass and try these examples on &lt;a href="https://codepen.io/pen/" rel="noopener noreferrer"&gt;CodePen&lt;/a&gt; here.  &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
The first-focus will be on &lt;strong&gt;Sample Button 1&lt;/strong&gt; having &lt;code&gt;tabindex&lt;/code&gt; value of 2. The next TAB will take you to &lt;strong&gt;Sample Button 3&lt;/strong&gt;, completely ignoring &lt;strong&gt;Sample Button 2&lt;/strong&gt;. The TAB-ing will NEVER happen in decreasing order, therefore you will never reach &lt;strong&gt;Sample Button 2&lt;/strong&gt;.  &lt;/p&gt;

&lt;h3&gt;
  
  
  The catch
&lt;/h3&gt;

&lt;p&gt;Positive &lt;code&gt;tabindex&lt;/code&gt; values are discouraged and are an antipattern. According to &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex" rel="noopener noreferrer"&gt;MDN Web Docs&lt;/a&gt;, never use positive &lt;code&gt;tabindex&lt;/code&gt; values and stick to the default value of 0. But if there is a use-case wherein you want to have a positive &lt;code&gt;tabindex&lt;/code&gt; value to change the order of focus sequence, then take a stop the fuck right there. Take a step back and a deep breath while you are at it! Now try to change the order of elements in your HTML file/source code!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TAB-ing must be fixed with correct order of HTML elements within the source code.&lt;/strong&gt;  &lt;/p&gt;




&lt;h1&gt;
  
  
  In Conclusion…
&lt;/h1&gt;

&lt;p&gt;I have been working as a web developer for more than 1.5 years now and I am a self-learner developer, like the majority out there. The thing with self learning is that you learn stuff when the opportunity knocks on the door to learn that shit. And this was no different. I learned about web accessibility recently and the sheer importance of it.&lt;/p&gt;

&lt;p&gt;As web developers we need to understand that we enjoy the privilege to develop products and projects that will be used by &lt;a href="https://www.w3.org/WAI/people-use-web/abilities-barriers/" rel="noopener noreferrer"&gt;speech and visually impaired&lt;/a&gt; people as well, apart from the rest of the world. Therefore the next time you are writing code in an HTML file, ensure that it adheres to web accessibility standards.&lt;/p&gt;

&lt;p&gt;Checkout more cool stuff &lt;a href="https://a11yproject.com/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.  &lt;/p&gt;




&lt;p&gt;Originally published at &lt;a href="https://adityatyagi.com" rel="noopener noreferrer"&gt;adityatyagi.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>a11y</category>
      <category>webdev</category>
      <category>webaccessibility</category>
    </item>
    <item>
      <title>Working with loaders and RxJS Observables</title>
      <dc:creator>Aditya Tyagi</dc:creator>
      <pubDate>Sun, 31 May 2020 11:35:00 +0000</pubDate>
      <link>https://forem.com/adityatyagi/working-with-loaders-and-rxjs-observables-3l5d</link>
      <guid>https://forem.com/adityatyagi/working-with-loaders-and-rxjs-observables-3l5d</guid>
      <description>&lt;p&gt;Loaders is an integral part of user experience. Appropriate usage of loaders is essential to ensure smooth experience. If a loader stops too early, it feels like nothing has happened and seems like the app has frozen. If the loader stops too late, then it feels like an eternity to use the app. In both the cases, you loose a user and in extreme cases, are liable for some cuss-words too!  &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%2Fi.imgflip.com%2F42kh3r.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%2Fi.imgflip.com%2F42kh3r.jpg" alt="Waiting Meme"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;Now if you are working in Angular, then you are obviously working with Observables. But if you are working with React, and are using RxJS Observables to control the data flow (the reactive paradigm), even then you can use the following technique to ensure perfect start-stop of loaders.  &lt;/p&gt;

&lt;h1&gt;
  
  
  Observable lifecycles
&lt;/h1&gt;

&lt;p&gt;There are 3 stages in the lifecycle:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;next&lt;/code&gt; – This is when the observable completes with a success and sends data to the subscriber  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;error&lt;/code&gt; – When the observable’s execution throws an error and sends an error object to the subscriber  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;complete&lt;/code&gt; – When the execution is completed but no data is sent to the subscriber&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Say, you start the loader before making the API call. The tricky part is when and how to stop the loader using the Observable lifecycle.  &lt;/p&gt;

&lt;h1&gt;
  
  
  STOPPING AT EVERY STEP
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// initially the loader is false&lt;/span&gt;
&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isLoading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  

&lt;span class="c1"&gt;// fetch todos&lt;/span&gt;
&lt;span class="nf"&gt;fetchTodos&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// start the loader&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isLoading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&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;http$&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;http&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com/todos&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 

        &lt;span class="nx"&gt;http$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="nx"&gt;next&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="s1"&gt;Data from API&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

              &lt;span class="c1"&gt;// stop the loader once the observable completes with success&lt;/span&gt;
              &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isLoading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&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="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="s1"&gt;Error from API&lt;/span&gt;&lt;span class="dl"&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="c1"&gt;// stop the loader if the observable fails&lt;/span&gt;
              &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isLoading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&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;Play with the demo here: &lt;a href="https://stackblitz.com/edit/angular-ivy-gv1f6f" rel="noopener noreferrer"&gt;Stackblitz Link&lt;/a&gt;  &lt;/p&gt;




&lt;h1&gt;
  
  
  Using &lt;code&gt;complete&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;The loader in this case will stop only when the observable completes with a success. If the observable fails with an error, we’ll have to still explicitly stop the loader in the error block.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt; &lt;span class="c1"&gt;// initially the loader is false&lt;/span&gt;
 &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isLoading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  

 &lt;span class="nf"&gt;fetchTodos&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isLoading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&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;http$&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;http&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com/todos&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 

        &lt;span class="nx"&gt;http$&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="nx"&gt;next&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="s1"&gt;Data from API&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&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="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="s1"&gt;Error from API&lt;/span&gt;&lt;span class="dl"&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="c1"&gt;// stop the loader if the observable fails&lt;/span&gt;
              &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isLoading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&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="c1"&gt;// onComplete block&lt;/span&gt;
              &lt;span class="c1"&gt;// stop the loader once the observable completes with success&lt;/span&gt;
              &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isLoading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&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;Play with the demo here: &lt;a href="https://stackblitz.com/edit/angular-ivy-gv1f6f" rel="noopener noreferrer"&gt;Stackblitz Link&lt;/a&gt;  &lt;/p&gt;




&lt;h1&gt;
  
  
  BEST WAY: RxJS &lt;code&gt;finalize&lt;/code&gt; operator
&lt;/h1&gt;

&lt;p&gt;This will help you to stop the loader in both cases, when the observable execution completes in success or when it fails.&lt;/p&gt;

&lt;p&gt;For this, you’ll first have to import the finalize operator from RxJS.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&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;finalize&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="s1"&gt;rxjs/operators&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;p&gt;Once done, you can use this operator with the pipe operator, just before you subscribe.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// initially the loader is false&lt;/span&gt;
&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isLoading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  

&lt;span class="nf"&gt;fetchTodos&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isLoading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&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;http$&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;http&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com/todos&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 

        &lt;span class="nx"&gt;http$&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
          &lt;span class="nf"&gt;finalize&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isLoading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&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="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="nx"&gt;next&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="s1"&gt;Data from API&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&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="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="s1"&gt;Error from API&lt;/span&gt;&lt;span class="dl"&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="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;Play with the demo here: &lt;a href="https://stackblitz.com/edit/angular-ivy-gv1f6f" rel="noopener noreferrer"&gt;Stackblitz Link&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;Here, you don’t have to stop the loader explicitly within “next” and “error” blocks. The loader will be stopped in the “finalize” block in both the cases:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;When the observable completes to success
&lt;/li&gt;
&lt;li&gt;When the observable completes to error
&lt;/li&gt;
&lt;/ol&gt;




&lt;h1&gt;
  
  
  Faking a Failed HTTP Request
&lt;/h1&gt;

&lt;p&gt;To check the stopping of loading in case the observable throws an error, we can fake a failed API response by throwing an error on purpose. For this, we’ll be using RxJS operators like map.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isLoading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

 &lt;span class="nf"&gt;fetchTodos&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isLoading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&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;http$&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;http&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com/todos&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 

        &lt;span class="nx"&gt;http$&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pipe&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;d&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
              &lt;span class="c1"&gt;// deliberately throwing an error&lt;/span&gt;
              &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;test error&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="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="nx"&gt;next&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="s1"&gt;Data from API&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
              &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
              &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isLoading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
              &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&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;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error from API&lt;/span&gt;&lt;span class="dl"&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="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isLoading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&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;Play with the demo here: &lt;a href="https://stackblitz.com/edit/angular-ivy-gv1f6f" rel="noopener noreferrer"&gt;Stackblitz Link&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;The “map” operator is generally used to modify the incoming data before we can use it in the subscribe block. Here, we are using the map-block to throw an Error and hence the error block will get executed.  &lt;/p&gt;




&lt;h1&gt;
  
  
  Hidden Gem – &lt;code&gt;.add()&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;If you feel like “finalize” doesn’t makes sense according to flow because we are writing code to stop the loader before everything, there is .add() operator for you. It behaves same like the finalize operator and gets executed in both the cases – success or error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;isLoading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;fetchTodos&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isLoading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&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;http$&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;http&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jsonplaceholder.typicode.com/todos&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 

        &lt;span class="nx"&gt;http$&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;subscribe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="nx"&gt;next&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="s1"&gt;Data from API&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;next&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
              &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;next&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
              &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&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;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Error from API&lt;/span&gt;&lt;span class="dl"&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="p"&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isLoading&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&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;Play with the demo here: &lt;a href="https://stackblitz.com/edit/angular-ivy-gv1f6f" rel="noopener noreferrer"&gt;Stackblitz Link&lt;/a&gt;  &lt;/p&gt;




&lt;h1&gt;
  
  
  In Conclusion…
&lt;/h1&gt;

&lt;p&gt;The one thing which is not addressed here is unsubscribing of Observables but I’ll surely cover that in the upcoming post. This was just to bring to your attention that Observables are sneaky.&lt;/p&gt;

&lt;p&gt;I learnt this after a number of trial and errors and its such a small thing which is being used in every project I do. There is one other way to start-stop the loader globally in the app which uses RxJS BehaviorSubject. I’ll try to update the post with this in future as well!&lt;/p&gt;

&lt;p&gt;Until then, share this with your friends/colleagues.&lt;br&gt;
Any suggestions/ideas/advice/feedback – please reach out to me:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In the comments below&lt;/li&gt;
&lt;li&gt;Email - &lt;a href="mailto:tyagi.aditya844747@gmail.com"&gt;tyagi.aditya844747@gmail.com&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Twitter - &lt;a href="https://twitter.com/secondbestcoder" rel="noopener noreferrer"&gt;@secondbestcoder&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;




&lt;blockquote&gt;
&lt;p&gt;Originally poster on &lt;a href="https://adityatyagi.com/" rel="noopener noreferrer"&gt;adityatyagi.com&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>angular</category>
      <category>react</category>
      <category>rxjs</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
