<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Swastik Yadav</title>
    <description>The latest articles on Forem by Swastik Yadav (@swastikyadav).</description>
    <link>https://forem.com/swastikyadav</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%2F624038%2F06e37841-8bee-420a-a76e-4f05684aaf1c.jpg</url>
      <title>Forem: Swastik Yadav</title>
      <link>https://forem.com/swastikyadav</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/swastikyadav"/>
    <language>en</language>
    <item>
      <title>How I prepared for Frontend interviews in 2 weeks (And how you can too)</title>
      <dc:creator>Swastik Yadav</dc:creator>
      <pubDate>Tue, 23 Sep 2025 12:21:49 +0000</pubDate>
      <link>https://forem.com/swastikyadav/how-i-prepared-for-frontend-interviews-in-2-weeks-and-how-you-can-too-jmd</link>
      <guid>https://forem.com/swastikyadav/how-i-prepared-for-frontend-interviews-in-2-weeks-and-how-you-can-too-jmd</guid>
      <description>&lt;p&gt;Preparing for frontend interviews was a nightmare for me.&lt;/p&gt;

&lt;p&gt;There is just so much resources with 500+ questions and so many topics to cover.&lt;/p&gt;

&lt;p&gt;The range of frontend interviews today is wild. You can be asked anything from CSS, JS, Performance, Networking, Accessibility, Browser APIs, System Design, and more...&lt;/p&gt;

&lt;p&gt;Before every frontend interview I use to feel overwhelmed. It took me months before feeling even remotely ready to start applying. The imposter syndrome was just at it's peak.&lt;/p&gt;

&lt;p&gt;It's not about more and more questions but right set of less questions.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“I fear not the man who has practiced 10,000 kicks once, but I fear the man who has practiced one kick 10,000 times.” - Bruce Lee&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Sounds familiar?&lt;/p&gt;

&lt;p&gt;I've been there, but I've also sat for multiple frontend interviews in many service and product companies.&lt;/p&gt;

&lt;p&gt;And noticed a pattern, in every interivew I was more or less asked the same set of concepts just with different variations.&lt;/p&gt;

&lt;p&gt;On the surface the questions looked different but deep down it was the same old concepts which can be answered easily if you understand concepts like closures, promises, performance, e.t.c.&lt;/p&gt;

&lt;p&gt;Hence I built a list of the smallest set of questions which covers all important concepts and helps me preapre quickly before a frontend interview.&lt;/p&gt;

&lt;p&gt;Now, I've decided to publicaly share my list with great explanations, examples, and visuals for FREE.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Introducing Frontend75&lt;/strong&gt;: A curated database of 75 most important questions you'll face in your next frontend interview.&lt;/p&gt;

&lt;p&gt;This isn't just another generic question dump. Each question includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Real-world examples&lt;/li&gt;
&lt;li&gt;A "signal score" showing how likely it is to appear in your next interview.&lt;/li&gt;
&lt;li&gt;Deep explanations (no more surface-level answers)&lt;/li&gt;
&lt;li&gt;How I'd actually respond in a real interview setting.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Launching in a few days for absolutely FREE.&lt;/p&gt;

&lt;p&gt;If you're tired of scattered resources and want a clear, focused prep path that actually works, join the waitlist here: &lt;a href="https://frontend75.kit.com/waitlist" rel="noopener noreferrer"&gt;https://frontend75.kit.com/waitlist&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;See you on the other side.&lt;/p&gt;

&lt;p&gt;Thank You!&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>webdev</category>
      <category>career</category>
      <category>interview</category>
    </item>
    <item>
      <title>React component library for rapid product prototyping.</title>
      <dc:creator>Swastik Yadav</dc:creator>
      <pubDate>Sun, 27 Jul 2025 11:39:43 +0000</pubDate>
      <link>https://forem.com/swastikyadav/how-why-i-created-a-ui-component-library-3a1a</link>
      <guid>https://forem.com/swastikyadav/how-why-i-created-a-ui-component-library-3a1a</guid>
      <description>&lt;p&gt;There is nothing more satisfying than building great products that entice your users.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmlykcge6m4tcjuygedib.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fmlykcge6m4tcjuygedib.png" alt="catalystui-dashboard" width="800" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, building a great product requires more than just coding or designing, and that's what I'm learning these days.&lt;/p&gt;

&lt;p&gt;I am one of those people who believe in building great products at great speed.&lt;/p&gt;

&lt;p&gt;Every time I build a product, I feel overwhelmed by the numerous UI/UX options available for layout, spacing, typography, and color.&lt;/p&gt;

&lt;p&gt;Hence, I created a minimal component library for myself, which follows a specific set of rules to avoid being overwhelmed.&lt;/p&gt;

&lt;p&gt;Introducing: &lt;a href="https://catalystui.vercel.app" rel="noopener noreferrer"&gt;&lt;strong&gt;Catalyst UI&lt;/strong&gt;&lt;/a&gt; - &lt;em&gt;A React components library for faster product prototyping&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Read the design system here: &lt;a href="https://catalystui.vercel.app/documentation/design-system" rel="noopener noreferrer"&gt;The Design System&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Every CatalystUI component, block, and template follows this design system.&lt;/p&gt;

&lt;p&gt;CatalystUI doesn't force you to follow this design system strictly. You can break the rules if you've a good reason to do so with simple TailwindCSS utility classes.&lt;/p&gt;

&lt;p&gt;This is built with React, TailwindCSS, and RadixUI.&lt;/p&gt;

&lt;p&gt;RadixUI is the core building block of this design system. Unstyled, Accessible, and Open-source React primitives.&lt;/p&gt;

&lt;p&gt;Let's break down one simple component from CatalystUI.&lt;/p&gt;

&lt;h2&gt;
  
  
  Avatar component breakdown
&lt;/h2&gt;

&lt;p&gt;RadixUI Avatar comes in three parts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Avatar.Root: The root element&lt;/li&gt;
&lt;li&gt;Avatar.Image: The element that takes the image URL&lt;/li&gt;
&lt;li&gt;Avatar.Fallback: The element which renders name initials if the image URL is not given or can't be fetched&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is the basic usage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Avatar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Root&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Avatar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Image&lt;/span&gt; &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;imageUrl&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Avatar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Fallback&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;SW&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Avatar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Fallback&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Avatar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Root&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This renders a completely unstyled Avatar, one that doesn't even look like an avatar. So that we can style it however we want. And that's not a bug but a feature of RadixUI Primitives.&lt;/p&gt;

&lt;p&gt;We'll create three different components for each part of the avatar.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use children props to render &lt;code&gt;Avatar.Image&lt;/code&gt; and &lt;code&gt;Avatar.Fallback&lt;/code&gt; into &lt;code&gt;Avatar.Root&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Style each part with TailwindCSS.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;AvatarRoot&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forwardRef&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;
  &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ElementRef&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;AvatarPrimitive&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Root&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;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ComponentPropsWithoutRef&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;AvatarPrimitive&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Root&lt;/span&gt;&lt;span class="o"&gt;&amp;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;className&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="nx"&gt;props&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;forwardedRef&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;AvatarPrimitive&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Root&lt;/span&gt;
      &lt;span class="na"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;forwardedRef&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;cx&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;props&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;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;AvatarPrimitive&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Root&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;const&lt;/span&gt; &lt;span class="nx"&gt;AvatarImage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forwardRef&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;
  &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ElementRef&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;AvatarPrimitive&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Image&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;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ComponentPropsWithoutRef&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;AvatarPrimitive&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Image&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;imgUrl&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="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(({&lt;/span&gt; &lt;span class="nx"&gt;imgUrl&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;forwardedRef&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;AvatarPrimitive&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Image&lt;/span&gt;
      &lt;span class="na"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;forwardedRef&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;cx&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="c1"&gt;// base&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;w-[26px] h-[26px] rounded-full cursor-pointer&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="c1"&gt;// className prop&lt;/span&gt;
        &lt;span class="nx"&gt;className&lt;/span&gt;
      &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;src&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;imgUrl&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;alt&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Colm Tuite"&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="si"&gt;}&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;const&lt;/span&gt; &lt;span class="nx"&gt;AvatarFallback&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forwardRef&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;
  &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ElementRef&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;AvatarPrimitive&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Image&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;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ComponentPropsWithoutRef&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;AvatarPrimitive&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Image&lt;/span&gt;&lt;span class="o"&gt;&amp;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;className&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="nx"&gt;props&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;forwardedRef&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;AvatarPrimitive&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Fallback&lt;/span&gt;
      &lt;span class="na"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;forwardedRef&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;cx&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="c1"&gt;// base&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cursor-pointer border border-gray-200 rounded-full p-1&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="c1"&gt;// className prop&lt;/span&gt;
        &lt;span class="nx"&gt;className&lt;/span&gt;
      &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="na"&gt;delayMs&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;props&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;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;AvatarPrimitive&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Fallback&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;Now, our Avatar component is ready to be used. Here is the usage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;AvatarRoot&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;AvatarImage&lt;/span&gt; &lt;span class="na"&gt;imgUrl&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"https://avatars.githubusercontent.com/u/44374494"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;AvatarFallback&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;SW&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;AvatarFallback&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;AvatarRoot&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Similarly, other components are also built with some API differences. Radix doesn't have primitives for everything, so for other things, we can use the Slot utility from Radix to get its accessibility benefits into our custom primitives.&lt;/p&gt;




