<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Naga Chaitanya Konada</title>
    <description>The latest articles on DEV Community by Naga Chaitanya Konada (@chaituknag).</description>
    <link>https://dev.to/chaituknag</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%2F112257%2Fa66f8367-4c82-455d-84e6-a6a8142ce1e9.jpg</url>
      <title>DEV Community: Naga Chaitanya Konada</title>
      <link>https://dev.to/chaituknag</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/chaituknag"/>
    <language>en</language>
    <item>
      <title>10 most important typescript concepts</title>
      <dc:creator>Naga Chaitanya Konada</dc:creator>
      <pubDate>Sun, 02 Jul 2023 01:41:20 +0000</pubDate>
      <link>https://dev.to/chaituknag/10-most-important-typescript-concepts-4830</link>
      <guid>https://dev.to/chaituknag/10-most-important-typescript-concepts-4830</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;TypeScript is an open-source programming language that is a superset of JavaScript. It adds optional static typing and class-based object-oriented programming to the language. As a result, TypeScript is becoming increasingly popular among developers, especially those working with large-scale projects. In this blog post, we will discuss 10 of the most important TypeScript concepts that every developer should know.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--q_PSvEnh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x07ckinyef4hzvvxdnsk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--q_PSvEnh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x07ckinyef4hzvvxdnsk.png" alt="Intro" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Type Annotations
&lt;/h2&gt;

&lt;p&gt;Type annotations are a crucial concept in TypeScript. They allow developers to specify the data types of variables, function parameters, and return types. This can help catch errors during development and improve code readability. &lt;/p&gt;

&lt;p&gt;For example,&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;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;27&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This specifies that the variable &lt;code&gt;age&lt;/code&gt; should be of type &lt;code&gt;number&lt;/code&gt; and have an initial value of &lt;code&gt;27&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TzrbYfEG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vqmnyht4i7u0xgvz4rqw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TzrbYfEG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vqmnyht4i7u0xgvz4rqw.png" alt="Type Annotations" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Interfaces
&lt;/h2&gt;

&lt;p&gt;Interfaces are used to define the structure of an object. They specify the names and types of the object's properties and can be used to enforce consistency across multiple objects. &lt;/p&gt;

&lt;p&gt;For instance,&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="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nl"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This defines an interface for a &lt;code&gt;Person&lt;/code&gt; object with a &lt;code&gt;name&lt;/code&gt; property of type &lt;code&gt;string&lt;/code&gt; and an &lt;code&gt;age&lt;/code&gt; property of type &lt;code&gt;number&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--j_d25853--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rvwu9tnw962vn6uyzjg0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--j_d25853--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rvwu9tnw962vn6uyzjg0.png" alt="Interfaces" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Classes
&lt;/h2&gt;

&lt;p&gt;Classes are a core concept in object-oriented programming, and TypeScript has full support for them. Classes allow developers to define blueprints for objects that share the same properties and methods. They can also include constructors, access modifiers, and inheritance. &lt;/p&gt;

&lt;p&gt;For example,&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;class&lt;/span&gt; &lt;span class="nx"&gt;Animal&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
    &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&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;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&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;This defines a &lt;code&gt;Animal&lt;/code&gt; class with a &lt;code&gt;name&lt;/code&gt; property and a constructor that sets the &lt;code&gt;name&lt;/code&gt; property.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xgPnDUiB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/683h6izov8ejly2m9wrj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xgPnDUiB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/683h6izov8ejly2m9wrj.png" alt="Classes" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Generics
&lt;/h2&gt;

&lt;p&gt;Generics are a powerful feature in TypeScript that allow for the creation of reusable code. They allow developers to create functions and classes that can work with a variety of data types. &lt;/p&gt;

&lt;p&gt;For example,&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;function&lt;/span&gt; &lt;span class="nx"&gt;identity&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&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;arg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;T&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;arg&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This defines a generic &lt;code&gt;identity&lt;/code&gt; function that returns the same value that is passed to it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OKHyn27W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/re2mbg8art1al5agbb3l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OKHyn27W--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/re2mbg8art1al5agbb3l.png" alt="Generics" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Enums
&lt;/h2&gt;

&lt;p&gt;Enums are a way to define a set of named values. They can improve code readability and help catch errors. &lt;/p&gt;

&lt;p&gt;For instance,&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="kr"&gt;enum&lt;/span&gt; &lt;span class="nx"&gt;Color&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="nx"&gt;Red&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Green&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Blue&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This defines an &lt;code&gt;Color&lt;/code&gt; enum with three named values: &lt;code&gt;Red&lt;/code&gt;, &lt;code&gt;Green&lt;/code&gt;, and &lt;code&gt;Blue&lt;/code&gt;. Enum values can also be assigned specific numeric values, such as:&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="kr"&gt;enum&lt;/span&gt; &lt;span class="nx"&gt;Color&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="nx"&gt;Red&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="nx"&gt;Green&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="nx"&gt;Blue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cG9nVpgn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vsz6l2tdaz1e1ksl8oxn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cG9nVpgn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vsz6l2tdaz1e1ksl8oxn.png" alt="Enums" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Type Inference
&lt;/h2&gt;

&lt;p&gt;Type inference is a feature of TypeScript that allows developers to omit type annotations in certain situations. &lt;/p&gt;

&lt;p&gt;For example,&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;age&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;27&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 automatically be inferred as a &lt;code&gt;number&lt;/code&gt; type because it is assigned a numeric value. Type inference can also be used with function parameters and return types, such as:&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;function&lt;/span&gt; &lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&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;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HsFBvIj5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j5pnfpq0m0z6emtgn73u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HsFBvIj5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j5pnfpq0m0z6emtgn73u.png" alt="Type Inference" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  7. Union and Intersection Types
&lt;/h2&gt;

&lt;p&gt;Union types allow for the combination of two or more data types into one. This can be useful when a function or variable can accept multiple types of data. &lt;/p&gt;

&lt;p&gt;For example,&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;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;27&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This specifies that the &lt;code&gt;age&lt;/code&gt; variable can be of type &lt;code&gt;number&lt;/code&gt; or &lt;code&gt;string&lt;/code&gt;. Intersection types, on the other hand, allow for the creation of a new type that includes all properties and methods of multiple types. &lt;/p&gt;

&lt;p&gt;For example,&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;type&lt;/span&gt; &lt;span class="nx"&gt;Animal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Dog&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;Cat&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This creates a new type &lt;code&gt;Animal&lt;/code&gt; that has all properties and methods of both the &lt;code&gt;Dog&lt;/code&gt; and &lt;code&gt;Cat&lt;/code&gt; types.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6MffmSys--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/czv867b8zgzk772h9vbt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6MffmSys--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/czv867b8zgzk772h9vbt.png" alt="Union and Intersection Types" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Type Guards
&lt;/h2&gt;

&lt;p&gt;Type guards are a feature in TypeScript that allow developers to check the type of a variable at runtime. This can be useful when working with union types or other situations where the type of a variable may not be known. &lt;/p&gt;

&lt;p&gt;For instance,&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;number&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; 
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This checks if the &lt;code&gt;age&lt;/code&gt; variable is of type &lt;code&gt;number&lt;/code&gt; before performing a multiplication operation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nK_KbCPp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9pwmme3lmrybyd6f452g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nK_KbCPp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9pwmme3lmrybyd6f452g.png" alt="Type Guards" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  9. Decorators
&lt;/h2&gt;

&lt;p&gt;Decorators are a feature in TypeScript that allow for the addition of metadata to classes, methods, and properties. They can be used to modify the behavior of a class or to provide additional information for tools like code analyzers. &lt;/p&gt;

&lt;p&gt;For example,&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="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;deprecated&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;MyClass&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This marks the &lt;code&gt;MyClass&lt;/code&gt; class as deprecated and will generate a warning when used.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NE8M0eBE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d71tvl3qihiske6yq7c1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NE8M0eBE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d71tvl3qihiske6yq7c1.png" alt="Decorators" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  10. Modules
&lt;/h2&gt;

&lt;p&gt;Modules are a way to organize code into smaller, reusable components. They allow developers to define private and public parts of a codebase and to import and export components between files. &lt;/p&gt;

&lt;p&gt;For example,&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;// my-class.ts&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;MyClass&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This exports the &lt;code&gt;MyClass&lt;/code&gt; class from a module, while:&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;// main.ts&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;MyClass&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./MyClass&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;This imports the &lt;code&gt;MyClass&lt;/code&gt; class into another module.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bJo2GFYU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xczldvzs7d7alg6v3q8i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bJo2GFYU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xczldvzs7d7alg6v3q8i.png" alt="Modules" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;TypeScript is a powerful language that is becoming increasingly popular among developers. By mastering these 10 important concepts, developers can write more efficient and maintainable code. While there are many other concepts and features in TypeScript, these 10 are a great starting point for any developer looking to learn the language.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.typescriptlang.org/"&gt;TypeScript&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.typescriptlang.org/docs/handbook/intro.html"&gt;TypeScript Handbook&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://basarat.gitbook.io/typescript/"&gt;TypeScript Deep Dive&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html"&gt;TypeScript in 5 minutes&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.typescriptlang.org/play"&gt;TypeScript Playground&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;If you liked what you learned, checkout my other posts &lt;a href="https://tech.nagakonada.com/all-articles"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How popular are libraries in each technology</title>
      <dc:creator>Naga Chaitanya Konada</dc:creator>
      <pubDate>Thu, 22 Jun 2023 01:38:31 +0000</pubDate>
      <link>https://dev.to/chaituknag/how-popular-are-libraries-in-each-technology-128h</link>
      <guid>https://dev.to/chaituknag/how-popular-are-libraries-in-each-technology-128h</guid>
      <description>&lt;p&gt;In the world of software development, every technology has a leading &lt;a href="https://www.baeldung.com/cs/framework-vs-library"&gt;library or framework&lt;/a&gt;. But have you ever wondered what is the leader among the leading libraries? Which technology has the highest number of likes or followers? Github is the best place to investigate and find out such a statistic. In this article, we will look at all the major technologies in various software development streams and explore the most popular libraries and frameworks in each category.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frontend Libraries
&lt;/h2&gt;

&lt;p&gt;Frontend development is the process of using HTML, CSS, and JavaScript to create &lt;a href="https://en.wikipedia.org/wiki/Web_application"&gt;web applications&lt;/a&gt; that run in a user's web browser. There are many popular frontend libraries available, but the clear leader is &lt;a href="https://react.dev/"&gt;React&lt;/a&gt;. React is a JavaScript library developed by Facebook that allows developers to create complex and dynamic user interfaces. It has over &lt;strong&gt;209k stars&lt;/strong&gt;  (2023) on Github, making it the most popular frontend library by a large margin.&lt;/p&gt;

&lt;p&gt;Other popular frontend libraries include Vue.js, Angular, and Ember.js. &lt;a href="https://vuejs.org/"&gt;Vue.js&lt;/a&gt; is a progressive JavaScript framework that is gaining popularity due to its simplicity and ease of use. Surprisingly, Vue.js has been more popular than React.js for a long time if you consider the GitHub stars parameter alone. &lt;a href="https://angular.io/"&gt;Angular&lt;/a&gt; is a framework developed by Google that is widely used in enterprise applications. &lt;a href="https://emberjs.com/"&gt;Ember.js&lt;/a&gt; is a framework that is known for its convention over configuration approach and is used by companies such as Netflix and LinkedIn.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kkWLrov8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nyf1me085x32uqy7nw87.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kkWLrov8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nyf1me085x32uqy7nw87.png" alt="Frontend Technologies" width="800" height="561"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Backend Language Libraries
&lt;/h2&gt;