&lt;p&gt;Show your support by giving CatalystUI a star on GitHub: &lt;a href="https://github.com/Swastikyadav/CatalystUI" rel="noopener noreferrer"&gt;https://github.com/Swastikyadav/CatalystUI&lt;/a&gt;&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>ui</category>
      <category>webdev</category>
      <category>frontend</category>
    </item>
    <item>
      <title>6 Steps To Become A Profitable Freelance Web Developer In 90 Days.</title>
      <dc:creator>Swastik Yadav</dc:creator>
      <pubDate>Fri, 30 Aug 2024 07:22:01 +0000</pubDate>
      <link>https://forem.com/swastikyadav/6-steps-to-become-a-profitable-freelance-web-developer-in-90-days-4kp4</link>
      <guid>https://forem.com/swastikyadav/6-steps-to-become-a-profitable-freelance-web-developer-in-90-days-4kp4</guid>
      <description>&lt;p&gt;Hello Devs!&lt;/p&gt;

&lt;p&gt;Did you know 99 out of 100 developers who try to start a freelance business and make money outside of a job fail?&lt;/p&gt;

&lt;p&gt;Yup, It sucks. The main reasons why they fail are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;They don't know how to select a niche.&lt;/li&gt;
&lt;li&gt;They don't know how to create great offers.&lt;/li&gt;
&lt;li&gt;They don't know how to bring traffic to their business.&lt;/li&gt;
&lt;li&gt;They don't know how to sell their services.&lt;/li&gt;
&lt;li&gt;And so on...&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Times have changed, selling only web development services won't work unless you tie it up with either "health", "wealth", or "relationship".&lt;/p&gt;

&lt;p&gt;Businesses don't want a website, they want a website that converts and brings more revenue.&lt;/p&gt;

&lt;p&gt;Hi, I am Swastik. A software engineer developing software for companies and freelance clients for 4+ years now.&lt;/p&gt;

&lt;p&gt;Over the years I have developed a 6-step framework for web developers to start a profitable freelance business in 90 days.&lt;/p&gt;

&lt;p&gt;This is the exact framework that I and my close developer friend circle use.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stop creating your Fiverr and Upwork profile.&lt;/li&gt;
&lt;li&gt;Stop bidding for minimally paid gigs.&lt;/li&gt;
&lt;li&gt;Stop trying to compete with thousands of commodity freelancers.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you follow this system step by step and be consistent you won't believe what you can achieve in 3 months.&lt;/p&gt;

&lt;p&gt;So, here I reveal the system.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Skills Needed
&lt;/h2&gt;

&lt;p&gt;To be honest you don’t need to know any crazy technologies. If you know how to build websites and landing pages, you are good to go.&lt;/p&gt;

&lt;p&gt;No matter how you build it plain HTML-CSS, React, Next, WordPress, or anything else.&lt;/p&gt;

&lt;p&gt;If you are not sure or don’t feel confident, start by learning NextJs, that’s what I use. If you know basic Js and React, it won’t be tough to learn.&lt;/p&gt;

&lt;p&gt;Also, NextJs is the standard nowadays.&lt;/p&gt;

&lt;p&gt;That’s why you should learn NextJs so your skills don’t hold you back.&lt;/p&gt;

&lt;p&gt;Skill problem solved!&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Niche Selection
&lt;/h2&gt;

&lt;p&gt;Niche is simply whom you serve as a freelancer. If you accept to work with every type of client under the sun, you'll soon become a commodity business and die.&lt;/p&gt;

&lt;p&gt;But being a niche expert will allow you to charge for value and you won't be competing over price.&lt;/p&gt;

&lt;p&gt;Use any AI tool for Niche selection research. I prefer Google's Gemini here because of its better ability to search the web.&lt;/p&gt;

&lt;p&gt;Come up with a list of 8-10 niches for yourself and then Use the following prompt.&lt;/p&gt;

&lt;h4&gt;
  
  
  -- AI Prompt For Niche Selection Research --
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;I am starting a service business and want your help to decide on a niche.

I have listed a few niches, I want you to do some research and figure out the following 2 metrics for each one.

The 2 metrics are:
- What is the average order value in that niche?
- What is the demand for the services the niche provides?

Here are the niches [*these are my list of niches, insert your list here*]:
- Medical Spas
- Beauticians / Makeup Artists
- Packers and Movers
- Cleaning businesses
- Real Estate
- Dentists
- Dermatologists
- Pest control
- Gym

I want you to give a score to each niche I provide. Give a score based on Demand "1 for low, 2 for moderate, and 3 for high" and AOV "similar to demand". And then rank or sort the niches according to the score.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will rank your list according to the 2 metrics we gave. Choose one from the top 3 niches.&lt;/p&gt;

&lt;p&gt;Once you choose a niche, stick with it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Offer Creation
&lt;/h2&gt;

&lt;p&gt;Your offer is the promise you are making to your clients.&lt;/p&gt;

&lt;p&gt;Selling only web development services is difficult because everyone is doing that. You have to offer something that no one else is offering.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Don't just offer a website, offer a website that'll increase their conversion rate from 1% to 3-4%.&lt;/li&gt;
&lt;li&gt;Don't just offer a landing page, offer a landing page that will 2x their revenue in 90 days.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You get the idea.&lt;/p&gt;

&lt;p&gt;Make an Offer so good people feel stupid saying no. Watch my video where I went through this checklist and closed a client, you'll understand what I am talking about. [Video link at end of post]&lt;/p&gt;

&lt;p&gt;But make sure to be practical and don't promise anything that you can't deliver.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Traffic Source
&lt;/h2&gt;

&lt;p&gt;Your offer doesn’t mean anything if no one knows about it. No matter how good of an offer you made.&lt;/p&gt;

&lt;p&gt;You are probably here from my cold DM, content, or Ad. That’s how I bring traffic.&lt;/p&gt;

&lt;p&gt;There are only 4 core ways to bring traffic and make people know about your stuff.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Warm outreach&lt;/li&gt;
&lt;li&gt;Content&lt;/li&gt;
&lt;li&gt;Cold outreach&lt;/li&gt;
&lt;li&gt;Ads&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The only purpose of traffic is to get leads and make strangers want to buy from you.&lt;/p&gt;

&lt;p&gt;Watch the video and see how I brought traffic to freelance business.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Sales
&lt;/h2&gt;

&lt;p&gt;If your offer is really good, sales will happen on its own. And you’ll do just fine.&lt;/p&gt;

&lt;p&gt;But if your offer is bad, you’ll have to put some effort into sales. And you can still do just fine.&lt;/p&gt;

&lt;p&gt;Now imagine, what'll happen if you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Have a great offer.&lt;/li&gt;
&lt;li&gt;Are good at sales.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sales is not forcing your clients to buy, but giving them as much value as possible until they are ready to buy.&lt;/p&gt;

&lt;p&gt;Give them so much value upfront that they feel obligated to pay you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 6: Service Delivery
&lt;/h2&gt;

&lt;p&gt;Once you close a client.&lt;/p&gt;

&lt;p&gt;Now the real work begins. Service delivery is the most important aspect of your freelance business. Because if you don’t deliver your promises your business will die fast and steady.&lt;/p&gt;

&lt;p&gt;A great service delivery fulfills your promises and keeps getting repeat clients and referrals.&lt;/p&gt;




&lt;p&gt;Follow this system and be consistent for the next 3 months. You'll thank me later.&lt;/p&gt;

&lt;p&gt;If you found this article helpful. For more tips, strategies, and frameworks on monetizing your coding skills join the newsletter at &lt;a href="https://degreeless.dev" rel="noopener noreferrer"&gt;Degreeless.Dev&lt;/a&gt;.&lt;/p&gt;




</description>
      <category>freelance</category>
      <category>development</category>
      <category>webdev</category>
      <category>career</category>
    </item>
    <item>
      <title>3-step process to break into tech in 180 days.</title>
      <dc:creator>Swastik Yadav</dc:creator>
      <pubDate>Wed, 19 Jun 2024 09:59:49 +0000</pubDate>
      <link>https://forem.com/swastikyadav/3-step-process-to-break-into-tech-in-180-days-2193</link>
      <guid>https://forem.com/swastikyadav/3-step-process-to-break-into-tech-in-180-days-2193</guid>
      <description>&lt;p&gt;As freshers worldwide scramble to make their first breakthrough in tech, one question remains:&lt;/p&gt;

&lt;p&gt;How do you prove your worth as a fresher?&lt;/p&gt;

&lt;p&gt;I have done this twice. I broke into tech again after a 1-year gap in my resume. I did it a couple of more times for my friends. So, let me tell you how.&lt;/p&gt;

&lt;p&gt;But it won't be possible without a carefully devised plan.&lt;/p&gt;

&lt;p&gt;I am sharing my tried and tested framework for breaking into tech with this article.&lt;/p&gt;

&lt;p&gt;Everything is distilled into actionable steps to help you make your first breakthrough.&lt;/p&gt;

&lt;p&gt;Let's get into it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are you doing wrong?
&lt;/h2&gt;

&lt;p&gt;What most freshers are doing wrong is they apply to job postings where there are already hundreds of applicants.&lt;/p&gt;

&lt;p&gt;Tell me this,&lt;br&gt;
Where do you stand in that crowd without any professional experience?&lt;/p&gt;

&lt;p&gt;So, here are the prerequisites to the main framework. Make sure to have these points in place first.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stop applying to every job posting mindlessly.&lt;/li&gt;
&lt;li&gt;Learn to create pixel-perfect designs with CSS.&lt;/li&gt;
&lt;li&gt;Learn to make web pages interactive with JS.&lt;/li&gt;
&lt;li&gt;Learn one JS framework/library, preferably ReactJs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's time to stand out, not to get lost among hundreds of resumes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Your 3-step breakthrough roadmap
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Build projects beyond todo apps.&lt;/li&gt;
&lt;li&gt;Be the LinkedIn profile recruiters are looking for.&lt;/li&gt;
&lt;li&gt;Learn to network and reach out.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Step #1: Build projects beyond todo apps.
&lt;/h2&gt;