&lt;p&gt;Backend development is the process of creating &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/Server-side/First_steps/Introduction"&gt;server-side applications&lt;/a&gt; that provide data and services to frontend applications. There are many programming languages that can be used for backend development, and each language has its own set of libraries and frameworks. The most popular backend language is currently Python, and it has a number of popular libraries such as Django and Flask. Although Node.js has the most stars among individual projects, we have to give this category to Python in this category. This is because of its collective stars in the first two popular libraries, among many others.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.djangoproject.com/"&gt;Django&lt;/a&gt; is a high-level Python web framework that enables rapid development of secure and maintainable websites. It has over 71.5k stars on Github and is used by companies such as Instagram and Mozilla. &lt;a href="https://flask.palletsprojects.com/en/2.3.x/"&gt;Flask&lt;/a&gt; is a micro web framework that is lightweight and easy to use. It has over 63.3k stars (2023) on Github and is used by companies such as Airbnb and Netflix.&lt;/p&gt;

&lt;p&gt;Other popular backend languages include Java, Ruby, and Node.js. &lt;a href="https://www.java.com/en/"&gt;Java&lt;/a&gt; is a widely used programming language that is popular in enterprise applications. &lt;a href="https://www.ruby-lang.org/en/"&gt;Ruby&lt;/a&gt; is a dynamic, open-source programming language that is used in web development. &lt;a href="https://nodejs.org/en"&gt;Node.js&lt;/a&gt; is a JavaScript runtime built on Chrome's V8 JavaScript engine that enables developers to build server-side applications in JavaScript.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8u58y8mT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k11t1j82ojphhq3aq4hv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8u58y8mT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k11t1j82ojphhq3aq4hv.png" alt="Backend Technologies" width="800" height="561"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  DevOps
&lt;/h2&gt;

&lt;p&gt;DevOps is the practice of combining software development and IT operations to improve the speed and quality of &lt;a href="https://softwaresim.com/blog/how-can-devops-improve-software-delivery/"&gt;software delivery&lt;/a&gt;. There are many tools and platforms available for DevOps, but the most popular platform by far is &lt;a href="https://kubernetes.io/"&gt;Kubernetes&lt;/a&gt;. It is an open-source container &lt;a href="https://www.redhat.com/en/topics/containers/what-is-container-orchestration"&gt;orchestration&lt;/a&gt; platform that automates the deployment, scaling, and management of containerized applications. Kubernetes has over 99.3k stars (2023) on Github. Kubernetes is used by major companies such as Airbnb, GitHub, and Spotify for container orchestration and deployment automation.&lt;/p&gt;

&lt;p&gt;Other popular DevOps tools include Docker, Jenkins, and Ansible. &lt;a href="https://www.docker.com/"&gt;Docker&lt;/a&gt; is a platform that allows developers to package applications and their dependencies into containers that can be easily deployed to any environment. &lt;a href="https://www.jenkins.io/"&gt;Jenkins&lt;/a&gt; is an open-source automation server that enables developers to automate the building, testing, and deployment of software. &lt;a href="https://www.ansible.com/"&gt;Ansible&lt;/a&gt; is an open-source automation tool that enables developers to automate the configuration and management of IT infrastructure.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--R9iooV5Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iry4fa1t9msxz2vm320w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--R9iooV5Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iry4fa1t9msxz2vm320w.png" alt="Devops Technologies" width="800" height="561"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Fullstack E2E Solutions
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://bootcamp.learn.utoronto.ca/blog/what-is-a-full-stack-developer/"&gt;Fullstack development&lt;/a&gt; is the process of creating applications that span both frontend and backend development. There are many fullstack frameworks available, but the most popular by far is &lt;a href="https://nodejs.org/en"&gt;Node.js&lt;/a&gt;. Node.js is a JavaScript runtime built on Chrome's &lt;a href="https://v8.dev/"&gt;V8 JavaScript engine&lt;/a&gt; that enables developers to build server-side applications in JavaScript. It has over &lt;strong&gt;96k stars&lt;/strong&gt; on Github and is used by companies such as Netflix and LinkedIn.&lt;/p&gt;

&lt;p&gt;Other popular fullstack frameworks include Ruby on Rails, Django, and Laravel. &lt;a href="https://rubyonrails.org/"&gt;Ruby on Rails&lt;/a&gt; is a popular web application framework that uses the Ruby programming language. &lt;a href="https://www.djangoproject.com/"&gt;Django&lt;/a&gt; and &lt;a href="https://laravel.com/"&gt;Laravel&lt;/a&gt; are both backend web frameworks that use Python and PHP, respectively.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---T_eVq-G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ux86wzhtndwfin5qwzu4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---T_eVq-G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ux86wzhtndwfin5qwzu4.png" alt="Fullstack Technologies" width="800" height="557"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Machine Learning
&lt;/h2&gt;

&lt;p&gt;Machine learning is the process of using algorithms and &lt;a href="https://en.wikipedia.org/wiki/Statistical_model"&gt;statistical models&lt;/a&gt; to enable computers to learn from data. There are many tools and libraries available for machine learning, but the most popular by far is &lt;a href="https://www.tensorflow.org/"&gt;TensorFlow&lt;/a&gt;. TensorFlow is an open-source platform for machine learning developed by Google. It has over &lt;strong&gt;176k stars&lt;/strong&gt; on Github and is used by companies such as Airbnb and Intel.&lt;/p&gt;

&lt;p&gt;Other popular machine learning tools include PyTorch, Keras, and Scikit-learn. &lt;a href="https://pytorch.org/"&gt;PyTorch&lt;/a&gt; is an open-source machine learning library developed by Facebook that is known for its ease of use and flexibility. &lt;a href="https://keras.io/"&gt;Keras&lt;/a&gt; is a high-level neural networks API that is written in Python and is known for its simplicity. &lt;a href="https://scikit-learn.org/stable/"&gt;Scikit-learn&lt;/a&gt; is a machine learning library for Python that is used for data analysis and data mining tasks.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JtXnIkKC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lo4qr985oeudp2ugakg2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JtXnIkKC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lo4qr985oeudp2ugakg2.png" alt="Machine Learning Technologies" width="800" height="557"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Mobile App Libraries and Languages
&lt;/h2&gt;

&lt;p&gt;Mobile app development is the process of creating applications for mobile devices such as smartphones and tablets. There are many mobile app libraries and languages available, but the most popular by far is Flutter. &lt;a href="https://flutter.dev/"&gt;Flutter&lt;/a&gt; is a mobile app development framework developed by Google that enables developers to build high-performance, high-fidelity, apps for iOS and Android from a single codebase. It has over &lt;a href="https://pytorch.org/"&gt;154k stars&lt;/a&gt; on Github.&lt;/p&gt;

&lt;p&gt;Other popular mobile app libraries and languages include Swift, Kotlin, and React Native. &lt;a href="https://developer.apple.com/swift/"&gt;Swift&lt;/a&gt; is a programming language developed by Apple that is used for iOS and macOS development. &lt;a href="https://kotlinlang.org/"&gt;Kotlin&lt;/a&gt; is a programming language developed by JetBrains that is used for Android development. &lt;a href="https://reactnative.dev/"&gt;React Native&lt;/a&gt; is a JavaScript framework developed by Facebook that enables developers to build mobile applications for iOS and Android using a single codebase.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0e5FMVZU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8oqhobbdqww3lk0ghlr7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0e5FMVZU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8oqhobbdqww3lk0ghlr7.png" alt="Mobile App Libraries" width="800" height="561"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Templating Engines
&lt;/h2&gt;

&lt;p&gt;Templating engines are tools that enable developers to create HTML templates that can be dynamically generated and rendered by web applications. There are many templating engines available, but the most popular by far is Pug. &lt;a href="https://pugjs.org/api/getting-started.html"&gt;Pug&lt;/a&gt; is a templating engine that is known for its simplicity and ease of use. It has over 21.3k stars on Github. Airbnb and Node.js use Pug templating engine.&lt;/p&gt;

&lt;p&gt;Other popular templating engines include Jade, EJS, and Handlebars. &lt;a href="https://github.com/dscape/jade"&gt;Jade&lt;/a&gt; is a high-performance templating engine that is used for server-side rendering. &lt;a href="https://ejs.co/"&gt;EJS&lt;/a&gt; is a lightweight templating engine that is used for client-side and server-side rendering. &lt;a href="https://handlebarsjs.com/"&gt;Handlebars&lt;/a&gt; is a templating language that is based on the &lt;a href="https://mustache.github.io/"&gt;Mustache template language&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yOAts7zc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zo2vuf7zufvyltr2avct.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yOAts7zc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zo2vuf7zufvyltr2avct.png" alt="Templating Engines" width="800" height="561"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Finally
&lt;/h2&gt;

&lt;p&gt;In conclusion, the popularity of libraries and frameworks varies widely across different technologies and software development streams. However, by examining Github stars and usage by major companies, we can determine which libraries and frameworks are currently the most popular in each category. Although ChatGPT and AI are buzzwords in the software industry these days, it is important to note that a solid history of success and reliability for a tool is equally important. The number of stars on Github is a testament to this. React.js leads the way with &lt;strong&gt;209k stars&lt;/strong&gt;, followed closely by Vue.js with 204k stars, and then TensorFlow with 176k stars.&lt;/p&gt;




&lt;p&gt;If you liked this post, please take a moment to check out my other posts &lt;a href="https://tech.nagakonada.com/all-articles"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Evolution of Frontend Frameworks over the Last Decade</title>
      <dc:creator>Naga Chaitanya Konada</dc:creator>
      <pubDate>Thu, 02 Mar 2023 11:22:07 +0000</pubDate>
      <link>https://dev.to/chaituknag/evolution-of-frontend-frameworks-over-the-last-decade-84f</link>
      <guid>https://dev.to/chaituknag/evolution-of-frontend-frameworks-over-the-last-decade-84f</guid>
      <description>&lt;p&gt;Over the past decade, frontend frameworks have evolved significantly, providing developers with better tools and technologies to build dynamic and responsive web applications. In this video, we'll take a closer look at how frontend frameworks have changed and evolved over the years.&lt;/p&gt;

&lt;h2&gt;
  
  
  Early 2010s: jQuery and Backbone.js
&lt;/h2&gt;

&lt;p&gt;In the early 2010s, jQuery was the most popular frontend library used by developers to simplify DOM manipulation and event handling. It was widely used by developers due to its ease of use and the fact that it greatly simplified many of the complexities of Javascript. However, as web applications became more complex, developers began to realize that they needed a more structured approach to building web applications. This led to the development of Backbone.js, a lightweight framework that provided structure and organization to web applications. Backbone.js was designed to be more modular and scalable than jQuery, allowing developers to build large and complex web applications more easily. It provided a set of conventions for organizing code and encouraged the use of models, views, and collections to organize data and logic. This made it easier for developers to build complex applications with fewer errors and more maintainable code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mid-2010s: AngularJS and React
&lt;/h2&gt;

&lt;p&gt;In the mid-2010s, AngularJS and React emerged as two of the most popular frontend frameworks. AngularJS, developed by Google, provided developers with a complete solution for building large-scale web applications. It offered a lot of features out of the box, including two-way data binding and dependency injection. This allowed developers to build complex applications with ease. On the other hand, React, developed by Facebook, offered a more lightweight approach to building web applications. It utilized a virtual DOM to improve performance and scalability, making it a great choice for building modern web applications. Developers could easily create reusable components that could be shared between different parts of the application. This made it possible to build complex applications that were easy to maintain and scale. Overall, both AngularJS and React had their strengths and weaknesses, and developers had to choose the right tool for the job depending on the project requirements and their own preferences.&lt;/p&gt;

&lt;h2&gt;
  
  
  Late 2010s: Vue.js and Angular
&lt;/h2&gt;

&lt;p&gt;In the late 2010s, Vue.js and Angular emerged as two of the most popular frontend frameworks. Vue.js, a progressive framework, offered a more flexible and modular approach to building web applications. It allowed developers to easily integrate into existing applications, and offered a great deal of flexibility when working with templates, making it a popular choice for many developers. Angular, on the other hand, continued to evolve and improve, providing developers with a complete solution for building scalable and complex web applications. It's extensive set of features and tools allowed developers to quickly build large-scale applications that could easily handle high traffic and complex data manipulation. Additionally, Angular's strict adherence to object-oriented principles made it an attractive choice for enterprise-level applications, where maintainability and scalability were key concerns. Overall, while both Vue.js and Angular have their strengths and weaknesses, they continue to be two of the most popular and widely-used frontend frameworks in the world of web development.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion - who stood the test of time
&lt;/h2&gt;

&lt;p&gt;In terms of standing the test of time, Angular and React have emerged as the most popular and widely-used frontend frameworks. Angular's extensive set of features and tools make it a great choice for building large-scale applications, while React's lightweight approach and virtual DOM make it perfect for building modern web applications. Both frameworks have continued to evolve and improve, and they remain at the forefront of frontend development.&lt;/p&gt;

&lt;p&gt;However, Vue.js has also gained a considerable following since its introduction in the late 2010s. Its flexible and modular approach to building web applications, as well as its ease of integration with existing applications, has made it a popular choice for many developers. &lt;/p&gt;

&lt;p&gt;It's also worth mentioning that there are other frontend frameworks that have gained popularity in recent years, such as Svelte and Ember.js. While they may not have the same level of adoption as Angular, React, or Vue.js, they offer unique features and benefits that may be useful for certain projects. As frontend development continues to evolve, it will be interesting to see how these frameworks and others continue to grow and adapt to meet the needs of developers.&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>machinelearning</category>
      <category>ai</category>
      <category>ethics</category>
    </item>
    <item>
      <title>Renderprops vs Custom Hooks: Which one to use?</title>
      <dc:creator>Naga Chaitanya Konada</dc:creator>
      <pubDate>Wed, 01 Mar 2023 17:01:21 +0000</pubDate>
      <link>https://dev.to/chaituknag/renderprops-vs-custom-hooks-which-one-to-use-5a0</link>
      <guid>https://dev.to/chaituknag/renderprops-vs-custom-hooks-which-one-to-use-5a0</guid>
      <description>&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;React Hooks have revolutionized the way we write React components. They provide a way to reuse stateful logic across components, making our code more modular and easier to maintain. Two of the most commonly used techniques for reusing logic in React are renderprops and custom hooks. In this post, we'll explore the differences between renderprops and custom hooks, and when to use each one.&lt;/p&gt;

&lt;h3&gt;
  
  
  Renderprops
&lt;/h3&gt;

&lt;p&gt;Renderprops is a technique where a component accepts a function as a prop, which it then calls and passes some data to it. The function then returns some JSX, which the component renders. The main advantage of using renderprops is that it allows for a lot of flexibility in the way that data is passed between components. It's also a great way to share stateful logic between components without needing to use Redux or other state management libraries.&lt;/p&gt;

&lt;p&gt;For example, let's say that we have a component that fetches some data from an API and needs to render it. We could use a renderprop to pass the data to a child component:&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;function&lt;/span&gt; &lt;span class="nf"&gt;DataFetcher&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;children&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setData&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;setData&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;children&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;DisplayData&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;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;ul&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;data&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;item&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;li&lt;/span&gt; &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="si"&gt;}&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;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&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;li&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;ul&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;DataFetcher&lt;/span&gt; &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"https://api.example.com/data"&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;data&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;DisplayData&lt;/span&gt; &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;DataFetcher&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;In this example, we have a &lt;code&gt;DataFetcher&lt;/code&gt; component that fetches data from an API and passes it to its child component using a renderprop. The child component, &lt;code&gt;DisplayData&lt;/code&gt;, receives the data and renders it as a list.&lt;/p&gt;

&lt;h3&gt;
  
  
  Custom Hooks
&lt;/h3&gt;

&lt;p&gt;Custom hooks are functions that use React hooks to provide some reusable logic. They allow us to extract stateful logic from components and reuse it in other components. Custom hooks are great for encapsulating complex logic and making it easy to reuse across our application.&lt;/p&gt;

&lt;p&gt;For example, let's say that we have a component that needs to fetch some data from an API and update its state when the data changes. We could create a custom hook to handle the fetching logic:&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;function&lt;/span&gt; &lt;span class="nf"&gt;useData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setData&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;url&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;setData&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;url&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;data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;DisplayData&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;https://api.example.com/data&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&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;Loading...&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="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;ul&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;data&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;item&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;li&lt;/span&gt; &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="si"&gt;}&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;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&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;li&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;ul&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;DisplayData&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;In this example, we have a custom hook called &lt;code&gt;useData&lt;/code&gt; that fetches data from an API and returns it. We then use this hook in our &lt;code&gt;DisplayData&lt;/code&gt; component to fetch and display the data. This makes our &lt;code&gt;DisplayData&lt;/code&gt; component much simpler and easier to read.&lt;/p&gt;

&lt;h3&gt;
  
  
  When to use Renderprops vs Custom Hooks
&lt;/h3&gt;

&lt;p&gt;So, which one should you use? The answer is: it depends. Both renderprops and custom hooks have their own advantages and disadvantages, and the choice between them depends on the specific use case.&lt;/p&gt;

&lt;p&gt;Renderprops are great for passing data between components that aren't directly related. They allow for a lot of flexibility in the way that data is passed, and they're a good way to share stateful logic without requiring a lot of boilerplate code. On the other hand, renderprops can be difficult to read and understand, especially when you have a lot of nested components.&lt;/p&gt;

&lt;p&gt;Custom hooks are great for encapsulating complex logic and making it easy to reuse across your application. They're also very easy to use and understand, and they don't require any additional boilerplate code. However, custom hooks can only be used within a component, so they're not as flexible as renderprops.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In summary, both renderprops and custom hooks are powerful techniques for reusing logic in React. Renderprops are great for passing data between components, while custom hooks are great for encapsulating complex logic and making it easy to reuse across your application. The choice between them depends on the specific use case, so it's important to understand the advantages and disadvantages of each one. By using these techniques effectively, we can write more modular and maintainable code in React.&lt;/p&gt;

</description>
      <category>java</category>
      <category>code</category>
      <category>gratitude</category>
    </item>
    <item>
      <title>Animate on scroll in React</title>
      <dc:creator>Naga Chaitanya Konada</dc:creator>
      <pubDate>Sun, 14 Feb 2021 05:30:24 +0000</pubDate>
      <link>https://dev.to/chaituknag/animate-on-scroll-in-react-35e5</link>
      <guid>https://dev.to/chaituknag/animate-on-scroll-in-react-35e5</guid>
      <description>&lt;p&gt;Have you worked on animations in React? Do you think they are different from normal CSS animations? Are they difficult to achieve?&lt;/p&gt;

&lt;p&gt;Well, they are easy but they are not obvious. If you are good with CSS, then yeah you can animate things, but React plays with DOM nodes so differently that you may sometimes not get a level-ground to play with your CSS.&lt;/p&gt;

&lt;p&gt;This post does not go over the details of how you do animations in React. If you are looking for that, do let me know in the comments.&lt;/p&gt;

&lt;p&gt;This post tries to address a specific scenario: how to animate sections of your page into view as you scroll to those sections. &lt;/p&gt;

&lt;h1&gt;
  
  
  The challenge
&lt;/h1&gt;

&lt;p&gt;Product owners want the apps to be blazing fast. At the same time they want them to be beautiful and well designed and have a pleasant user experience. Sometimes depending on the type of web-site and the target consumers, that might mean that the app should contain some animations. &lt;/p&gt;

&lt;p&gt;Now writing up animations in plan HTML and CSS is quite easy because you are not dealing with involvement of JavaScript there. Browser understands CSS and converts the rules provided there to swift animations very easily.&lt;/p&gt;

&lt;p&gt;When you club the idea of blazing fast sites that still animate and do UI stuff, that is where things start to get a little tricky. You might go about using a modern framework like React (based things like Gatsby or Next.js) or Vue (or Angular, I know I know 😜). Now, each of these works differently and when it comes to animations they provide ways of achieving your required animations. All these ways are not quite as straight forward as working with CSS. To say the least, they do not scale well. Of course, since they are all JS based frameworks, you might get some flexibility and reusability but you always have the overhead of learning the methods recommended by these tools and these methods may not always suite your way.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One such scenario&lt;/strong&gt; is that you have a single column page with a bunch of sections and your product owner comes and tells you that these sections should not show up right away as static stuff. Instead their ask is that each of those sections should have some sort of fly-in animation (from left or right) and that they should animate when you scroll to them and not at the time the page loads. For our convenience, lets assume the project is built on React.&lt;/p&gt;

&lt;p&gt;How do you achieve this? &lt;/p&gt;

&lt;h1&gt;
  
  
  The solution for today
&lt;/h1&gt;

&lt;p&gt;Of course, we have many wonderful libraries that help with animations. Some of them are: &lt;a href="https://reactcommunity.org/react-transition-group/"&gt;react-transition-group&lt;/a&gt;, &lt;a href="https://www.react-spring.io/docs/hooks/basics"&gt;react-spring&lt;/a&gt;, &lt;a href="https://www.react-reveal.com/docs/"&gt;react-reveal&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Today, we will make use of something called &lt;a href="https://www.framer.com/api/motion/"&gt;framer-motion&lt;/a&gt;. I like this one particularly because it is very easy to use, you can achieve complex animations with simple configurations and you can animate between pages as well and my most favorite feature is exit animations. Exit animations are especially tricky because normally your component gets unmounted before the animation finishes (or even triggers) and achieving full animation is a little tricky whereas this tool allows us to specify exit animation as a prop which is cool.&lt;/p&gt;

&lt;p&gt;To achieve scroll based animations, we will leverage a capability in JavaScript called &lt;code&gt;IntersectionObserver&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Alright let's get started.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; that we are not dealing with dynamically loading components through &lt;code&gt;React.lazy&lt;/code&gt; or code-splitting or any of that stuff in this one. We have everything loaded on to the page up-front and we show them through an animation when user scrolls up to them.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;I will go over the solution by giving the step by step instructions so that you can follow. But if you are in a hurry, the TLDR; demo is &lt;a href="https://codesandbox.io/s/framer-motion-lazy-show-qx4qn?file=/src/App.js"&gt;here in codesandbox&lt;/a&gt;, you can take a look at it and may be copy paste stuff.&lt;/p&gt;

&lt;p&gt;Anyway, for the setup, go ahead and create a &lt;code&gt;create-react-app&lt;/code&gt; project or anything similar.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx create-react-app framer-motion-lazy-show
&lt;span class="c"&gt;# yarn create react-app framer-motion-lazy-show&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We need &lt;code&gt;framer-motion&lt;/code&gt; so go ahead and install it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i framer-motion
&lt;span class="c"&gt;# yarn add framer-motion&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Get started with the component
&lt;/h2&gt;

&lt;p&gt;Our hero is one component that handles revealing contents through a fade-in animation when user scrolls to it. Initially contents will be visibly hidden (notice contents are not unmounted).&lt;/p&gt;

&lt;p&gt;Lets create &lt;code&gt;LazyShow.js&lt;/code&gt; component with some boiler-plate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;LazyShow&lt;/span&gt; &lt;span class="o"&gt;=&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="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="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;lazy-div&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;childen&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All its doing at the moment is get the children and render them in a div with class &lt;code&gt;lazy-div&lt;/code&gt;. Lets style it a bit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.lazy-div&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c"&gt;/* height: 50vh; */&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;align-items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex-start&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;flex-direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;column&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.5em&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Font size is exaggerated here for demo purposes so that we see each of the LazyShow components occupy much of the view-port height. Alternatively we could have given a &lt;code&gt;height: 50vh;&lt;/code&gt; or &lt;code&gt;min-height: 80vh&lt;/code&gt; to make our point, but these styles do not affect the functionality of the component.&lt;/p&gt;