&lt;p&gt;As a fresher, you must show this to your potential employer. So, pay careful attention to building projects.&lt;/p&gt;

&lt;p&gt;Build projects which clearly show your:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;UI/CSS Skills&lt;/li&gt;
&lt;li&gt;Frontend Skills&lt;/li&gt;
&lt;li&gt;Handling 3rd party APIs and integrations
Build projects beyond todo apps.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For reference, check the pinned projects on my GitHub profile.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step #2: Be the LinkedIn profile recruiters are looking for.
&lt;/h2&gt;

&lt;p&gt;If you ask me to choose only one platform to build my social presence as a developer, I will choose LinkedIn every single time.&lt;/p&gt;

&lt;p&gt;LinkedIn is a goldmine of opportunities if used properly.&lt;/p&gt;

&lt;p&gt;It's time to optimize and fix your LinkedIn profile. So let's make every aspect of your profile count.&lt;/p&gt;

&lt;h3&gt;
  
  
  Your banner
&lt;/h3&gt;

&lt;p&gt;The LinkedIn banner is the most underutilized real estate by developers.&lt;/p&gt;

&lt;p&gt;It is not to show the creative art or your NFT (leave that stuff for Twitter guys).&lt;/p&gt;

&lt;p&gt;Your LinkedIn banner should give all your contact details to the visitor. Here is mine, for example.&lt;/p&gt;

&lt;p&gt;Note: This is not how my profile is set up currently. I keep changing my profile. I will revert to these suggestions if I again start looking for a job.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffjrhno2ffg82wlvdqctp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffjrhno2ffg82wlvdqctp.png" alt="banner ss" width="800" height="199"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Your headshot
&lt;/h3&gt;

&lt;p&gt;The profile picture is the most straightforward section. Yet, so many devs get it wrong.&lt;/p&gt;

&lt;p&gt;Avoid the following type of picture:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A cartoon version of you.&lt;/li&gt;
&lt;li&gt;You looking sideways.&lt;/li&gt;
&lt;li&gt;No selfie, please.
Your headshot should have a white/blue/black background and a great smile. That's it.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Your tagline
&lt;/h3&gt;

&lt;p&gt;Your tagline should be succinct and clearly state:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What you do. ex: JavaScript Developer&lt;/li&gt;
&lt;li&gt;Avoid using words like "aspiring". You are already a developer if you can build a simple web page.&lt;/li&gt;
&lt;li&gt;What technologies do you work with? Your profile won't show in search results without this.&lt;/li&gt;
&lt;li&gt;Don't write Frontend or Backend because no one is searching for those keywords. Mention exactly what you work with.&lt;/li&gt;
&lt;li&gt;You can mention an interesting project you are working on. Ex: Building a real-time feedback platform with socket.io.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is my tagline:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fol9dz0ahomeekobdq652.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fol9dz0ahomeekobdq652.png" alt="taglinen ss" width="727" height="167"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Your featured section
&lt;/h3&gt;

&lt;p&gt;Most developers use it the wrong way by featuring some posts or articles.&lt;/p&gt;

&lt;p&gt;This is where you showcase your projects. The featured section is where your portfolio goes.&lt;/p&gt;

&lt;p&gt;I don't suggest showing your projects in the LinkedIn project section because the project section is visible at the end of the profile page. Instead, use the featured section.&lt;/p&gt;

&lt;p&gt;Here is my featured section. I have live projects &amp;amp; GitHub codebase. Let's decode. Don't miss the Pro Tip.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuc7k304pm82qebvl6ont.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fuc7k304pm82qebvl6ont.png" alt="featured section ss" width="653" height="331"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Code samples, GitHub, live projects. Something that you have to show.&lt;/li&gt;
&lt;li&gt;Recruiters want to know what you have already done.&lt;/li&gt;
&lt;li&gt;If you have backend projects, share the code on GitHub.&lt;/li&gt;
&lt;li&gt;If you have frontend projects, make sure to add screenshots of your UIs.
Pro tips:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;100DaysOfCode is not for LinkedIn. Position yourself as a confident developer. (Perception is reality)&lt;/p&gt;

&lt;p&gt;Record a 30-second video and put it as the first thing in the featured section.&lt;/p&gt;

&lt;p&gt;I haven't done this personally. But I will do it if I again start a job search.&lt;/p&gt;

&lt;p&gt;In those 30 seconds, answer the most common interview question: "Tell me about yourself".&lt;/p&gt;

&lt;p&gt;Now when a recruiter sees it, they will know about you more than they know about any other candidate.&lt;/p&gt;

&lt;p&gt;Spoon-feed the recruiters.&lt;/p&gt;

&lt;h3&gt;
  
  
  Your About section
&lt;/h3&gt;

&lt;p&gt;This is where you brag about your achievements, even the smallest of achievements.&lt;/p&gt;

&lt;p&gt;Here also include relevant tech keywords. But do not overdo it. Overdoing it will kill your profile. Integrate keywords in the natural flow of writing.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fll5h4plzgcob9w2x8y5x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fll5h4plzgcob9w2x8y5x.png" alt="about ss" width="722" height="337"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is my LinkedIn about section. Let's decode it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;See how I naturally integrated my technologies. (Highlighted in yellow)&lt;/li&gt;
&lt;li&gt;Notice how I mentioned even small achievements. (Highlighted in green)&lt;/li&gt;
&lt;li&gt;Explain something interesting about yourself. (Highlighted in light blue)&lt;/li&gt;
&lt;li&gt;Avoid too much use of fluff words like "I am a passionate developer". Don't tell, show the passion in your work.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You may feel like you have no significant achievements. And it is normal, with more experience, you will have more achievements to talk about.&lt;/p&gt;

&lt;p&gt;Here is what you need to do now if you aren't that experienced.&lt;/p&gt;

&lt;p&gt;Sit down and reflect on your past experiences and projects. Write down every single achievement no matter how small they are. Then list the relevant ones on LinkedIn.&lt;/p&gt;

&lt;p&gt;Ex: Created a RestAPI design, implemented the UI from Figma wireframe, etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step #3: Learn to network and reach out.
&lt;/h2&gt;

&lt;p&gt;LinkedIn is a great place to make connections and network with people that bring value to the conversation.&lt;/p&gt;

&lt;p&gt;You never know where one conversation can lead you.&lt;br&gt;
Here is how you should apply for job postings. This method is pure gold.&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;If you see a company’s job posting that you’re interested in.&lt;/li&gt;
&lt;li&gt;Immediately go to LinkedIn, type the company’s name in the search bar, and hit enter.&lt;/li&gt;
&lt;li&gt;Filter by people, and you will have a list of around 300 people from that company.&lt;/li&gt;
&lt;li&gt;Start DMing these people.&lt;/li&gt;
&lt;li&gt;You: “Hey, I saw you have a job posting up. So, like, who do I really need to talk to?”&lt;/li&gt;
&lt;li&gt;They: “You need to get in touch with XYZ. He is managing the job posting and hiring.” (They will probably introduce you to the manager themselves. If they don’t, there is no harm in asking.)&lt;/li&gt;
&lt;li&gt;You: “Oh okay, do you mind if I ask you to introduce me to him? Like over email or LinkedIn, anything works for me.”&lt;/li&gt;
&lt;li&gt;They: “Yeah, sure.”&lt;/li&gt;
&lt;li&gt;Introduction done, and boom. You have an interview lined up.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;This method never fails. (Trust me) I have done this many times, and it works every single time. But please do not overdo this method, Use it in some situations only.&lt;/p&gt;

&lt;p&gt;There you have it — an actionable, effective framework to make your breakthrough into tech.&lt;/p&gt;




&lt;p&gt;Thanks for reading. For more tips, guides, and strategies on monetizing your coding skills follow me.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>career</category>
    </item>
    <item>
      <title>React Interview Task: Build a folder/file explorer UI.</title>
      <dc:creator>Swastik Yadav</dc:creator>
      <pubDate>Thu, 28 Mar 2024 05:52:24 +0000</pubDate>
      <link>https://forem.com/swastikyadav/react-interview-task-build-a-folderfile-explorer-ui-2hgh</link>
      <guid>https://forem.com/swastikyadav/react-interview-task-build-a-folderfile-explorer-ui-2hgh</guid>
      <description>&lt;p&gt;Frontend interviews are getting more and more challenging day by day.&lt;/p&gt;

&lt;p&gt;Implementing a complex frontend feature/UI live in an interview call is no joke.&lt;/p&gt;

&lt;p&gt;I encountered one such situation where I had to build a &lt;strong&gt;VS Code like folder/file explorer UI&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This post will discuss the question, thought process, and system design behind it. Finally, we will write code to solve it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are we building?
&lt;/h2&gt;

&lt;p&gt;Live preview with code: &lt;a href="https://stackblitz.com/edit/vitejs-vite-4bqecn?file=src%2FApp.jsx" rel="noopener noreferrer"&gt;https://stackblitz.com/edit/vitejs-vite-4bqecn?file=src%2FApp.jsx&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's start by understanding the philosophy and system design and then we will start writing code.&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;Before we begin, I want to mention that this post is part of my weekly newsletter.&lt;/p&gt;

&lt;p&gt;Where I build such complex frontend features and solve complex frontend interview questions every week.&lt;/p&gt;

&lt;p&gt;If you want to learn with me, join the &lt;a href="https://diaryofadev.ck.page" rel="noopener noreferrer"&gt;Newsletter&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now, let's continue.&lt;/p&gt;




&lt;h2&gt;
  
  
  Philosophy
&lt;/h2&gt;