&lt;h2&gt;
  
  
  Add in the animation
&lt;/h2&gt;

&lt;p&gt;In order to make use of &lt;code&gt;framer-motion&lt;/code&gt; we would have to import &lt;code&gt;motion&lt;/code&gt; element and convert our normal &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt; to a &lt;code&gt;&amp;lt;motion.div&lt;/code&gt; component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;motion&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;framer-motion&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;Then we can specify the &lt;code&gt;initial&lt;/code&gt; and &lt;code&gt;animate&lt;/code&gt; props for our fade-in affect.&lt;/p&gt;

&lt;p&gt;So go ahead and update the JSX as so:&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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;motion&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;
  &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;lazy-div&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
  &lt;span class="nx"&gt;initial&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;
  &lt;span class="nx"&gt;animate&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;}}&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/motion.div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All we are saying is that initially the opacity of our child component is &lt;code&gt;0&lt;/code&gt; and as the animation finishes it becomes &lt;code&gt;1&lt;/code&gt;. Also we are moving the component using &lt;code&gt;x&lt;/code&gt; key, initially it will be &lt;code&gt;10px&lt;/code&gt; towards left (negative) and then it becomes &lt;code&gt;0&lt;/code&gt; which is its normal position. So essentially the whole contents would be fading in from the left.&lt;/p&gt;

&lt;p&gt;There is another concept in &lt;code&gt;framer-motion&lt;/code&gt; called variants, where you can specify &lt;code&gt;variants={fadeInVariants}&lt;/code&gt; and define &lt;code&gt;fadeInVariants&lt;/code&gt; with &lt;code&gt;initial&lt;/code&gt; and &lt;code&gt;animate&lt;/code&gt; keys to do the exact same thing. This &lt;code&gt;variants&lt;/code&gt; concept has the advantage of clean less-cluttered JSX. But we do not require that for this demo.&lt;/p&gt;

&lt;h2&gt;
  
  
  Preview the component
&lt;/h2&gt;

&lt;p&gt;Add a bunch of the &lt;code&gt;&amp;lt;LazyShow&amp;gt;&lt;/code&gt; in your &lt;code&gt;App.js&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;LazyShowWrapper&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="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;LazyShow&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nx"&gt;Lorem&lt;/span&gt; &lt;span class="nx"&gt;ipsum&lt;/span&gt; &lt;span class="nx"&gt;dolor&lt;/span&gt; &lt;span class="nx"&gt;sit&lt;/span&gt; &lt;span class="nx"&gt;amet&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;consectetur&lt;/span&gt; &lt;span class="nx"&gt;adipiscing&lt;/span&gt; &lt;span class="nx"&gt;elit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sed&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="nx"&gt;eiusmod&lt;/span&gt;
        &lt;span class="nx"&gt;tempor&lt;/span&gt; &lt;span class="nx"&gt;incididunt&lt;/span&gt; &lt;span class="nx"&gt;ut&lt;/span&gt; &lt;span class="nx"&gt;labore&lt;/span&gt; &lt;span class="nx"&gt;et&lt;/span&gt; &lt;span class="nx"&gt;dolore&lt;/span&gt; &lt;span class="nx"&gt;magna&lt;/span&gt; &lt;span class="nx"&gt;aliqua&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nx"&gt;Ut&lt;/span&gt; &lt;span class="nx"&gt;enim&lt;/span&gt; &lt;span class="nx"&gt;ad&lt;/span&gt; &lt;span class="nx"&gt;minim&lt;/span&gt;
        &lt;span class="nx"&gt;veniam&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;quis&lt;/span&gt; &lt;span class="nx"&gt;nostrud&lt;/span&gt; &lt;span class="nx"&gt;exercitation&lt;/span&gt; &lt;span class="nx"&gt;ullamco&lt;/span&gt; &lt;span class="nx"&gt;laboris&lt;/span&gt; &lt;span class="nx"&gt;nisi&lt;/span&gt; &lt;span class="nx"&gt;ut&lt;/span&gt; &lt;span class="nx"&gt;aliquip&lt;/span&gt; &lt;span class="nx"&gt;ex&lt;/span&gt; &lt;span class="nx"&gt;ea&lt;/span&gt;
        &lt;span class="nx"&gt;commodo&lt;/span&gt; &lt;span class="nx"&gt;consequat&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nx"&gt;Duis&lt;/span&gt; &lt;span class="nx"&gt;aute&lt;/span&gt; &lt;span class="nx"&gt;irure&lt;/span&gt; &lt;span class="nx"&gt;dolor&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;reprehenderit&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;voluptate&lt;/span&gt;
        &lt;span class="nx"&gt;velit&lt;/span&gt; &lt;span class="nx"&gt;esse&lt;/span&gt; &lt;span class="nx"&gt;cillum&lt;/span&gt; &lt;span class="nx"&gt;dolore&lt;/span&gt; &lt;span class="nx"&gt;eu&lt;/span&gt; &lt;span class="nx"&gt;fugiat&lt;/span&gt; &lt;span class="nx"&gt;nulla&lt;/span&gt; &lt;span class="nx"&gt;pariatur&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="nx"&gt;Excepteur&lt;/span&gt; &lt;span class="nx"&gt;sint&lt;/span&gt;
        &lt;span class="nx"&gt;occaecat&lt;/span&gt; &lt;span class="nx"&gt;cupidatat&lt;/span&gt; &lt;span class="nx"&gt;non&lt;/span&gt; &lt;span class="nx"&gt;proident&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sunt&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;culpa&lt;/span&gt; &lt;span class="nx"&gt;qui&lt;/span&gt; &lt;span class="nx"&gt;officia&lt;/span&gt; &lt;span class="nx"&gt;deserunt&lt;/span&gt;
        &lt;span class="nx"&gt;mollit&lt;/span&gt; &lt;span class="nx"&gt;anim&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="nx"&gt;est&lt;/span&gt; &lt;span class="nx"&gt;laborum&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/LazyShow&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/* add a bunch of these*/&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
   &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;LazyShowWrapper&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you would see in the preview that the component renders but immediately runs the animation and be done with it. That is not what we want.&lt;/p&gt;

&lt;h2&gt;
  
  
  Control animation start
&lt;/h2&gt;

&lt;p&gt;We should control when the animation starts. For that we can use the &lt;code&gt;useAnimation&lt;/code&gt; hook that &lt;code&gt;framer-motion&lt;/code&gt; provides and get the &lt;code&gt;controls&lt;/code&gt; module. Replace the &lt;code&gt;animate&lt;/code&gt; prop value with this &lt;code&gt;controls&lt;/code&gt; api and use the &lt;code&gt;controls.start&lt;/code&gt; function to start the animation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;motion&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useAnimation&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;framer-motion&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;Changed component looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;LazyShow&lt;/span&gt; &lt;span class="o"&gt;=&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;controls&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useAnimation&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;controls&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;duration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;ease&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;easeOut&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="nx"&gt;controls&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;motion&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;
      &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;lazy-div&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="nx"&gt;initial&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;
      &lt;span class="nx"&gt;animate&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;controls&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/motion.div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, with the above changes, the animation is controlled but it still triggers immediately after the component loads. We still want to control the animation to show when user scrolls to it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Listen to visibility (Intersection Observer)
&lt;/h2&gt;

&lt;p&gt;We can use the &lt;code&gt;useOnScreen&lt;/code&gt; hook available in &lt;a href="https://usehooks.com/useOnScreen/"&gt;here&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;useOnScreen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;rootMargin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;0px&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;isIntersecting&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setIntersecting&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;observer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;IntersectionObserver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;setIntersecting&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isIntersecting&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="p"&gt;},&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;rootMargin&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;observe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;unobserve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;current&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;isIntersecting&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;Quickly, what this hook is doing is taking a ref and root margin and maintaining an internal &lt;code&gt;isIntersecting&lt;/code&gt; state which becomes true when the ref is intersecting.&lt;/p&gt;

&lt;p&gt;Now let's update the &lt;code&gt;LazyShow&lt;/code&gt; component to leverage this new hook.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;LazyShow&lt;/span&gt; &lt;span class="o"&gt;=&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;controls&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useAnimation&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;rootRef&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useRef&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;onScreen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useOnScreen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rootRef&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;useEffect&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;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;onScreen&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;controls&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;start&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;duration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;ease&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;easeOut&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;onScreen&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;controls&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;motion&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;
      &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;lazy-div&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;rootRef&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="nx"&gt;initial&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt; &lt;span class="na"&gt;opacity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="p"&gt;}}&lt;/span&gt;
      &lt;span class="nx"&gt;animate&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;controls&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/motion.div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We leverage &lt;code&gt;useRef&lt;/code&gt; api to get the reference of our &lt;code&gt;motion.div&lt;/code&gt; that needs animation. We update the dependencies list of our only &lt;code&gt;useEffect&lt;/code&gt; to track the &lt;code&gt;onScreen&lt;/code&gt; boolean that is returned out of the &lt;code&gt;useOnScreen&lt;/code&gt; hook. &lt;/p&gt;

&lt;p&gt;So when the component comes into view, the &lt;code&gt;onScreen&lt;/code&gt; becomes true and the &lt;code&gt;useEffect&lt;/code&gt; executes and the animation starts.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;transition&lt;/code&gt; key in the &lt;code&gt;control.start&lt;/code&gt; call controls the duration of the animation and also the ease parameter.&lt;/p&gt;

&lt;p&gt;This is the final change. Now you can see that the component shows up with the animation when user scrolls to it.&lt;/p&gt;

&lt;p&gt;The solution demo is here:&lt;br&gt;
&lt;iframe src="https://codesandbox.io/embed/qx4qn?runonclick=1"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;There are many ways to achieve the same effect. Did you try something else previously? Let me know how it worked out for you. I would like to know your feedback. Do you want me to create a post on anything else? Do let me know.&lt;/p&gt;

</description>
      <category>react</category>
      <category>framer</category>
      <category>scroll</category>
      <category>animation</category>
    </item>
    <item>
      <title>How to check if you are in an iFrame</title>
      <dc:creator>Naga Chaitanya Konada</dc:creator>
      <pubDate>Mon, 16 Nov 2020 14:51:33 +0000</pubDate>
      <link>https://dev.to/chaituknag/how-to-check-if-you-are-in-an-iframe-17e8</link>
      <guid>https://dev.to/chaituknag/how-to-check-if-you-are-in-an-iframe-17e8</guid>
      <description>&lt;p&gt;What if you want to check if your page is hosted in an i-frame and may be prevent certain features?&lt;/p&gt;

&lt;p&gt;On the network side, you can pass a response header from your server that looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;X-Frame-Options: DENY
X-Frame-Options: SAMEORIGIN
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;X-Frame-Options: DENY&lt;/code&gt; header prevents your page to be accessed in an i-frame altogether.&lt;/p&gt;

&lt;p&gt;Whereas, the &lt;code&gt;X-Frame-Options: SAMEORIGIN&lt;/code&gt; header allows the page to load if the parent (wrapping window) of the i-frame is of the same origin, which is somewhat OK.&lt;/p&gt;

&lt;p&gt;But if you do not have a header provided by your server and you still want to check if you are inside an i-frame, you may do the following conditional check.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(window.location === window.parent.location) {
  // you are not inside an i-frame
} else {
  // you are definitely inside an i-frame
}

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

&lt;/div&gt;