&lt;p&gt;The basic philosophy behind building a "Folder/File explorer UI" is as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;List all the folders and files in the root directory.&lt;/li&gt;
&lt;li&gt;Clicking on the folder name should expand to show all the files inside that folder.&lt;/li&gt;
&lt;li&gt;Clicking on the folder again should collapse to hide all the files inside that folder.&lt;/li&gt;
&lt;li&gt;Clicking on a file would do nothing in our case.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;CSS will not be the focus of this task.&lt;/p&gt;

&lt;h2&gt;
  
  
  System Design
&lt;/h2&gt;

&lt;p&gt;We will create a JSON object to mimic a VS code-like folder/file structure. This object will contain all the folders and their nested folders/files.&lt;/p&gt;

&lt;p&gt;Alright, but there is a big question here. How do we identify which entry in the JSON object is a folder and which is a file?&lt;/p&gt;

&lt;p&gt;Well, we can keep nested folders/files in an array of objects and add the flag &lt;code&gt;isFoloder&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here is our JSON object with all folders and files.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;code&gt;structure.js&lt;/code&gt;&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;folderStructureData&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="s1"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;isFolder&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;items&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="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="s1"&gt;index.html&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;isFolder&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="p"&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="s1"&gt;app&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;isFolder&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;items&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="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="s1"&gt;app.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;isFolder&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="p"&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="s1"&gt;src&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;isFolder&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;items&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="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="s1"&gt;main.jsx&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
              &lt;span class="na"&gt;isFolder&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="p"&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="s1"&gt;utils.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
              &lt;span class="na"&gt;isFolder&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="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="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="s1"&gt;app.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;isFolder&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="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="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;folderStructureData&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we need to access this JSON and render the folders/files name in UI. So let's do that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let the coding begin.
&lt;/h2&gt;

&lt;p&gt;We'll start by fetching JSON data and map over it in &lt;code&gt;App.jsx&lt;/code&gt;. And at each iteration, we will check if the item is a folder or a file.&lt;/p&gt;

&lt;p&gt;If it is a folder we will return &lt;strong&gt;&lt;code&gt;&amp;lt;Folder /&amp;gt;&lt;/code&gt;&lt;/strong&gt; component else &lt;strong&gt;&lt;code&gt;&amp;lt;File /&amp;gt;&lt;/code&gt;&lt;/strong&gt; component is returned.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;code&gt;App.jsx&lt;/code&gt;&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./App.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Folder&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;./components/Folder&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;File&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;./components/File&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;folderStructureData&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;./structureData/structure.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;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="o"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;folderStructureData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;items&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="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;isFolder&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;Folder&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&amp;gt; : &amp;lt;File item={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;})}&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="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's define our &lt;code&gt;&amp;lt;Folder /&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;File /&amp;gt;&lt;/code&gt; components.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;components/Folder.jsx&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="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="nf"&gt;Folder&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;item&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;p&lt;/span&gt;
        &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt;
          &lt;span class="na"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;lightgray&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2px&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pointer&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;}}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;x276D&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&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="p"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&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;&lt;em&gt;&lt;code&gt;components/File.jsx&lt;/code&gt;&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="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="nf"&gt;File&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;item&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;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;
      &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt;
        &lt;span class="na"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;lightgray&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2px&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="p"&gt;}}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;9781&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&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="p"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&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;Awesome, this renders our folders and files on screen. But wait ideally, we should see a folder structure like the following on screen.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;---- index.html (file)&lt;br&gt;
---- app (folder)&lt;br&gt;
-------- app.js (file)&lt;br&gt;
-------- src (folder)&lt;br&gt;
------------ main.jsx (file)&lt;br&gt;
------------ utils.js (file)&lt;br&gt;
-------- app.css (file)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But what we see right now is just &lt;code&gt;index.html&lt;/code&gt; and &lt;code&gt;app&lt;/code&gt;, but why?&lt;/p&gt;

&lt;p&gt;This is where this task becomes a little bit challenging. Can you figure it out on your own? Try and then come back.&lt;/p&gt;

&lt;p&gt;Ok, let's solve it.&lt;/p&gt;

&lt;p&gt;So basically, we are iterating over top-level data only in &lt;code&gt;App.jsx&lt;/code&gt; that's why it only shows top-level folder and file names on the screen. How do we iterate over the nested data? Like inside &lt;code&gt;app&lt;/code&gt; and then inside &lt;code&gt;src&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Well, we can manually do it for &lt;code&gt;app&lt;/code&gt; and &lt;code&gt;src&lt;/code&gt; but then it would fail if we change our JSON structure. Our solution should be such that it works automatically with any change in JSON structure.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Did you notice that our top-level and nested data both have the same data structure?&lt;br&gt;
​&lt;br&gt;
That design will allow us to recursively solve this problem. We will use the concept of recursion to solve this.&lt;br&gt;
Recursion means calling a function within itself.&lt;br&gt;
​&lt;br&gt;
Ex:&lt;br&gt;
function recurseEx() {&lt;br&gt;
recurseEx();&lt;br&gt;
}&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Inside the &lt;code&gt;Folder.jsx&lt;/code&gt; we will again map but this time over nested data and check for &lt;code&gt;isFolder&lt;/code&gt; flag.&lt;/p&gt;

&lt;p&gt;If &lt;code&gt;isFolder&lt;/code&gt; is false &lt;code&gt;File.jsx&lt;/code&gt; is returned, else &lt;code&gt;Folder.jsx&lt;/code&gt; is returned from &lt;code&gt;Folder.jsx&lt;/code&gt; itself.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;code&gt;Folder.jsx&lt;/code&gt;&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;File&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;./File&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Folder&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;item&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;isExpanded&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setIsExpanded&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;false&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;p&lt;/span&gt;
        &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt;
          &lt;span class="na"&gt;background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;lightgray&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;2px&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
          &lt;span class="na"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;pointer&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;onClick&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="nf"&gt;setIsExpanded&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;prevState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;prevState&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="nx"&gt;x276D&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&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="p"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;
        &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{{&lt;/span&gt;
          &lt;span class="na"&gt;paddingLeft&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;12px&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;}}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;isExpanded&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&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;items&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="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;isFolder&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;Folder&lt;/span&gt; &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&amp;gt; : &amp;lt;File item={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="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&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;Notice, that the &lt;code&gt;Folder.jsx&lt;/code&gt; is returned from &lt;code&gt;Folder.jsx&lt;/code&gt; itself, and that is recursion. With that now all our nested data is taken care of, no matter how deeply they are nested.&lt;/p&gt;

&lt;p&gt;There is also an &lt;code&gt;isExpanded&lt;/code&gt; state added, which just tracks if a folder is in expanded or collapsed state. And based on that the nested data of that folder is shown or hidden.&lt;/p&gt;

&lt;p&gt;Now, try changing the JSON structure and our feature will still work. And that is awesome.&lt;/p&gt;




&lt;p&gt;P.S:&lt;/p&gt;

&lt;p&gt;This feature is not tough to build if you understand recursion. But I also know that recursion is not an easy concept to wrap our heads around.&lt;/p&gt;

&lt;p&gt;And there are many more concepts like recursion. That's why I am building a resource that'll teach you such programming concepts with visual examples.&lt;/p&gt;

&lt;p&gt;And don't worry it is not gonna cost you anything.&lt;/p&gt;

&lt;p&gt;I am still working on that resource and am very close to launching it.&lt;/p&gt;

&lt;p&gt;So, stay tuned by joining the &lt;a href="https://diaryofadev.ck.page" rel="noopener noreferrer"&gt;Newsletter&lt;/a&gt; if you haven't already.&lt;/p&gt;




&lt;p&gt;Thank you,&lt;/p&gt;

&lt;p&gt;Comment down on which feature I should build next.&lt;/p&gt;

</description>
      <category>react</category>
      <category>interview</category>
      <category>tutorial</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Adding dark mode to your app has never been this easy.</title>
      <dc:creator>Swastik Yadav</dc:creator>
      <pubDate>Wed, 20 Mar 2024 08:04:47 +0000</pubDate>
      <link>https://forem.com/swastikyadav/adding-dark-mode-to-your-app-has-never-been-this-easy-29dn</link>
      <guid>https://forem.com/swastikyadav/adding-dark-mode-to-your-app-has-never-been-this-easy-29dn</guid>
      <description>&lt;p&gt;Hello Devs,&lt;/p&gt;

&lt;p&gt;Nowadays, one feature that you will see in almost all sites especially in blogs is &lt;strong&gt;theme switching&lt;/strong&gt; specifically dark mode.&lt;/p&gt;

&lt;p&gt;And that's what we are building today. [&lt;strong&gt;Dark Mode in NextJs page with Tailwind and Shadcn-UI&lt;/strong&gt;]&lt;/p&gt;

&lt;p&gt;So, let's dive in to build our third front-end feature.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are we building?
&lt;/h2&gt;

&lt;p&gt;Live preview with code: &lt;a href="https://stackblitz.com/edit/stackblitz-starters-adalin?file=app%2Fpage.tsx" rel="noopener noreferrer"&gt;https://stackblitz.com/edit/stackblitz-starters-adalin?file=app%2Fpage.tsx&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Before we start I just wanna mention that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This post is the #3 issue of my newsletter.&lt;/li&gt;
&lt;li&gt;Where I am building one complex front-end feature every week and breaking down the exact steps, philosophy, and system design behind it.&lt;/li&gt;
&lt;li&gt;Join the newsletter to learn with me.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://diaryofadev.ck.page/" rel="noopener noreferrer"&gt;https://diaryofadev.ck.page/&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Philosophy
&lt;/h2&gt;

&lt;p&gt;First, let's understand the philosophy and basic system design behind adding dark mode to a web page.&lt;/p&gt;

&lt;p&gt;As front-end engineers, we should provide our users with the best experience possible. Readability and simplicity are important. There is no point in creating the best animation in the world which leaves your user confused.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Remember, The goal is to be clear, not clever.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Dark mode provides relief to the user's eyes. You as a developer must be using the dark theme of VS-Code. Then why deprive your users of that experience?&lt;/p&gt;

&lt;h2&gt;
  
  
  System Design
&lt;/h2&gt;

&lt;p&gt;You must have seen the color wheel.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fembed.filekitcdn.com%2Fe%2F8LS4y7NXp5roUEEAnf2ief%2Ft4eLqFMMqs8GywYKYgihrz" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fembed.filekitcdn.com%2Fe%2F8LS4y7NXp5roUEEAnf2ief%2Ft4eLqFMMqs8GywYKYgihrz" alt="color-wheel" width="800" height="800"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The color wheel provides a complimentary color for each primary color. You will use the color wheel if you are building multiple themes on your page.&lt;/p&gt;

&lt;p&gt;But for our purpose, we only care about two colors white (primary) and black (secondary). I have oversimplified the design by saying white (primary) and black (secondary) colors.&lt;/p&gt;

&lt;p&gt;We will be using different shades of those colors using hue and saturation as you will see later.&lt;/p&gt;

&lt;p&gt;We will predefine all our primary and their respective secondary colors and whenever the user switches to dark mode all we have to do is switch the primary and secondary colors being used in our code.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let the coding begin.
&lt;/h2&gt;

&lt;p&gt;Let's start by creating a new NextJs project using create-next-app. Create-next-app is equivalent to create-react-app but for NextJs.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;npx create-next-app@latest next dark --typescript --tailwind&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This will create a new NextJs project named &lt;code&gt;nextDark&lt;/code&gt; with typescript and tailwind already configured for us. Now replace the default content in &lt;code&gt;app/page.tsx&lt;/code&gt; with the following code.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;page.tsx is a special file in NextJs that serves as the home page.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;page.tsx&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Button&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;@/components/ui/button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Home&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;main&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"flex min-h-screen flex-col items-center p-24"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"text-2xl font-bold"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;NextJs Dark Mode&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h1&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Issue #3 of the Newsletter.&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;small&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"my-4"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        I am building one complex frontend feature every week. Breaking down the
        exact thought process and system design behind it.
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;small&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;a&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"https://diaryofadev.ck.page"&lt;/span&gt; &lt;span class="na"&gt;target&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"_blank"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Join The Newsletter&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;main&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;The button you see in the above code is not a regular button it is a shadcn-ui component. Shadcn is a UI components library. Let's add it to our project.&lt;/p&gt;

&lt;p&gt;Run the following two commands in your terminal. Run them one by one.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;npx shadcn-ui@latest init // answer few config questions, go with default ones.&lt;br&gt;
​npx shadcn-ui@latest add button&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The first command installs shadcn-ui, its dependencies latest version. Sets up the project configuration like tailwind.config.ts and &lt;code&gt;app/globals.css&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The second command add the button component in &lt;code&gt;components/ui/button.tsx&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Ok, our home page is ready to go.&lt;/p&gt;

&lt;p&gt;See the globals.css file, it is modified by shadcn-ui. It contains some interesting configurations.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;globals.css&lt;/code&gt;&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="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;--background&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;0%&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;--foreground&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;222.2&lt;/span&gt; &lt;span class="m"&gt;84%&lt;/span&gt; &lt;span class="m"&gt;4.9%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="py"&gt;--card&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;0%&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;--card-foreground&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;222.2&lt;/span&gt; &lt;span class="m"&gt;84%&lt;/span&gt; &lt;span class="m"&gt;4.9%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="err"&gt;.dark&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;--background&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;222.2&lt;/span&gt; &lt;span class="m"&gt;84%&lt;/span&gt; &lt;span class="m"&gt;4.9%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;--foreground&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;210&lt;/span&gt; &lt;span class="m"&gt;40%&lt;/span&gt; &lt;span class="m"&gt;98%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="py"&gt;--card&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;222.2&lt;/span&gt; &lt;span class="m"&gt;84%&lt;/span&gt; &lt;span class="m"&gt;4.9%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="py"&gt;--card-foreground&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;210&lt;/span&gt; &lt;span class="m"&gt;40%&lt;/span&gt; &lt;span class="m"&gt;98%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The class &lt;code&gt;.dark&lt;/code&gt; defines the secondary color for each respective primary color. Check the global CSS file and explore the primary and their secondary colors for a while. This makes our job to switch to light/dark mode very easy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding dark mode.
&lt;/h2&gt;

&lt;p&gt;Install &lt;code&gt;next-themes&lt;/code&gt;. Next-themes provides a wrapper to wrap the part of the application where we want theme switching. We will wrap up our entire application.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;npm install next-themes&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Create a theme provider (the wrapper). Create a new file &lt;code&gt;theme-provider.tsx&lt;/code&gt; and paste the following code.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;theme-provider.tsx&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;use client&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;React&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;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ThemeProvider&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;NextThemesProvider&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;next-themes&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;ThemeProvider&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="nx"&gt;props&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;NextThemesProvider&lt;/span&gt; &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;props&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;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;NextThemesProvider&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;Make sure to add "use client" at top of the file because this must be a client component not server component. Then we import ThemeProvider from "next-themes" and return it with children.&lt;/p&gt;

&lt;p&gt;Next let's wrap the root layout with ThemeProvider. &lt;code&gt;app/layout.tsx&lt;/code&gt; is again a special file in NextJs. The style and content in layout is applied to the entire app.&lt;/p&gt;

&lt;p&gt;So, wrapping layout with ThemeProvider will add theme-switching to the entire app.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;layouts.tsx&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="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;html&lt;/span&gt; &lt;span class="na"&gt;lang&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;inter&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ThemeProvider&lt;/span&gt;
          &lt;span class="na"&gt;attribute&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"class"&lt;/span&gt;
          &lt;span class="na"&gt;defaultTheme&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"system"&lt;/span&gt;
          &lt;span class="na"&gt;enableSystem&lt;/span&gt;
          &lt;span class="na"&gt;disableTransitionOnChange&lt;/span&gt;
        &lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ModeToggle&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;children&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;ThemeProvider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;body&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;html&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;Okay, now all we need to do is add a theme toggle button. Notice in the above code there is a component &lt;code&gt;&amp;lt;ModeToggle /&amp;gt;&lt;/code&gt;. Let's create that component and we will be done.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;modle-toggle.jsx&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;use client&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;React&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;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Moon&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Sun&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;lucide-react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useTheme&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;next-themes&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Button&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;@/components/ui/button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;DropdownMenu&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;DropdownMenuContent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;DropdownMenuItem&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;DropdownMenuTrigger&lt;/span&gt;&lt;span class="p"&gt;,&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;@/components/ui/dropdown-menu&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;ModeToggle&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;setTheme&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useTheme&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;DropdownMenu&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;DropdownMenuTrigger&lt;/span&gt; &lt;span class="na"&gt;asChild&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt; &lt;span class="na"&gt;variant&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"outline"&lt;/span&gt; &lt;span class="na"&gt;size&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"icon"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Sun&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Moon&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"absolute h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;span&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"sr-only"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Toggle theme&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;span&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;DropdownMenuTrigger&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;DropdownMenuContent&lt;/span&gt; &lt;span class="na"&gt;align&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"end"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;DropdownMenuItem&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setTheme&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;light&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          Light
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;DropdownMenuItem&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;DropdownMenuItem&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setTheme&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dark&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          Dark
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;DropdownMenuItem&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;DropdownMenuItem&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setTheme&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;system&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          System
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;DropdownMenuItem&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;DropdownMenuContent&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;DropdownMenu&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;The above code adds a dropdown menu to switch between light, dark, and system. The dropdown is a shadcn-ui component. So let's add that component to our project.&lt;/p&gt;

&lt;p&gt;Run the following command.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;npx shadcn-ui@latest add dropdown-menu&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This will add dropdown-menu component in &lt;code&gt;component/ui/dropdown-menu.tsx&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Break down of few important things in mode-toggle.jsx:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;setTheme sets the theme (light, dark, or system) in the provider so that it is accessible to the entire app.&lt;/li&gt;
&lt;li&gt;The tailwindCSS of Sun and Moon elements.

&lt;ul&gt;
&lt;li&gt;Sun (scale-100 dark:scale-0): Sun icon width becomes 0 when theme is dark so that it is not visible in dark mode.&lt;/li&gt;
&lt;li&gt;Moon (scale-0 dark:scale-100): Moon icon width becomes 100% when theme is dark so that is is visible in dark mode.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;And vice versa.&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Cool, now go ahead and try to switch the theme.&lt;/p&gt;

&lt;p&gt;Congrats!&lt;/p&gt;

&lt;p&gt;Oh wait, what? It is not working. Ya, it won't work because we have a little bug.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gotcha
&lt;/h2&gt;

&lt;p&gt;Right now the theme switching won't work because of a small bug.&lt;/p&gt;

&lt;p&gt;See we are using &lt;code&gt;tsx&lt;/code&gt; and &lt;code&gt;jsx&lt;/code&gt; both in our application. But NextJs was initiated with typescript configurations so tailwind ignores our jsx files. Just add the js and jsx in tailwind config.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;tailwind.config.ts&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;config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;darkMode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;class&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./pages/**/*.{ts,tsx,js,jsx}&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./components/**/*.{ts,tsx,js,jsx}&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./app/**/*.{ts,tsx,js,jsx}&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/**/*.{ts,tsx,js,jsx}&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that is it.&lt;/p&gt;