&lt;p&gt;Alright, I hope this helps.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options"&gt;https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options&lt;/a&gt;&lt;br&gt;
&lt;a href="https://tommcfarlin.com/check-if-a-page-is-in-an-iframe/"&gt;https://tommcfarlin.com/check-if-a-page-is-in-an-iframe/&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>JavaScript execution context (this)</title>
      <dc:creator>Naga Chaitanya Konada</dc:creator>
      <pubDate>Sun, 18 Oct 2020 16:20:12 +0000</pubDate>
      <link>https://dev.to/chaituknag/javascript-execution-context-this-3512</link>
      <guid>https://dev.to/chaituknag/javascript-execution-context-this-3512</guid>
      <description>&lt;p&gt;There is a &lt;a href="https://www.youtube.com/playlist?list=PL0-gUIpqQtepykqScEQFSmh9yonEl2iHc"&gt;YouTube playlist&lt;/a&gt; that I did explaining the whole concept mentioned in this article, if you are that person who wants to watch and learn, please head on there.&lt;/p&gt;

&lt;h1&gt;
  
  
  The agenda
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Talk about the execution context&lt;/li&gt;
&lt;li&gt;About &lt;code&gt;use strict&lt;/code&gt; and global &lt;code&gt;this&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Where to define a function

&lt;ul&gt;
&lt;li&gt;Does location matter for functions&lt;/li&gt;
&lt;li&gt;Putting a function in an object literal&lt;/li&gt;
&lt;li&gt;Inside a method function&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;How to invoke a function

&lt;ul&gt;
&lt;li&gt;Normal function invocation&lt;/li&gt;
&lt;li&gt;Method invocation&lt;/li&gt;
&lt;li&gt;Explicit binding invocation&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;How arrow functions differ

&lt;ul&gt;
&lt;li&gt;Where to declare the arrow functions&lt;/li&gt;
&lt;li&gt;How to invoke them&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Conclusion

&lt;ul&gt;
&lt;li&gt;Recap differences between using &lt;code&gt;use effect&lt;/code&gt; and not&lt;/li&gt;
&lt;li&gt;Different types of invocations&lt;/li&gt;
&lt;li&gt;Location of a normal function&lt;/li&gt;
&lt;li&gt;Arrow functions invocation and location&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  What is &lt;code&gt;this&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;The &lt;code&gt;this&lt;/code&gt; keyword refers to the object that a function gets based on how it is invoked. For arrow functions, it refers to the &lt;code&gt;this&lt;/code&gt; context that gets assigned to the enclosing function.&lt;/p&gt;

&lt;p&gt;depends on&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;whether you used &lt;code&gt;use strict&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;how the function is invoked&lt;/li&gt;
&lt;li&gt;where the function is declared&lt;/li&gt;
&lt;li&gt;whether it is an arrow function or now&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  About &lt;code&gt;use strict&lt;/code&gt; and &lt;code&gt;this&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;When you use &lt;code&gt;this&lt;/code&gt; in global scope, it refers to the window object in a browser. It refers to &lt;code&gt;globalThis&lt;/code&gt; when in Node.js environment.&lt;/p&gt;

&lt;p&gt;But if you use strict mode (by putting &lt;code&gt;use strict&lt;/code&gt; at the beginning of your file), then you will not get window object when you use &lt;code&gt;this&lt;/code&gt;. In fact it points to &lt;code&gt;undefined&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use strict&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Where to define a function
&lt;/h1&gt;

&lt;p&gt;In modern JavaScript development, we generally tend to put functions in their own files, thanks to the JavaScrpt ES6 modules, CommonJS pattern and many other techniques that work towards using per-file concept.&lt;/p&gt;

&lt;p&gt;But we are not touching the module system or the &lt;code&gt;import&lt;/code&gt; and &lt;code&gt;export&lt;/code&gt; feature of ES6. In this series, we are only concerned about the question of whether a function is declared outside another function or not.&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;function&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;naga&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remove duplicate function declaration:&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;function&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;naga&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Location does not matter when it comes to using the &lt;code&gt;this&lt;/code&gt; context:&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;// foo.js&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&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="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// bar.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;foo&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;./foo.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;naga&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// prints obj&lt;/span&gt;
&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// prints window&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;invoking a member method without the object&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;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;naga&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Putting a function inside a method&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;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;naga&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;obj&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;bar&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;barFunc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nx"&gt;barFunc&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Ways to invoke a function
&lt;/h1&gt;

&lt;p&gt;normal invocation&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;function&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&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="c1"&gt;// global or window&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;method invocation&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;function&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&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="c1"&gt;// points to obj&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;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// prints obj&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;explicit binding&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;function&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&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="c1"&gt;// normally prints global or window&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;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&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;boundFoo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;boundFoo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// prints obj coz of the binding&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;using call or apply&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;function&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&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="c1"&gt;// normally prints global or window&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;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// prints obj coz of the binding&lt;/span&gt;
&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// prints obj coz of the binding&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;call vs apply&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;math&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;add&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arguments&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;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;num&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;thisArg&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&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;add5&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;thisArg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// returns a curried function&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;add5&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// 15&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;thisArg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt; &lt;span class="c1"&gt;// 15&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;add&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;thisArg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;]));&lt;/span&gt; &lt;span class="c1"&gt;// 15&lt;/span&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Fixing sub-function problem
&lt;/h2&gt;

&lt;p&gt;the problem&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;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;naga&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;obj&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;bar&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;barFunc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nx"&gt;barFunc&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;using scope&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;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;naga&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nb"&gt;self&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="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// oh yeah works&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// always true&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;bar&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;barFunc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nx"&gt;barFunc&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;using explicit binding&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;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;naga&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;obj&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;bar&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;barFunc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;barFuncBound&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;barFunc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;barFuncBound&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// now it works --&amp;gt; true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  How arrow functions differ from normal functions regarding &lt;code&gt;this&lt;/code&gt;
&lt;/h1&gt;

&lt;p&gt;We know normal functions take the &lt;code&gt;this&lt;/code&gt; context based on how they are invoked and &lt;strong&gt;not&lt;/strong&gt; based on where they are declared*.*&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Arrow functions&lt;/em&gt;&lt;/strong&gt; take the &lt;code&gt;this&lt;/code&gt; context based on where they are declared and &lt;strong&gt;not&lt;/strong&gt; based on how they are invoked.&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;foo&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// true, so not bound to obj even though it is a method&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;objFooBound&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;objFooBound&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// true, still points to window, bind fails&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fooBound&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;fooBound&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// still true, bind fails&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  What if we declare in a function
&lt;/h2&gt;

&lt;p&gt;Now the arrow function totally obeys the enclosing scope's &lt;code&gt;this&lt;/code&gt; context because it is declared inside it.&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;function&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bar&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nx"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// true, enclosing function is called in the normal way&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;baz&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// now false, enclosing function called using method invocation&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;boundFoo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;({});&lt;/span&gt;
&lt;span class="nx"&gt;boundFoo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// now also false, enclosing function bound to an object&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  visiting our old example
&lt;/h3&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;obj&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;naga&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bar&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// true, now it takes context of the foo method &lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// obviously true&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;bar&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;bar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;foo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;span class="nx"&gt;bar&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this fixes the problem of having functions inside methods of an object. you may use arrow functions.&lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Declare normal functions anywhere, just not inside the object methods&lt;/li&gt;
&lt;li&gt;Use arrow functions for functions inside methods&lt;/li&gt;
&lt;li&gt;You can invoke normal functions in three ways: normal way, as an object method and by explicitly binding&lt;/li&gt;
&lt;li&gt;Arrow functions do not care how you invoke them, all they care is where they are declared.&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;use strict&lt;/code&gt; to avoid accidentally putting stuff in the global context (window or globalThis)&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>frontend</category>
      <category>execution</category>
      <category>context</category>
    </item>
    <item>
      <title>Blog post layout using CSS grids</title>
      <dc:creator>Naga Chaitanya Konada</dc:creator>
      <pubDate>Sat, 03 Oct 2020 14:48:42 +0000</pubDate>
      <link>https://dev.to/chaituknag/blog-post-layout-using-css-grids-3ioo</link>
      <guid>https://dev.to/chaituknag/blog-post-layout-using-css-grids-3ioo</guid>
      <description>&lt;h1&gt;
  
  
  Recap
&lt;/h1&gt;

&lt;p&gt;Welcome back!&lt;/p&gt;

&lt;p&gt;In the last &lt;a href="https://dev.to/chaituknag/blog-post-layout-using-css-flexbox-383j"&gt;article&lt;/a&gt;, I explained how I tried to achieve a typical blog-post layout using &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox" rel="noopener noreferrer"&gt;&lt;code&gt;flexbox&lt;/code&gt;&lt;/a&gt;. Here is the &lt;a href="https://cdpn.io/chaituknag/debug/PoNvXmJ/bZrQWERaDgyk" rel="noopener noreferrer"&gt;link to the final layout&lt;/a&gt; in CodePen.&lt;/p&gt;

&lt;p&gt;I mentioned that there were a couple of hacks we had to do to make it work, because of the way flexbox works. It is unidirectional in nature, which means, at any time you can only affect the layout in one direction, row or column. If you wish to make a complex layout with sections spanning across multiple rows and columns in a random fashion, then the best option (and somewhat of the only option) is CSS grids.&lt;/p&gt;

&lt;p&gt;The last time I checked the compatibility for CSS grid layout in &lt;a href="https://caniuse.com/css-grid" rel="noopener noreferrer"&gt;CanIUse.com&lt;/a&gt;, it is hovering around 95%. It is a very good coverage, you can confidently use CSS grids for your layout needs and this number will only become better going forward.&lt;/p&gt;

&lt;p&gt;So, why don't we go ahead and implement the same layout in CSS grids? &lt;/p&gt;

&lt;h1&gt;
  
  
  Final result
&lt;/h1&gt;

&lt;p&gt;Just like the previous one, we achieve the same UI, no difference at all. But internally, it is a lot cleaner and easy to understand.&lt;/p&gt;

&lt;p&gt;Here is the &lt;a href="https://codepen.io/chaituknag/pen/zYqQyoV" rel="noopener noreferrer"&gt;codepen&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/chaituknag/embed/zYqQyoV?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h1&gt;
  
  
  Demo
&lt;/h1&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%2F6nm1gv0r8rgxdozm5zta.gif" 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%2F6nm1gv0r8rgxdozm5zta.gif" alt="blog-article-layout-using-css-grid"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is it, that is what we get. Not so much different from the previous &lt;a href="https://codepen.io/chaituknag/pen/PoNvXmJ?editors=0100" rel="noopener noreferrer"&gt;flexbox example&lt;/a&gt;, much simpler internally.&lt;/p&gt;

&lt;h1&gt;
  
  
  Let's look at the improvements
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Addressing the double &lt;code&gt;h1&lt;/code&gt; problem
&lt;/h2&gt;

&lt;p&gt;We have done some structural changes to the HTML. It no longer has two &lt;code&gt;h1&lt;/code&gt;s, which is good for our SEO stuff and semantics.&lt;/p&gt;

&lt;p&gt;Now the structure looks like this:&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;!-- content wrapper --&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- the h1 title --&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- the left nav --&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- the reading column --&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;&amp;lt;!-- content wrapper ends --&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is so much simpler than the one in &lt;code&gt;flexbox&lt;/code&gt; version. &lt;/p&gt;

&lt;p&gt;We use the beauty of CSS grids and specifically &lt;code&gt;grid-template-areas&lt;/code&gt; property to achieve our desired layouts, both in desktop and mobile views.&lt;/p&gt;

&lt;p&gt;To make grids work, we apply &lt;code&gt;display: grid&lt;/code&gt; to the root level &lt;code&gt;.content-wrapper&lt;/code&gt; div.&lt;/p&gt;

&lt;p&gt;Unlike flexbox which might require multiple parent divs to achieve complex layouts, the grid system does require only one parent div and all the sections can be immediate children of that parent.&lt;/p&gt;

&lt;p&gt;Lets see the magic of &lt;code&gt;grid-template-areas&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  In desktop view:
&lt;/h2&gt;

&lt;p&gt;The content wrapper div looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.title&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-area&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;title&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="err"&gt;//&lt;/span&gt; &lt;span class="err"&gt;this&lt;/span&gt; &lt;span class="err"&gt;is&lt;/span&gt; &lt;span class="err"&gt;the&lt;/span&gt; &lt;span class="err"&gt;grid&lt;/span&gt; &lt;span class="err"&gt;area&lt;/span&gt; &lt;span class="err"&gt;label&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.left-nav&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-area&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;leftnav&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;relative&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.reading-column&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;grid-area&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;reading&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.content-wrapper&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;grid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-gap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;2rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-areas&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="s1"&gt;". title"&lt;/span&gt;
    &lt;span class="s1"&gt;"leftnav reading"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;minmax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;250px&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&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;We firstly provide &lt;code&gt;grid-area&lt;/code&gt; label to each of the siblings and use those names in &lt;code&gt;grid-template-areas&lt;/code&gt; rule of the parent to decide the layout.&lt;/p&gt;

&lt;p&gt;There are two strings in the value of &lt;code&gt;grid-template-areas&lt;/code&gt;, they represent two rows. And the contents of each string represent the columns. Each string has two tokens, so two columns each.&lt;/p&gt;

&lt;p&gt;So, the first row has nothing in the first column (because &lt;code&gt;.&lt;/code&gt; represents nothing) and has the &lt;code&gt;header&lt;/code&gt; in the second column.&lt;/p&gt;

&lt;p&gt;The second row has the &lt;code&gt;leftnav&lt;/code&gt; in the first column space and the &lt;code&gt;reading&lt;/code&gt; section in the second column space. &lt;/p&gt;

&lt;p&gt;This is what we want.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mobile view:
&lt;/h2&gt;

&lt;p&gt;Now lets look at the &lt;code&gt;grid-template-areas&lt;/code&gt; value in case of mobile view:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="n"&gt;only&lt;/span&gt; &lt;span class="n"&gt;screen&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;900px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;.content-wrapper&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;grid-template-areas&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="s1"&gt;"title"&lt;/span&gt;
      &lt;span class="s1"&gt;"leftnav"&lt;/span&gt;
      &lt;span class="s1"&gt;"reading"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&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;Here there are three strings, so three rows. And each string has only one token, so only one column. As simple as that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Controlling width of the left nav section
&lt;/h2&gt;

&lt;p&gt;Notice this line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.content-wrapper&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="err"&gt;...&lt;/span&gt;
  &lt;span class="py"&gt;grid-template-columns&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;minmax&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;250px&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="m"&gt;3&lt;/span&gt;&lt;span class="n"&gt;fr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="err"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is a function we are using here called &lt;code&gt;minmax&lt;/code&gt;. What this does is it fixes the minimum and maximum width values for each column (since it is &lt;code&gt;grid-template-columns&lt;/code&gt;). In this particular case, we want the first column of the &lt;code&gt;.content-wrapper&lt;/code&gt; to have a minimum of &lt;code&gt;250px&lt;/code&gt; and a maximum of &lt;code&gt;1fr&lt;/code&gt;. &lt;code&gt;1fr&lt;/code&gt; means one fraction.&lt;/p&gt;

&lt;p&gt;The second column has 3fr always (no &lt;code&gt;minmax&lt;/code&gt; applied), so as long as the total width of &lt;code&gt;.content-wrapper&lt;/code&gt; is such that the total fractions (1fr + 3fr = 4fr) is more than 4 times 250px, the width of the leftnav column will be that much (total width / 4). But as soon as that becomes 250px or less, the leftnav takes up 250px and the rest is divided to three fractions (3fr).&lt;/p&gt;

&lt;p&gt;So, when the overall width is 1200px, the left column width is 1fr (out of 4fr) which is 1/4 of 1200px which is 300px. &lt;/p&gt;

&lt;p&gt;Whereas when the overall width is just 900px, the leftnav takes up 250px and the reading section width is 650px (900 - 250).&lt;/p&gt;

&lt;p&gt;Summing up, you can notice that the size of the leftnav increases slightly as you keep increasing the window width.&lt;/p&gt;

&lt;p&gt;In the mobile view, there is only one column and all the rows have &lt;code&gt;1fr&lt;/code&gt; width, so they occupy complete width.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reading column width
&lt;/h2&gt;

&lt;p&gt;There are &lt;code&gt;.reading-column__section&lt;/code&gt;s within the reading column and thanks to the below rules, the maximum width of these sections does not exceed &lt;code&gt;60ch&lt;/code&gt; even though the column itself is spanning till the right side edge.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.reading-column__section&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;60ch&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;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;If you are new to flexbox and grids in CSS, it is high time you learn them. There are many good resources for you to understand them. The browser support is getting better and better. &lt;/p&gt;

&lt;p&gt;Please do suggest if you want me to achieve any other feature in this particular example. Or if you like it, please let me know what you learned.&lt;/p&gt;

&lt;p&gt;Subscribe to my &lt;a href="https://www.youtube.com/channel/UCl5dc2m9rRGZsAu04ytfDjw/featured?view_as=subscriber" rel="noopener noreferrer"&gt;&lt;strong&gt;YouTube channel&lt;/strong&gt;&lt;/a&gt; for many such developer tips.&lt;/p&gt;

</description>
      <category>html</category>
      <category>css</category>
      <category>grid</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Blog post layout using CSS flexbox</title>
      <dc:creator>Naga Chaitanya Konada</dc:creator>
      <pubDate>Thu, 01 Oct 2020 08:10:46 +0000</pubDate>
      <link>https://dev.to/chaituknag/blog-post-layout-using-css-flexbox-383j</link>
      <guid>https://dev.to/chaituknag/blog-post-layout-using-css-flexbox-383j</guid>
      <description>&lt;h1&gt;
  
  
  Intro
&lt;/h1&gt;

&lt;p&gt;Lately, I have been thinking a lot about CSS. It is so wonderful how far CSS has come along. Browser support is awesome for new features like Flexbox and Grids in CSS. &lt;/p&gt;

&lt;p&gt;When you think about creating complex layouts, it is no longer a dread or nightmare. Rather, it is just fun to create them, isn't it?&lt;/p&gt;

&lt;p&gt;So, why not get our feet wet and start off by creating some layouts on our own. Along the way, why not learn a new concept or two!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The best way to learn is to write code.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Final result
&lt;/h1&gt;

&lt;p&gt;This is what we are building today. This is a typical layout when you come across blog article layouts.&lt;/p&gt;

&lt;p&gt;There is a header, a page navigation section and the rest of the page contains sections, each with a section header and some content.&lt;/p&gt;

&lt;p&gt;Now, in larger screen sizes, the layout can split into two columns, the left column being the table of contents and the right column is the sections content.&lt;/p&gt;

&lt;p&gt;I made the table of contents floating when you scroll the page so that it is always visible for you, very typical these days.&lt;/p&gt;

&lt;p&gt;Also, according to &lt;a href="https://www.youtube.com/user/KepowOb"&gt;Kevin Powell&lt;/a&gt; (watch &lt;a href="https://youtu.be/dgbFtMBOMlA"&gt;this video&lt;/a&gt;, it is awesome), we need to limit the total width of the text column to be a max of &lt;code&gt;60ch&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/chaituknag/embed/PoNvXmJ?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h1&gt;
  
  
  Demo
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Bk0UxPHG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/49mqbx1cgmns67nlek3b.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Bk0UxPHG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/49mqbx1cgmns67nlek3b.gif" alt="blog-article-layout-using-css-flexbox"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Lets kick it off
&lt;/h1&gt;

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

&lt;p&gt;For the rest of the tutorial, we will be working towards the above code.&lt;/p&gt;

&lt;h2&gt;
  
  
  The all important template
&lt;/h2&gt;

&lt;p&gt;Go ahead and start your coding, create an empty html 5 document and create the default structure.&lt;/p&gt;

&lt;p&gt;It looks something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1.0"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Document&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;TIP: You can get the above structure in VSCode (thanks to Emmet) by typing &lt;code&gt;!&lt;/code&gt; and hitting tab in a new HTML file&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The most important line in the above code is the meta viewport tag. It should have the &lt;code&gt;width=device-width&lt;/code&gt; and &lt;code&gt;initial-scale=1.0&lt;/code&gt; to make responsive stuff work in mobile views.&lt;/p&gt;

&lt;h2&gt;
  
  
  A little bit about the structure
&lt;/h2&gt;

&lt;p&gt;We have a page title, a navigation section and some content sections.&lt;/p&gt;

&lt;p&gt;In the desktop view, we want to display the page title aligning to the content sections column. We want the navigation section towards the left.&lt;/p&gt;

&lt;p&gt;In the mobile view, we want them all to be in a single column, but the left navigation should now go in between the page title and the sections.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem with this layout
&lt;/h2&gt;

&lt;p&gt;You might think, the markup structure should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- page title h1 --&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;&amp;lt;!-- left nav list --&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;&amp;lt;!-- content sections --&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The problem with this is very simple. How would you get only the left nav and content sections to be in two columns in the desktop layout?&lt;/p&gt;

&lt;p&gt;Now you can do it like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- page title h1 --&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;&amp;lt;!-- two column wrapper --&amp;gt;&lt;/span&gt;
   &lt;span class="c"&gt;&amp;lt;!-- left nav list --&amp;gt;&lt;/span&gt;
   &lt;span class="c"&gt;&amp;lt;!-- content sections --&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;&amp;lt;!-- two column wrapper ends --&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The above layout works fine now, you can toggle the layout of the two column wrapper div to be two column or single column layout based on view port widths.&lt;/p&gt;

&lt;p&gt;But the &lt;strong&gt;big problem&lt;/strong&gt; is that the page title will not align with the content sections in the desktop view. Instead it will always be on the left side. Now, as a hack, you may use some javascript to find out the width of the left nav and add left margin to the page title when the viewport width changes. This is kind of hack-ey.&lt;/p&gt;

&lt;p&gt;What I would do instead is, to use two headings in two different locations and show-hide them based on the layout.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="c"&gt;&amp;lt;!-- page title h1 (for mobile) --&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;&amp;lt;!-- two column wrapper --&amp;gt;&lt;/span&gt;
   &lt;span class="c"&gt;&amp;lt;!-- left nav list --&amp;gt;&lt;/span&gt;
   &lt;span class="c"&gt;&amp;lt;!-- reading column --&amp;gt;&lt;/span&gt;
      &lt;span class="c"&gt;&amp;lt;!-- page title h1 (for desktop) --&amp;gt;&lt;/span&gt;
      &lt;span class="c"&gt;&amp;lt;!-- content sections --&amp;gt;&lt;/span&gt;
   &lt;span class="c"&gt;&amp;lt;!-- reading column ends --&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;&amp;lt;!-- two column wrapper ends --&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  The markup
&lt;/h2&gt;

&lt;p&gt;Here is how the markup looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Lorem ipsum dolor sit amet&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"content-wrapper"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;nav&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"left-nav"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ul&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"left-nav__list"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"left-nav__list-item"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"#"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"left-nav__link"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Lorem ipsum dolor.&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
      &lt;span class="c"&gt;&amp;lt;!-- rest of the links--&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/nav&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"reading-column"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h1&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Lorem ipsum dolor sit amet&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"reading-column__section"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;h2&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"reading-column__title"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Lorem ipsum dolor sit amet, consectetur.&lt;span class="nt"&gt;&amp;lt;/h2&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"reading-column__desc"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eius est tenetur possimus ipsum. Nostrum nobis odit delectus et excepturi, quis repudiandae facere, expedita dignissimos, quo nihil? Veritatis, voluptates expedita corporis earum esse illo ipsa vitae ab. Molestiae officiis officia aut? Explicabo earum quis officia quo eligendi eveniet reprehenderit sint dolores?&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- rest of the sections --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Notice, there are two h1 tags, one at the root level (inside &lt;code&gt;body&lt;/code&gt;), the other one inside the &lt;code&gt;.reading-column&lt;/code&gt; div. &lt;/p&gt;