&lt;p&gt;Now our theme switching is working perfectly fine. You can check the final project at the preview link provided at top.&lt;/p&gt;




&lt;p&gt;Your users are gonna love you for giving them a dark mode.&lt;/p&gt;

&lt;p&gt;Reply/comment to this email/post if you have any suggestion on which feature should I build next.&lt;/p&gt;

&lt;p&gt;If you found this useful, join the &lt;a href="https://diaryofadev.ck.page" rel="noopener noreferrer"&gt;newsletter&lt;/a&gt; for such posts every week.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>nextjs</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Build a password strength indicator in ReactJs.</title>
      <dc:creator>Swastik Yadav</dc:creator>
      <pubDate>Wed, 13 Mar 2024 07:07:19 +0000</pubDate>
      <link>https://forem.com/swastikyadav/build-a-password-strength-indicator-in-reactjs-mfm</link>
      <guid>https://forem.com/swastikyadav/build-a-password-strength-indicator-in-reactjs-mfm</guid>
      <description>&lt;p&gt;Hello Devs,&lt;/p&gt;

&lt;p&gt;This feature is the latest issue of my newsletter where I am building one complex frontend feature every week.&lt;/p&gt;

&lt;p&gt;And share the breakdown of the thought process and design behind it.&lt;/p&gt;

&lt;p&gt;Join the newsletter: &lt;a href="https://diaryofadev.ck.page/" rel="noopener noreferrer"&gt;https://diaryofadev.ck.page/&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Today we are building a simple "&lt;strong&gt;Password Strength Indicator&lt;/strong&gt;" in React.&lt;/p&gt;

&lt;p&gt;So, let's dive in to build our second front-end feature.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are we building?
&lt;/h2&gt;

&lt;p&gt;Live Preview: &lt;a href="https://stackblitz.com/edit/vitejs-vite-usrrut?file=src%2FApp.jsx" rel="noopener noreferrer"&gt;https://stackblitz.com/edit/vitejs-vite-usrrut?file=src%2FApp.jsx&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Let the coding begin.
&lt;/h2&gt;

&lt;p&gt;If you have built anything in React previously, this one will be fairly simple for you.&lt;/p&gt;

&lt;p&gt;I would suggest you go ahead and try to build this feature on your own first, then come back and check my solution.&lt;/p&gt;

&lt;p&gt;First thing first, let's show an input element and a strength indicator text on the screen.&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"password"&lt;/span&gt; &lt;span class="na"&gt;placeholder&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Enter your password"&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;small&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Password strength:&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;small&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Cool, now let's make it a controlled component by adding a state for the input value. Along with that, we will add a state to store the strength of the password.&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setPassword&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="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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;strength&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setStrength&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="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="err"&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;input&lt;/span&gt;
    &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"password"&lt;/span&gt;
    &lt;span class="na"&gt;placeholder&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Enter your password"&lt;/span&gt;
    &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="na"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setPassword&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="err"&gt;​&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;small&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Password&lt;/span&gt; &lt;span class="nx"&gt;strength&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;strength&lt;/span&gt;&lt;span class="p"&gt;}&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;/&lt;/span&gt;&lt;span class="na"&gt;small&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now this is a controlled component with input being handled by a local state. We also added strength value in the strength indicator text.&lt;/p&gt;

&lt;p&gt;But wait, How are we gonna calculate the strength of the password entered by the user?&lt;/p&gt;

&lt;p&gt;First, let's decide what we consider as a strong password. A password is strong if it has the following features.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Minimum 8 characters.&lt;/li&gt;
&lt;li&gt;Contains lowercase letters.&lt;/li&gt;
&lt;li&gt;Contains uppercase letters.&lt;/li&gt;
&lt;li&gt;Contains number.&lt;/li&gt;
&lt;li&gt;Contains special characters.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, let's write a function that will evaluate the strength of a given password based on the above points.&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;evaluatePasswordStrength&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;score&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="err"&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;password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="err"&gt;​&lt;/span&gt;
  &lt;span class="c1"&gt;// Check password length&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;password&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;score&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="c1"&gt;// Contains lowercase&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;a-z&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="nx"&gt;score&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="c1"&gt;// Contains uppercase&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;A-Z&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="nx"&gt;score&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="c1"&gt;// Contains numbers&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\d&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="nx"&gt;score&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="c1"&gt;// Contains special characters&lt;/span&gt;
  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;[^&lt;/span&gt;&lt;span class="sr"&gt;A-Za-z0-9&lt;/span&gt;&lt;span class="se"&gt;]&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;test&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="nx"&gt;score&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above function adds 1 to the score for each password feature available. The more the score stronger the password. To check for features like lowercase, uppercase, number, and special characters we are using regex.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://regexr.com/" rel="noopener noreferrer"&gt;Regex&lt;/a&gt; is a tool to identify patterns in a string. If you are not familiar with it just google and read the basics of it. It is not that tough. And most of the time your desired regex pattern is just a search away.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Score: 0-2 (Weak password)&lt;/li&gt;
&lt;li&gt;Score: 3 (Medium password)&lt;/li&gt;
&lt;li&gt;Score: 4-5 (Strong password)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Next, we determine and set the strength state based on the above points.&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;evaluatePasswordStrength&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;password&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="err"&gt;​&lt;/span&gt;
  &lt;span class="k"&gt;switch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;score&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Weak&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Medium&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Strong&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the &lt;code&gt;onChange&lt;/code&gt; callback where we set the password value, we will also set the strength state to the value that is returned from evaluatePasswordStrength function.&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt;
    &lt;span class="err"&gt;....&lt;/span&gt;
    &lt;span class="na"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&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;setPassword&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nf"&gt;setStrength&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;evaluatePasswordStrength&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And, that is it. Our password strength indicator is ready.&lt;/p&gt;

&lt;p&gt;There is a small addition we can make, but we won't do it here. I give it to you as a challenge to solve. You can check the solution in the final preview link.&lt;/p&gt;

&lt;h2&gt;
  
  
  Challenge
&lt;/h2&gt;

&lt;p&gt;Add a feature to the strength indicator text so that it changes its color based on the strength.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Weak passwords shows in red color.&lt;/li&gt;
&lt;li&gt;Medium password shows in orange color.&lt;/li&gt;
&lt;li&gt;Strong password shows in green color.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Alright!&lt;/p&gt;

&lt;p&gt;That was neat. I will bring more complex features to our future issues.&lt;/p&gt;

&lt;p&gt;Reply/comment to this email/post, if you have any suggestions on which feature should I build in future issues.&lt;/p&gt;

&lt;p&gt;If you enjoyed this issue, you will love other issues of building complex frontend features every week&lt;/p&gt;

&lt;p&gt;Check Here: &lt;a href="https://diaryofadev.ck.page/" rel="noopener noreferrer"&gt;https://diaryofadev.ck.page/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank You!&lt;/p&gt;




</description>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Webpack, The clear and concise explanation.</title>
      <dc:creator>Swastik Yadav</dc:creator>
      <pubDate>Fri, 26 Jan 2024 11:37:43 +0000</pubDate>
      <link>https://forem.com/swastikyadav/webpack-the-clear-and-concise-explanation-4oi2</link>
      <guid>https://forem.com/swastikyadav/webpack-the-clear-and-concise-explanation-4oi2</guid>
      <description>&lt;p&gt;If you have been working with JS for a while, you must have came across webpack. Might have used it as well, but didn't actually know what it does.&lt;/p&gt;

&lt;p&gt;At least for me it didn't made sense when I first tried it. I just copied &amp;amp; pasted config files from internet and somehow made it to work.&lt;/p&gt;

&lt;p&gt;Infact that is the reason for tools like "create-react-app" to exist. Because it was too complex for beginners to setup a React app from scratch with webpack.&lt;/p&gt;

&lt;p&gt;So, let's understand what's the deal with webpack.&lt;/p&gt;

&lt;p&gt;We are going to build a small Product-Listing app and understand webpack in the proccess.&lt;/p&gt;

&lt;h2&gt;
  
  
  Initiating Product-Listing App.
&lt;/h2&gt;

&lt;p&gt;Let's start by setting up our project folders.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;productList
&lt;span class="nb"&gt;cd&lt;/span&gt; ./productList
&lt;span class="nb"&gt;mkdir &lt;/span&gt;public src
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will work with "src" and "pulic" folders later. For now we will initiate vanilla JS project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above command will ask few questions, just accept all default configs. Now we have a package.json file in our project.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installing Dependencies
&lt;/h3&gt;

&lt;p&gt;Run the following command in project directory. We will talk about each dependency later.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;faker html-webpack-plugin webpack webpack-cli webpack-dev-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Adding entry HTML and JS files.
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ./public
touch index.html
// This simply creates index.html file in public folder.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside the &lt;code&gt;public/index.html&lt;/code&gt; all we need to do is add a root element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;html&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;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"root"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&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;p&gt;Now we add "index.js" inside &lt;code&gt;src&lt;/code&gt; folder.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ./src
touch index.js
// This simply creates index.js file inside src.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside &lt;code&gt;src/index.js&lt;/code&gt; import "faker" and console a fake productName. Faker just provides some fake data to work with. Nothing fancy here.&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="nx"&gt;faker&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;faker&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;productName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;faker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;commerce&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;productName&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;productName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;pn++&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;Okay, now if we try to execute this file in terminal. We will get an error.&lt;br&gt;
You can add this js file as script in &lt;code&gt;index.html&lt;/code&gt; but that's not what we want. Neither that will be able to import faker from node_modules.&lt;/p&gt;

&lt;p&gt;By the way we can execute the above file with "CJS require". But instead let's just make the "ESM import" work with webpack.&lt;/p&gt;
&lt;h2&gt;
  
  
  Webpack Configuration
&lt;/h2&gt;

&lt;p&gt;Create a new file &lt;code&gt;webpack.config.js&lt;/code&gt; in the root of project directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;touch webpack.config.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's configure webpack and understand the installed packages.&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="c1"&gt;// Require HtmlWebpackPlugin&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;HtmlWebpackPlugin&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;html-webpack-plugin&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// mode will change to "production" in `webpack.prod.js`&lt;/span&gt;
    &lt;span class="na"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;development&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="c1"&gt;// port where our main.js will become available.&lt;/span&gt;
    &lt;span class="na"&gt;devServer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;8081&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="na"&gt;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;HtmlWebpackPlugin&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="c1"&gt;// Whatever file names coming out from webpack will be used as the entry point.&lt;/span&gt;
            &lt;span class="c1"&gt;// And will be added as script to the template (public/index.html).&lt;/span&gt;
            &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./public/index.html&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  webpack-dev-server
&lt;/h3&gt;

&lt;p&gt;WebpackDevServer takes main.js (output by webpack) and makes it available to the browser.&lt;/p&gt;

&lt;h3&gt;
  
  
  html-webpack-plugin
&lt;/h3&gt;

&lt;p&gt;HtmlWebpackPlugin takes whatever file name webpack generates (main.js) and adds it as script in &lt;code&gt;/public/index.html&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Change the start script in &lt;code&gt;package.json&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="err"&gt;//...rest&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;of&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;code...&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"webpack serve"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;//...rest&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;of&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;code...&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run the start script.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the &lt;code&gt;main.js&lt;/code&gt; is available on the browser. Open &lt;em&gt;&lt;a href="http://localhost:8081/main.js" rel="noopener noreferrer"&gt;http://localhost:8081/main.js&lt;/a&gt;&lt;/em&gt; in browser. We can see the source code generated by webpack. If we search we will find our productList code and faker package as well in this file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fswastikyadav.com%2Fstatic%2F540f4dca0bcc90958b0f621f513eec78%2F369bf%2Fmainjs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fswastikyadav.com%2Fstatic%2F540f4dca0bcc90958b0f621f513eec78%2F369bf%2Fmainjs.png" alt="mainjs on browser" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hmm, nice. Now just open &lt;em&gt;&lt;a href="http://localhost:8081" rel="noopener noreferrer"&gt;http://localhost:8081&lt;/a&gt;&lt;/em&gt;. This will serve &lt;code&gt;index.html&lt;/code&gt; file with &lt;code&gt;main.js&lt;/code&gt; added as script in html file.&lt;/p&gt;

&lt;p&gt;Open console and see the productName appear there. Let's show productName on the screen. Make following changes in &lt;code&gt;src/index.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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;faker&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;@faker-js/faker&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;rootElm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#root&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="nf"&gt;mount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;elm&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;products&lt;/span&gt; &lt;span class="o"&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;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&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;productName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;faker&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;commerce&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;productName&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nx"&gt;products&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="s2"&gt;`&amp;lt;div&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;productName&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;/div&amp;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;elm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;products&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;mount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;rootElm&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Checking &lt;em&gt;&lt;a href="http://localhost:8081" rel="noopener noreferrer"&gt;http://localhost:8081&lt;/a&gt;&lt;/em&gt; on browser should show product lists on the screen.&lt;/p&gt;

&lt;p&gt;Alright, let's see some explanation around webpack.&lt;/p&gt;

&lt;h2&gt;
  
  
  Webpack Explanation
&lt;/h2&gt;

&lt;p&gt;Normally we would have to load many different files on the browser. For ex, if our application uses multiple files and external libraries. We would have to load each file on the browser.&lt;/p&gt;

&lt;p&gt;As a rule of thumb, we should not load many diff files on browser. And that's where webpack comes in.&lt;/p&gt;

&lt;p&gt;Webpack &lt;em&gt;&lt;code&gt;combines/bundles&lt;/code&gt;&lt;/em&gt; all those files into single file which can be loaded on the browser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fswastikyadav.com%2Fstatic%2Fe3efb9662acb9c656a302a6669906e8d%2F39ea5%2Fwebpack-exp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fswastikyadav.com%2Fstatic%2Fe3efb9662acb9c656a302a6669906e8d%2F39ea5%2Fwebpack-exp.png" alt="webpack-usecase" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;main.js&lt;/code&gt;/&lt;code&gt;bundle.js&lt;/code&gt; not only contains our &lt;code&gt;src/index.js&lt;/code&gt; code but all other imported dependency code as well.&lt;/p&gt;

&lt;p&gt;Webpack officially calls themselves a "module bundler". Not only scripts, but it helps you bundle styles and assets as well.&lt;/p&gt;




&lt;p&gt;So, that is all for this post. Hopefully this was a good read for you.&lt;/p&gt;

&lt;p&gt;Original Post: &lt;a href="https://swastikyadav.com/webpack-the-clear-and-concise-explanation" rel="noopener noreferrer"&gt;https://swastikyadav.com/webpack-the-clear-and-concise-explanation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank You!&lt;/p&gt;

</description>
      <category>webpack</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>5 JavaScript Project Ideas Beyond TODO Apps.</title>
      <dc:creator>Swastik Yadav</dc:creator>
      <pubDate>Fri, 20 Oct 2023 08:18:22 +0000</pubDate>
      <link>https://forem.com/swastikyadav/5-javascript-project-ideas-beyond-todo-apps-h9h</link>
      <guid>https://forem.com/swastikyadav/5-javascript-project-ideas-beyond-todo-apps-h9h</guid>
      <description>&lt;p&gt;&lt;strong&gt;Tired of building Todo apps?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;✨ 5 JavaScript project ideas beyond TODO apps.&lt;/p&gt;

&lt;p&gt;These projects will challenge you to get out of your comfort zone learn something new and implement it.&lt;/p&gt;

&lt;p&gt;Let start!&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;1️⃣ Timeline Scrolling&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Develop a web app that documents a series of historic events. Ideally, dates are separated evenly and make use of infinite scrolling.&lt;/p&gt;

&lt;p&gt;For example, scrolling back to the 1980s is quick but scrolling back to the age of the dinosaurs is tedious.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;2️⃣ Article Navigator&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Provide a browser extension that outlines articles and shows a minimap of the page with scroll features.&lt;/p&gt;

&lt;p&gt;The idea is to always have an accessible table of contents and quickly view the page structure without scrolling.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;3️⃣ Digital Business Card&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Develop a single-page app that is the equivalent of a business card.&lt;/p&gt;

&lt;p&gt;Provide your contact information, social media links, and a short description of what you do.&lt;/p&gt;

&lt;p&gt;Let the user decide to share it publically or only with selected people.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;4️⃣ Pailgarism Checker&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Display the similarities between two text inputs, or two files, and provide a score that states how similar they are.&lt;/p&gt;

&lt;p&gt;Show the comparison in 2 files like how it is compared on GitHub.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;5️⃣ Meme Platform&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Use Giphy API to build your own searchable platform of memes.&lt;/p&gt;




&lt;p&gt;If you found this post valuable, consider following on &lt;a href="https://www.linkedin.com/in/swastikyadav/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank You!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>projects</category>
      <category>programming</category>
    </item>
    <item>
      <title>From dropout to developer.</title>
      <dc:creator>Swastik Yadav</dc:creator>
      <pubDate>Thu, 19 Oct 2023 04:13:53 +0000</pubDate>
      <link>https://forem.com/swastikyadav/from-dropout-to-developer-ieo</link>
      <guid>https://forem.com/swastikyadav/from-dropout-to-developer-ieo</guid>
      <description>&lt;p&gt;&lt;strong&gt;2018&lt;/strong&gt;&lt;br&gt;
A college dropout, broke, in debt, completely clueless about life.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2023&lt;/strong&gt;&lt;br&gt;
A well-paid Software Engineer, helping others learn to code.&lt;/p&gt;

&lt;p&gt;Here is what made it possible:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1/ Willingness To Learn&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I was/am always willing to learn.&lt;/p&gt;

&lt;p&gt;Don't see challenges as obstacles but an opportunity to learn new things.&lt;/p&gt;

&lt;p&gt;Growth mindset, not fixed mindset.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2/ Building Social Presence&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I had an active blog from the beginning, even when I was just learning.&lt;/p&gt;

&lt;p&gt;Don't wait to learn everything before you show your skills to the world.&lt;/p&gt;

&lt;p&gt;Have a blog from the start.&lt;/p&gt;

&lt;p&gt;You won't believe how many opportunities I have received just because of my blog.&lt;/p&gt;

&lt;p&gt;Building a social presence doesn't mean having 1000s of followers. You are just putting your work out in the world.&lt;/p&gt;