&lt;p&gt;I know, you might be thinking - two &lt;code&gt;h1&lt;/code&gt;s inside the markup, is it like violating the SEO rules or something? Yes it kind of does. But at least we got one h1 right up in the markup. Do you think there is a better way? Leave a comment plz.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lets dive into the CSS
&lt;/h2&gt;

&lt;p&gt;Now, having consistent CSS is every FE guy's dream, right? The important thing to take care up front for this is to have some CSS resets.&lt;/p&gt;

&lt;p&gt;This is what I start with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;box-sizing&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;border-box&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.2rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;img&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&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;Now, the &lt;code&gt;font-family&lt;/code&gt;, &lt;code&gt;font-size&lt;/code&gt; and &lt;code&gt;margin&lt;/code&gt; are optional, but I included them anyway. The most important ones are &lt;code&gt;box-sizing&lt;/code&gt; and image &lt;code&gt;width&lt;/code&gt;. Of course, there are many more resets you can do.&lt;/p&gt;

&lt;h3&gt;
  
  
  Image width thing:
&lt;/h3&gt;

&lt;p&gt;By default, all &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt;s are displayed &lt;code&gt;inline-block&lt;/code&gt; and so if the width of the image is bigger, it will overflow towards right creating a horizontal scrollbar.&lt;/p&gt;

&lt;p&gt;So, we set the &lt;code&gt;width&lt;/code&gt; to &lt;code&gt;100%&lt;/code&gt; to fix that issue.&lt;/p&gt;

&lt;p&gt;See this &lt;a href="https://codepen.io/chaituknag/pen/RwamdMN"&gt;codepen&lt;/a&gt; to see the issue.&lt;/p&gt;

&lt;h3&gt;
  
  
  Maximum width 60ch:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bYa5UpLT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/a4td2o5z07t0yafm8yuc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bYa5UpLT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/a4td2o5z07t0yafm8yuc.png" alt="Screenshot 2020-09-30 at 10.04.47 PM"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As I mentioned earlier, there is a psychological thing that says a line should contain a max of 60 letters in a line for the comfort of the eyes and for the sake of not losing interest.&lt;/p&gt;

&lt;h3&gt;
  
  
  Making two columns work:
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;By default all HTML content without additional CSS is &lt;code&gt;single column&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then how do we make it two columns? We use &lt;code&gt;@media&lt;/code&gt; queries (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/@media"&gt;MDN&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;There are two main approaches to writing media queries. &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;desktop first approach&lt;/strong&gt;: When you write CSS for desktop version and then write just the media queries for mobile version.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;mobile first approach&lt;/strong&gt;: When you write CSS for mobile version first and then write just the media queries for desktop version.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The common thing with both approaches is that you always override some rules you wrote above in your file.&lt;/p&gt;

&lt;p&gt;In our example, we are using desktop first approach, no particular reason.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;.content-wrapper&lt;/code&gt; div holds two sections, the &lt;code&gt;.left-nav&lt;/code&gt; and the &lt;code&gt;.reading-column&lt;/code&gt;. In desktop, in order to make them two columns, we just give &lt;code&gt;display: flex&lt;/code&gt; to the &lt;code&gt;.content-wrapper&lt;/code&gt; parent. They immediately become two columns, why?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;When you use &lt;code&gt;display: flex&lt;/code&gt;, by default the layout becomes horizontal. All the immediate children become individual columns. This is because by default, &lt;code&gt;flex-direction&lt;/code&gt; is &lt;code&gt;row&lt;/code&gt; in flexbox (&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox"&gt;MDN&lt;/a&gt;).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now, We achieved two columns. Next thing is page title alignment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Making page title work:
&lt;/h3&gt;

&lt;p&gt;We wanted the main title of the page to align with the second column (content column), right? So how do we achieve that?&lt;/p&gt;

&lt;p&gt;Well, if you just want to use CSS and no JS, you have very little choice with Flexbox. In a future post, we will cover CSS grids which solve this issue very easily.&lt;/p&gt;

&lt;p&gt;For now, what we do is that we create a duplicate &lt;code&gt;h1&lt;/code&gt; tag and copy that inside the &lt;code&gt;.reading-column&lt;/code&gt; div. This allows us the ability to hide and show based on layout.&lt;/p&gt;

&lt;p&gt;In desktop view, we hide the original page title and show the one inside &lt;code&gt;.reading-column&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.title&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.reading-column&lt;/span&gt; &lt;span class="nc"&gt;.title&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;block&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;In mobile view (@media query), we do the opposite:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="n"&gt;only&lt;/span&gt; &lt;span class="n"&gt;screen&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;900px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;.title&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nc"&gt;.reading-column&lt;/span&gt; &lt;span class="nc"&gt;.title&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&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;There you go, our title is now aligning properly with respect to the content column.&lt;/p&gt;

&lt;h3&gt;
  
  
  Lets take care of left-nav
&lt;/h3&gt;

&lt;p&gt;There are a couple of things to take care here:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;In desktop layout, the top of the first left-nav link should align with the first title of the content sections. If not, it would look awkward because the left nav goes all the way up, nudging beside the page title.&lt;/li&gt;
&lt;li&gt;In desktop layout, I wish to have the left navigation floating when the user scrolls so that they can have an idea where to go next.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For the first issue, we simply manage the &lt;code&gt;margin-top&lt;/code&gt; of the &lt;code&gt;.left-nav&lt;/code&gt;. Now, you have to try out the alignment by changing the &lt;code&gt;margin-top&lt;/code&gt; till you see it properly aligned. For my layout, it worked at &lt;code&gt;5rem&lt;/code&gt; so I kept that.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.left-nav&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="err"&gt;other&lt;/span&gt; &lt;span class="err"&gt;rules&lt;/span&gt;
    &lt;span class="nl"&gt;margin-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5rem&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="err"&gt;other&lt;/span&gt; &lt;span class="err"&gt;rules&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;We reset this back to &lt;code&gt;0&lt;/code&gt; in the media query because we do not want this kind of margin in mobile view.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="n"&gt;only&lt;/span&gt; &lt;span class="n"&gt;screen&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;900px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nt"&gt;other&lt;/span&gt; &lt;span class="nt"&gt;rules&lt;/span&gt;
    &lt;span class="nc"&gt;.left-nav&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="err"&gt;other&lt;/span&gt; &lt;span class="err"&gt;left-nav&lt;/span&gt; &lt;span class="err"&gt;rules&lt;/span&gt;
        &lt;span class="nl"&gt;margin-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="err"&gt;other&lt;/span&gt; &lt;span class="err"&gt;left-nav&lt;/span&gt; &lt;span class="err"&gt;rules&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="nt"&gt;other&lt;/span&gt; &lt;span class="nt"&gt;rules&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Achieving floating left nav in desktop
&lt;/h3&gt;

&lt;p&gt;This is a cool feature isn't it? To be able to see the page links all the time in the desktop view?&lt;/p&gt;

&lt;p&gt;To achieve this, we have to use a cool feature called &lt;code&gt;position: sticky&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Thanks to flexbox, We already have the &lt;code&gt;.left-nav&lt;/code&gt; stretching from top to bottom in desktop view. This is because, by default, the &lt;code&gt;align-items&lt;/code&gt; rule defaults to &lt;code&gt;stretch&lt;/code&gt;. Check &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox"&gt;MDN&lt;/a&gt; to learn more about this.&lt;/p&gt;

&lt;p&gt;Now, all we have to do is target the &lt;code&gt;.left-nav__list&lt;/code&gt; and do the position related changes.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note about positioning: In order for this to work, we have to make sure our &lt;code&gt;.left-nav&lt;/code&gt; should have a &lt;code&gt;position&lt;/code&gt; value other than the default one. Because, the child with a position value of &lt;code&gt;sticky&lt;/code&gt; will always look for its immediate parent in the hierarchy that has its own stacking context. In other words, it will look for the parent that has &lt;code&gt;position&lt;/code&gt; as one of these: [sticky, fixed, absolute or relative]. So we give &lt;code&gt;position: relative&lt;/code&gt; to &lt;code&gt;.left-nav&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Here are the changes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.left-nav&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="err"&gt;other&lt;/span&gt; &lt;span class="err"&gt;rules&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;relative&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.left-nav__list&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="err"&gt;#&lt;/span&gt; &lt;span class="err"&gt;other&lt;/span&gt; &lt;span class="err"&gt;rules&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;sticky&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&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;The &lt;code&gt;top: 0&lt;/code&gt; rule makes sure our list is sticking to the top rather than to the bottom of the parent.&lt;/p&gt;

&lt;h3&gt;
  
  
  Other important things to learn
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;In the desktop view, the links are aligning towards right, this is something I have seen in many such implementations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use &lt;code&gt;list-style-type: none&lt;/code&gt; to remove the bullets in the list which come by default. In some CSS resets, this is done for all lists, but I think that is more of a limitation than an advantage, especially in documentation apps where bullets are expected to be there by default.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Notice that in desktop view, we are fixing the width of the left nav and doing &lt;code&gt;flex: 1&lt;/code&gt; to the reading column. What this does is that your reading column will always occupy the rest of the width in the page.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Missing features we could add
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;The "always see the table of contents" feature is only available in desktop but not in the mobile view, may be we could add a sliding-in left-navigation to achieve this in future.&lt;/li&gt;
&lt;li&gt;We may try to achieve highlighting the left-nav link based on the current section in view. This is a useful feature if you have sections whose heights are many times more than the viewport height. In this case, even though the section heading is hidden above, you can still look at the left-nav to know which section it is.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What next
&lt;/h2&gt;

&lt;p&gt;I will resolve a couple of hacks that we did here in my next post using CSS grids.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Two &lt;code&gt;h1&lt;/code&gt;s in the markup&lt;/li&gt;
&lt;li&gt;Manually tweaking the &lt;code&gt;margin-top&lt;/code&gt; of left-nav to align it with the first content heading.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Please do suggest if you want me to achieve any other feature in this particular example. Or if you like it, please let me know what you learned.&lt;/p&gt;

&lt;p&gt;See you in the next one.&lt;/p&gt;

&lt;p&gt;Subscribe to my &lt;a href="https://www.youtube.com/channel/UCl5dc2m9rRGZsAu04ytfDjw/featured?view_as=subscriber"&gt;YouTube channel&lt;/a&gt; for many such developer tips.&lt;/p&gt;

</description>
      <category>css</category>
      <category>html</category>
      <category>tutorial</category>
      <category>flexbox</category>
    </item>
    <item>
      <title>React vs Vue (A feature comparison)</title>
      <dc:creator>Naga Chaitanya Konada</dc:creator>
      <pubDate>Thu, 23 Apr 2020 19:02:06 +0000</pubDate>
      <link>https://dev.to/chaituknag/react-vs-vue-a-feature-comparison-5678</link>
      <guid>https://dev.to/chaituknag/react-vs-vue-a-feature-comparison-5678</guid>
      <description>&lt;h1&gt;
  
  
  What this is not
&lt;/h1&gt;

&lt;p&gt;This is not a comparison of how React works, how Vue fares in performance and code quality against React, etc.&lt;/p&gt;

&lt;p&gt;This is rather a set of features which caught my eye as somewhat of a similarity. They are so similar in terms of learning curve, feature set and also tools developed around them, that sometimes I think they could combine and become a super-sonic tool that works across the board.&lt;/p&gt;

&lt;p&gt;Please do not judge me over this, if some of the feature items look too naive and should not be there at all. But this is how I think both of the tools evolved over time and they are more common than you might think.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Wherever possible I have given links to the corresponding tools, in case you want to quickly take a look at them.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  Here it goes
&lt;/h1&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;For React&lt;/th&gt;
&lt;th&gt;For VueJS&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://en.wikipedia.org/wiki/Single-page_application"&gt;Single Page Application&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;React CLI (&lt;a href="https://create-react-app.dev/docs/getting-started"&gt;create-react-app&lt;/a&gt;)&lt;/td&gt;
&lt;td&gt;Vue CLI (&lt;a href="https://cli.vuejs.org/guide/"&gt;vue create&lt;/a&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://medium.com/@benjburkholder/javascript-seo-server-side-rendering-vs-client-side-rendering-bc06b8ca2383"&gt;Server Side Rendering&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="https://nextjs.org/learn/basics/create-nextjs-app"&gt;Next.js&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="https://nuxtjs.org/guide/installation"&gt;Nuxt.js&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://staticgen.org/"&gt;Static Site Generator&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://www.gatsbyjs.org/"&gt;Gatsby&lt;/a&gt;, &lt;a href="https://github.com/react-static/react-static/tree/master/docs"&gt;React-Static&lt;/a&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://gridsome.org/docs/"&gt;Gridsome&lt;/a&gt;, &lt;a href="https://vuepress.vuejs.org/guide/"&gt;VuePress&lt;/a&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="https://material.io/design/"&gt;Material UI&lt;/a&gt; Library&lt;/td&gt;
&lt;td&gt;&lt;a href="https://material-ui.com/getting-started/installation/"&gt;Material-UI.com&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="https://vuetifyjs.com/en/getting-started/quick-start/"&gt;Vuetify&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href="https://en.wikipedia.org/wiki/Web_development_tools"&gt;DevTools&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;React DevTools for &lt;a href="https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en"&gt;Chrome&lt;/a&gt; and &lt;a href="https://addons.mozilla.org/en-US/firefox/addon/react-devtools/"&gt;Firefox&lt;/a&gt;
&lt;/td&gt;
&lt;td&gt;Vue DevTools for &lt;a href="https://chrome.google.com/webstore/detail/vuejs-devtools/nhdogjmejiglipccpnnnanhbledajbpd?hl=en"&gt;Chrome&lt;/a&gt; and &lt;a href="https://addons.mozilla.org/en-US/firefox/addon/vue-js-devtools/"&gt;Firefox&lt;/a&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;a href="https://getbootstrap.com/docs/4.4/getting-started/introduction/"&gt;Bootstrap&lt;/a&gt; Library&lt;/td&gt;
&lt;td&gt;&lt;a href="https://react-bootstrap.github.io/getting-started/introduction"&gt;react-bootstrap&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href="https://bootstrap-vue.js.org/docs"&gt;bootstrap-vue&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Routing&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://reacttraining.com/react-router/web/guides/quick-start"&gt;react-router&lt;/a&gt;, &lt;a href="https://reach.tech/router"&gt;reach-router&lt;/a&gt;
&lt;/td&gt;
&lt;td&gt;VueJS router (&lt;a href="https://router.vuejs.org/installation.html#direct-download-cdn"&gt;vue-router&lt;/a&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;UI State management&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://reactjs.org/docs/context.html"&gt;React Context&lt;/a&gt;, &lt;a href="https://redux.js.org/introduction/getting-started"&gt;Redux&lt;/a&gt; (&lt;a href="https://react-redux.js.org/introduction/quick-start"&gt;react-redux&lt;/a&gt;)&lt;/td&gt;
&lt;td&gt;&lt;a href="https://vuex.vuejs.org/guide/"&gt;Vuex&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Native apps&lt;/td&gt;
&lt;td&gt;
&lt;a href="https://reactnative.dev/docs/getting-started"&gt;React Native&lt;/a&gt; (&lt;a href="https://github.com/expo/create-react-native-app"&gt;create-react-native-app&lt;/a&gt;)&lt;/td&gt;
&lt;td&gt;Vue Native (&lt;a href="https://vue-native.io/docs/installation.html"&gt;vue-native-cli&lt;/a&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;h1&gt;
  
  
  What do you think
&lt;/h1&gt;

&lt;p&gt;I feel I did a nice job going after all these tools. I come from a React background and rarely get to work on VueJS apps in my work. I have been doing some side projects in Vue, just to get a feel of it. What do you think of the above listing of features. Should I add any other features for comparison? Did I miss anything. Have I listed something wrong? Do let  me know in the comments.&lt;/p&gt;

</description>
      <category>react</category>
      <category>vue</category>
      <category>feature</category>
      <category>comparison</category>
    </item>
    <item>
      <title>Headless CMS comparison from JAMStack perspective (Gatsby)</title>
      <dc:creator>Naga Chaitanya Konada</dc:creator>
      <pubDate>Thu, 23 Apr 2020 13:07:53 +0000</pubDate>
      <link>https://dev.to/chaituknag/headless-cms-comparison-from-jamstack-perspective-gatsby-4g9d</link>
      <guid>https://dev.to/chaituknag/headless-cms-comparison-from-jamstack-perspective-gatsby-4g9d</guid>
      <description>&lt;h2&gt;
  
  
  What are JAMStack projects
&lt;/h2&gt;

&lt;p&gt;JAMStack has been popularised by teams like &lt;a href="https://www.netlify.com/"&gt;Netlify&lt;/a&gt; who along with many static site generator frameworks like &lt;a href="https://www.gatsbyjs.org/"&gt;Gatsby&lt;/a&gt; are making the process of hosting sites way better than before. If you are anyone like me, you must have utilised Gatsby and Netlify and one of the headless CMS tools out there already. No?&lt;/p&gt;

&lt;p&gt;Checkout &lt;a href="https://jamstack.org/"&gt;JAMStack.org&lt;/a&gt; site to know more about JAM stack and its advantages over traditional stacks.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Headless CMS tools
&lt;/h2&gt;

&lt;p&gt;These are CMS tools where content is decoupled from their respective templates, thus avoiding the tight dependency of frontend projects on these CMS tools. If these are used, front-end developer can easily get the content and plug it in wherever required for the application they are making.&lt;/p&gt;

&lt;p&gt;These CMS tools will expose an API layer that gets consumed by the front-end setup, as a traditional REST api or a GraphQL api.&lt;/p&gt;

&lt;p&gt;Static Site Generators, will consume this API and generate static HTML pages that can be hosted easily without an actual server -- the whole point of JAMStack.&lt;/p&gt;

&lt;p&gt;Checkout the &lt;a href="https://headlesscms.org/"&gt;HeadlessCMS.org&lt;/a&gt; site for a quick look at the plethora of these kind of CMS solutions out there, sorted by their popularity.&lt;/p&gt;

&lt;p&gt;Also checkout &lt;a href="https://www.staticgen.com/"&gt;StaticGen.com&lt;/a&gt; which has a similar listing for Static Site Generator tools out there, sorted by their popularity.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the comparison then
&lt;/h2&gt;

&lt;p&gt;Recently, I went through a bunch of these CMS solutions against the Gatsby framework, mainly understanding how well and easy, we can integrate them with an existing Gatsby setup, how easily we can migrate content to these CMS tools and how easily we can maintain these.&lt;/p&gt;

&lt;p&gt;Here is a full list of comparisons I did ⬇️&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Feature&lt;/th&gt;
&lt;th&gt;Netlify CMS&lt;/th&gt;
&lt;th&gt;Contentful&lt;/th&gt;
&lt;th&gt;Strapi CMS&lt;/th&gt;
&lt;th&gt;Tina CMS&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Gatsby integration&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cloud based&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Separate repo&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Authentication&lt;/td&gt;
&lt;td&gt;GitHub/GitLab/BitBucket&lt;/td&gt;
&lt;td&gt;GitHub/Google/Twitter&lt;/td&gt;
&lt;td&gt;Email based/random UID&lt;/td&gt;
&lt;td&gt;Anyone with access to the repo&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Static files&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Same repo&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Multi-media&lt;/td&gt;
&lt;td&gt;Repo-based&lt;/td&gt;
&lt;td&gt;Cloud-based&lt;/td&gt;
&lt;td&gt;Independent&lt;/td&gt;
&lt;td&gt;Repo-based&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Integration changes&lt;/td&gt;
&lt;td&gt;Low&lt;/td&gt;
&lt;td&gt;Low&lt;/td&gt;
&lt;td&gt;Low&lt;/td&gt;
&lt;td&gt;Medium&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Incremental builds&lt;/td&gt;
&lt;td&gt;Yes, possible&lt;/td&gt;
&lt;td&gt;No, full build required&lt;/td&gt;
&lt;td&gt;No, full build required&lt;/td&gt;
&lt;td&gt;Yes, possible&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CMS UI&lt;/td&gt;
&lt;td&gt;Separate&lt;/td&gt;
&lt;td&gt;Separate&lt;/td&gt;
&lt;td&gt;Separate&lt;/td&gt;
&lt;td&gt;Integrated&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CMS Component support&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Content Types&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;File formats&lt;/td&gt;
&lt;td&gt;Markdown, Yaml, JSON&lt;/td&gt;
&lt;td&gt;N/A&lt;/td&gt;
&lt;td&gt;N/A&lt;/td&gt;
&lt;td&gt;Markdown, JSON&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Component modification required (one time)&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Multi-site support&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Webhooks&lt;/td&gt;
&lt;td&gt;Not required&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Not required&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Content migration&lt;/td&gt;
&lt;td&gt;Possible&lt;/td&gt;
&lt;td&gt;Not possible&lt;/td&gt;
&lt;td&gt;Not possible&lt;/td&gt;
&lt;td&gt;Possible&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;How do you find this comparison to be? Would you like to add more details? Probably more points to compare? Have you done a similar comparison with these (or other) CMS tools? Please jump in and leave a comment. I will definitely check them out.&lt;/p&gt;

</description>
      <category>netlifycms</category>
      <category>strapicms</category>
      <category>tinacms</category>
      <category>contentful</category>
    </item>
    <item>
      <title>Best practices for reusable components in React</title>
      <dc:creator>Naga Chaitanya Konada</dc:creator>
      <pubDate>Mon, 30 Mar 2020 13:00:13 +0000</pubDate>
      <link>https://dev.to/chaituknag/best-practices-for-reusable-components-in-react-1cm9</link>
      <guid>https://dev.to/chaituknag/best-practices-for-reusable-components-in-react-1cm9</guid>
      <description>&lt;p&gt;These are some of the points related to best practices for reusable components in React-based projects.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Components should be small and easy to read.&lt;/li&gt;
&lt;li&gt;Use prop-types package to structure and validate the props of your components.&lt;/li&gt;
&lt;li&gt;For styled-components, do not include any functional details, instead pass them as props.&lt;/li&gt;
&lt;li&gt;For container components, do not include UI details, instead, let the children styled-components take care of them&lt;/li&gt;
&lt;li&gt;Prefer functional components vs class-based components.&lt;/li&gt;
&lt;li&gt;Prefer CSS in JS strategy for styled-components for better maintainability.&lt;/li&gt;
&lt;li&gt;UI variations should be coming in as configurable props whereas data should be coming up as part of a global state like Redux or React Context.&lt;/li&gt;
&lt;li&gt;Don’t repeat sections wherever it can be avoided, instead use arrays to store those section details and loop over them.&lt;/li&gt;
&lt;li&gt;For components, add comments only wherever absolutely necessary (to indicate a hack or workaround for a bug).&lt;/li&gt;
&lt;li&gt;For library utilities (pure functions), write JS-Doc comments.&lt;/li&gt;
&lt;li&gt;Avoid using anonymous components wherever possible.&lt;/li&gt;
&lt;li&gt;All files for a component should be part of the same folder.&lt;/li&gt;
&lt;li&gt;Always use eslint and prettier for keeping your code clean and formatted.&lt;/li&gt;
&lt;li&gt;Use ES6 features.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>reusable</category>
      <category>component</category>
      <category>optimisation</category>
    </item>
  </channel>
</rss>