&lt;p&gt;(My blog: &lt;a href="https://swastikyadav.com" rel="noopener noreferrer"&gt;https://swastikyadav.com&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3/ Law Of Average&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The more you do something, more are the chances of you getting the desired result.&lt;/p&gt;

&lt;p&gt;A friend of mine (whom I taught to code) literally gave 500+ interviews before he finally got selected.&lt;/p&gt;

&lt;p&gt;Each failure takes you closer to success.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4/ Community&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There were times when I felt like giving up but being in a community of dedicated learners helped me keep going.&lt;/p&gt;

&lt;p&gt;Collaboration not Competition.&lt;/p&gt;

&lt;p&gt;–––––––––––––––––––––––&lt;/p&gt;

&lt;p&gt;Was it easy? Not at all.&lt;br&gt;
If there is a secret that I learned through my experience then it is this:&lt;/p&gt;

&lt;p&gt;Consistency + Intensity&lt;/p&gt;

&lt;p&gt;–––––––––––––––––––––––&lt;/p&gt;

&lt;p&gt;Thanks a lot for reading.&lt;/p&gt;

&lt;p&gt;If you liked this&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Follow me on &lt;a href="https://twitter.com/swastikb380" rel="noopener noreferrer"&gt;X (Twitter)&lt;/a&gt; and &lt;a href="https://www.linkedin.com/in/swastikyadav/" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;See you next time with more valuable life and developer lessons.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Swastik Yadav&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>motivation</category>
      <category>career</category>
    </item>
    <item>
      <title>9 reasons why you should learn to code in the age of no-code tools &amp; gain an unfair advantage.</title>
      <dc:creator>Swastik Yadav</dc:creator>
      <pubDate>Fri, 07 Oct 2022 08:04:22 +0000</pubDate>
      <link>https://forem.com/swastikyadav/9-reasons-why-you-should-learn-to-code-in-the-age-of-no-code-tools-gain-an-unfair-advantage-32mb</link>
      <guid>https://forem.com/swastikyadav/9-reasons-why-you-should-learn-to-code-in-the-age-of-no-code-tools-gain-an-unfair-advantage-32mb</guid>
      <description>&lt;p&gt;Every month a new no-code tool pops-ups in the market, just like a new JavaScript library or framework.&lt;/p&gt;

&lt;p&gt;3 Years ago when I was learning to code (I'm still learning).&lt;/p&gt;

&lt;p&gt;I use to wonder if no-code tools will ever replace web-developers. And today I do have an answer.&lt;/p&gt;

&lt;p&gt;And the answer is "Never".&lt;/p&gt;

&lt;p&gt;No-code tools are great and all, quick to launch and market. Lately many people started to think that no-code means no more coding and developers are obsolete now.&lt;/p&gt;

&lt;p&gt;But the truth is exact opposite.&lt;/p&gt;

&lt;p&gt;Here are the 9 reasons to learn programming &amp;amp; gain unfair advantage even in the age of no-code tools.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Here is the video on this topic&lt;br&gt;
&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/tJDTopz_uCg"&gt;
&lt;/iframe&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  1. Add-ons / Plugins
&lt;/h2&gt;

&lt;p&gt;How do you create addons and plugins.&lt;/p&gt;

&lt;p&gt;Programming knowledge is required to create addons and plugins which run these platforms. Be a creator of these addons not just a consumer.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Development Methodology
&lt;/h2&gt;

&lt;p&gt;Code or no-code doesn't matter without the right development methodology.&lt;/p&gt;

&lt;p&gt;You need the right development methodology to create something meaningful regardless of code or no-code. And the best way to learn development methodology is to learn to code.&lt;/p&gt;

&lt;p&gt;Agile, Scrum, Lean, or Waterfall. Just name it. &lt;/p&gt;

&lt;h2&gt;
  
  
  3. Security and stability
&lt;/h2&gt;

&lt;p&gt;Your business is at risk.&lt;/p&gt;

&lt;p&gt;All your and your project data is integrated with a 3rd party tool. Higher the layer of integrations, higher the level of security risk.&lt;/p&gt;

&lt;p&gt;What if they misuse it, what if the tool goes outdated or shuts down.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Developer Value
&lt;/h2&gt;

&lt;p&gt;No-code tools make developers / programmers more valuable.&lt;/p&gt;

&lt;p&gt;It may seem that no-code tool is here to replace developers, but the truth is that they increases the value of a developer. Because, Now you realize that no-code cann't create what a highly efficient team of developers can.&lt;/p&gt;

&lt;p&gt;And, from this comes our next point.&lt;/p&gt;

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

&lt;p&gt;No-code tools are limited in terms of building highly customizable and large-scale platform.&lt;/p&gt;

&lt;p&gt;These tools are good to create landing pages, and basic web apps. But they have limitations beyond that point.&lt;/p&gt;

&lt;p&gt;Migrations is really tough. What if later on you realize that a specific tool is not fulfilling your needs and you need to migrate. It is not easy to do so.&lt;/p&gt;

&lt;p&gt;There again, only a highly skilled developer can rescue you.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. Learning curve
&lt;/h2&gt;

&lt;p&gt;No-code tools have their own learning curve.&lt;/p&gt;

&lt;p&gt;You need to learn and invest enough time to use these solutions efficiently. Some of these tools may take you a week to properly learn and star using.&lt;/p&gt;

&lt;p&gt;Well, you can learn and get started with ReactJs over a weekend.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. No-code tools are machine, but you are not
&lt;/h2&gt;

&lt;p&gt;No-code tools are just machines.&lt;/p&gt;

&lt;p&gt;They cann't interact with a client and understand their pain points to build a tailored solution for them. But you can, and that's what makes you invaluable and irreplaceable as a human developer.&lt;/p&gt;

&lt;p&gt;No machine can replace humanly interactions.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Learn to think
&lt;/h2&gt;

&lt;p&gt;Learning to code teaches you how to think.&lt;/p&gt;

&lt;p&gt;When you learn to code, your perpective toward the world changes. You start looking at everything with a more logical approach.&lt;/p&gt;

&lt;p&gt;You become a problem solver.&lt;/p&gt;

&lt;h2&gt;
  
  
  9. No-code is not really no-code
&lt;/h2&gt;

&lt;p&gt;No-code tools are not really no-code.&lt;/p&gt;

&lt;p&gt;No-code tools are build on top of code. So, there is no such thing as no-code. It is just layer of UIs to hide the code implementation.&lt;/p&gt;

&lt;p&gt;At last, all that matters is code.&lt;/p&gt;




&lt;p&gt;At the end of the day, no-code tools are just tools. Tools will come and go, but HTML, CSS, and JS are here to stay.&lt;/p&gt;

&lt;p&gt;So, learn them well.&lt;/p&gt;

&lt;p&gt;And, that is the true source of developer's value.&lt;/p&gt;




&lt;p&gt;That's it for this post, I hope you found this useful, and if so, please show your support by joining the weekly newsletter: &lt;a href="https://www.getrevue.co/profile/8020lessons" rel="noopener noreferrer"&gt;8020 Newsletter&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Master and learn JavaScript like never before: &lt;a href="https://8020lessons.in" rel="noopener noreferrer"&gt;https://8020lessons.in&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Understand call, apply, and bind functions in JavaScript like never before.</title>
      <dc:creator>Swastik Yadav</dc:creator>
      <pubDate>Fri, 23 Sep 2022 10:18:37 +0000</pubDate>
      <link>https://forem.com/swastikyadav/understand-call-apply-and-bind-functions-in-javascript-like-never-before-575e</link>
      <guid>https://forem.com/swastikyadav/understand-call-apply-and-bind-functions-in-javascript-like-never-before-575e</guid>
      <description>&lt;p&gt;In this post, we'll take a detailed look at how call, apply, and bind work in JavaScript.&lt;/p&gt;

&lt;p&gt;JavaScript's call(), apply(), and bind() functions are often misunderstood. In this video, we'll clear up the confusion once and for all.&lt;/p&gt;

&lt;p&gt;We'll discuss the differences between the three, and when you would want to use each one. We'll also provide examples to help you understand how they work.&lt;/p&gt;

&lt;p&gt;By the end of this post, you'll have a deep understanding of how these functions work, and be able to use them in your own code.&lt;/p&gt;

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

&lt;p&gt;Now, let's start for real.&lt;/p&gt;




&lt;p&gt;Let's say we have an object with name and greet function.&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;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;Swastik&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`Hello &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="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;, age: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&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;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// console -&amp;gt; Hello Swastik, age: 23&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Calling the greeet function consoles "Hello Swastik". The &lt;code&gt;**"this"**&lt;/code&gt; keyword refers to the context of greet() function.&lt;/p&gt;

&lt;p&gt;In other words &lt;code&gt;**"this"**&lt;/code&gt; keywords for greet() function refers to the object (obj) in which it was defined.&lt;/p&gt;

&lt;p&gt;Now, let's say you need to &lt;strong&gt;change the context&lt;/strong&gt; of greet() function, means you need to change where the "this" keyword refers in greet() function from &lt;code&gt;obj&lt;/code&gt; to &lt;code&gt;obj1&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let's define obj1.&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;obj1&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;Yadav&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;What we want to achieve is that when we call greet() function it should console "Hello Yadav" instead of "Hello Swastik".&lt;/p&gt;

&lt;p&gt;This can be achieved with call(), apply(), and bind() method in JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  call()
&lt;/h2&gt;

&lt;p&gt;"call" method changes the context of a given function to the context that we specify. So here we are changing the context of greet from obj to obj1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;call&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// console -&amp;gt; Hello Yadav, age: 24&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First argument is the new context we want, and all comma separated arguments are for greet function.&lt;/p&gt;

&lt;h2&gt;
  
  
  apply()
&lt;/h2&gt;

&lt;p&gt;"apply" method is exactly similar to "call method", the only difference being that call takes argument of greet as comma separated and apply takes them as an array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;obj&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;greet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;24&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt; &lt;span class="c1"&gt;// console -&amp;gt; Hello Yadav, age: 24&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  bind()
&lt;/h2&gt;

&lt;p&gt;"bind" is also exactly similar to call and apply, and here is the difference.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;call and apply executes the fuction right away.&lt;/li&gt;
&lt;li&gt;bind returns a new function binded with new "this" keyword, which can be called later.
&lt;/li&gt;
&lt;/ul&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;bindYadav&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;greet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;bind&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;obj1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nf"&gt;bindYadav&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// console.log -&amp;gt; Hello Yadav, age: 25&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;That's it for this post, I hope you found this useful, and if so, please show your support by joining the weekly newsletter: &lt;a href="https://swastikyadav.com" rel="noopener noreferrer"&gt;Newsletter&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
