<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Md Anas Sabah</title>
    <description>The latest articles on DEV Community by Md Anas Sabah (@mdanassabah).</description>
    <link>https://dev.to/mdanassabah</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%2F883569%2F928351a5-e178-4a5b-8d1c-8f5ce18b69d8.jpg</url>
      <title>DEV Community: Md Anas Sabah</title>
      <link>https://dev.to/mdanassabah</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mdanassabah"/>
    <language>en</language>
    <item>
      <title>The Art of Deep Comparison in JavaScript (No Loops Required!)</title>
      <dc:creator>Md Anas Sabah</dc:creator>
      <pubDate>Mon, 12 May 2025 15:17:19 +0000</pubDate>
      <link>https://dev.to/mdanassabah/the-art-of-deep-comparison-in-javascript-no-loops-required-3fg2</link>
      <guid>https://dev.to/mdanassabah/the-art-of-deep-comparison-in-javascript-no-loops-required-3fg2</guid>
      <description>&lt;p&gt;&lt;strong&gt;✅ Understanding the Goal&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You're being asked to implement a function called deepEqual(valueA, valueB) that checks if two values (which can be primitives, objects, or arrays) are deeply equal.&lt;/p&gt;

&lt;p&gt;The keyword here is deep, this means we can’t just check equality on the surface (like ===), especially for things like objects and arrays. We need to go into nested levels and check if all elements or properties match recursively.&lt;/p&gt;

&lt;p&gt;🧠 &lt;strong&gt;Think Like This, Before you jump into code, ask yourself questions like:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;-&amp;gt; What types of values can valueA and valueB be?&lt;/p&gt;

&lt;p&gt;-&amp;gt; How do I handle primitive types vs arrays vs objects?&lt;/p&gt;

&lt;p&gt;-&amp;gt; What does it mean for arrays or objects to be “equal”?&lt;/p&gt;

&lt;p&gt;-&amp;gt; Should I use recursion?&lt;/p&gt;

&lt;p&gt;🤔&lt;strong&gt;Design Your Thinking Strategy:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Base case: If a === b, return true.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Type check:&lt;/p&gt;

&lt;p&gt;If types differ, return false.&lt;/p&gt;

&lt;p&gt;If both are arrays:&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check length.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Recursively compare each element.&lt;/p&gt;

&lt;p&gt;If both are objects (but not arrays):&lt;/p&gt;

&lt;p&gt;Compare keys.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Recursively compare each corresponding value.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Otherwise: return false.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;🔁 &lt;strong&gt;Why Recursion? Why Loops Alone Aren’t Enough?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A simple for loop works great when you're comparing flat structures, like two arrays of numbers. But when the data can go many levels deep , arrays inside objects inside arrays, etc. you’d need:&lt;/p&gt;

&lt;p&gt;a loop inside a loop inside a loop... 😵&lt;/p&gt;

&lt;p&gt;or a smarter approach that can handle any depth&lt;/p&gt;

&lt;p&gt;That’s Where &lt;strong&gt;Recursion&lt;/strong&gt; Shines.&lt;/p&gt;

&lt;p&gt;Recursion is perfect for tree-like or nested structures, because you can say:&lt;/p&gt;

&lt;p&gt;“If the current level is an array or object, go deeper and run the same logic again.”&lt;/p&gt;

&lt;p&gt;So your function ends up being clean and adaptable to any depth.&lt;/p&gt;

&lt;p&gt;⚡️&lt;strong&gt;Implementation of the deepEqual function using recursion:&lt;/strong&gt;&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%2F63u35mtu81ykuwq6ozal.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%2F63u35mtu81ykuwq6ozal.png" alt="Image description" width="800" height="1135"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;With a clear understanding of recursion and careful handling of data types, you now have a robust deepEqual function that can accurately compare even the most nested structures, a must-have tool in any JavaScript developer's toolkit.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>algorithms</category>
      <category>interview</category>
    </item>
    <item>
      <title>Understanding JSON Web Tokens (JWT)</title>
      <dc:creator>Md Anas Sabah</dc:creator>
      <pubDate>Sat, 30 Dec 2023 17:28:42 +0000</pubDate>
      <link>https://dev.to/mdanassabah/understanding-json-web-tokens-jwt-3n68</link>
      <guid>https://dev.to/mdanassabah/understanding-json-web-tokens-jwt-3n68</guid>
      <description>&lt;p&gt;JSON Web Tokens (JWT) are a compact, URL-safe means of representing claims to be transferred between two parties. In web development, JWTs are commonly used for authentication and information exchange between a client and a server. This article will explore the basics of JWT, how they work, and how to implement them using React.js and Express.js.&lt;/p&gt;

&lt;h4&gt;
  
  
  What is JWT?
&lt;/h4&gt;

&lt;p&gt;A JSON Web Token is a self-contained, compact way of representing information between two parties. It consists of three parts:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Header: Contains information about how the JWT is encoded, such as the type of token and the signing algorithm.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Payload: Contains the claims. Claims are statements about an entity (typically, the user) and additional data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Signature: To create the signature part you have to take the encoded header, the encoded payload, a secret, the algorithm specified in the header, and sign that.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These three parts are concatenated with dots ('.') to form the JWT.&lt;/p&gt;

&lt;h4&gt;
  
  
  How JWT Works?
&lt;/h4&gt;

&lt;h6&gt;
  
  
  1. Authentication:
&lt;/h6&gt;

&lt;ul&gt;
&lt;li&gt;A user logs in with their credentials.&lt;/li&gt;
&lt;li&gt;Upon successful authentication, the server generates a JWT and sends it to the 
client.&lt;/li&gt;
&lt;/ul&gt;

&lt;h6&gt;
  
  
  2. Authorization:
&lt;/h6&gt;

&lt;ul&gt;
&lt;li&gt;The client includes the JWT in the header of subsequent requests to the server.&lt;/li&gt;
&lt;li&gt;The server validates the JWT and grants access based on the claims it contains.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Implementation with React.js
&lt;/h4&gt;

&lt;p&gt;Let's create a simple React.js application that includes JWT authentication.&lt;/p&gt;

&lt;h6&gt;
  
  
  1. Install Dependencies:
&lt;/h6&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%2Fg5agy0p2oyt4zzwoh6nd.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%2Fg5agy0p2oyt4zzwoh6nd.png" alt="Image description1" width="800" height="395"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h6&gt;
  
  
  2. Install Axios for HTTP Requests:
&lt;/h6&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%2Fmq3q6af5w916tf79yhuh.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%2Fmq3q6af5w916tf79yhuh.png" alt="Image description2" width="800" height="349"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h6&gt;
  
  
  3. Create a Login Component:
&lt;/h6&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%2Fetiy0bo2umfygw4gh0a8.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%2Fetiy0bo2umfygw4gh0a8.png" alt="Image description3" width="800" height="1023"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h6&gt;
  
  
  4. Create a Protected Component:
&lt;/h6&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%2F4jgvru763w6i70eibnkd.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%2F4jgvru763w6i70eibnkd.png" alt="Image description5" width="800" height="663"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Implementation with Express.js
&lt;/h4&gt;

&lt;p&gt;Now, let's create a simple Express.js server that handles JWT authentication.&lt;/p&gt;

&lt;h6&gt;
  
  
  1. Install Dependencies:
&lt;/h6&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%2F92zmidctcv29knx3ba5g.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%2F92zmidctcv29knx3ba5g.png" alt="Image description5" width="800" height="366"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h6&gt;
  
  
  2. Create an Server File(Server.js):
&lt;/h6&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%2Fh7zom4hmwt40w9j5cpge.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%2Fh7zom4hmwt40w9j5cpge.png" alt="Image description6" width="800" height="1055"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In conclusion, delving into the realm of JSON Web Tokens has unveiled a powerful tool for secure and efficient authentication in web development. As we deciphered the intricacies of JWT, we explored its inner workings and practical applications. Now equipped with this knowledge, you have the key to implementing robust authentication systems, ensuring data integrity, and enhancing user experiences. Remember, the journey of understanding JWT is just the beginning. As technology evolves, so does the world of web development, and JWT remains a fundamental aspect of ensuring secure and seamless user interactions. Whether you're a seasoned developer or just embarking on your coding journey, harnessing the potential of JSON Web Tokens opens doors to a safer and more connected digital landscape. Happy coding!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>jwt</category>
      <category>programming</category>
      <category>learning</category>
    </item>
    <item>
      <title>Callback Hell and Promises</title>
      <dc:creator>Md Anas Sabah</dc:creator>
      <pubDate>Mon, 03 Apr 2023 19:02:28 +0000</pubDate>
      <link>https://dev.to/mdanassabah/callback-hell-and-promises-4mo1</link>
      <guid>https://dev.to/mdanassabah/callback-hell-and-promises-4mo1</guid>
      <description>&lt;p&gt;For understanding the concept of &lt;strong&gt;Callback Hell&lt;/strong&gt;, I think you should know about &lt;strong&gt;Callback&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;What is Callback?&lt;br&gt;
Callback is a powerful way to do asynchronous thing in JavaScript. It is a function which is to be executed after another function has finished execution.&lt;/p&gt;

&lt;p&gt;Suppose, we have an E-commerce Application where we have createOrder and proceedToPayment function which have to execute one after another respectively.&lt;br&gt;
We have dependency between those two , We can manage those dependency in our code using callback because it's an async operation.&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%2Fgc8fna4lylixczsill3l.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%2Fgc8fna4lylixczsill3l.png" alt="callback" width="800" height="444"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;When JavaScript Engine executes this code it will just call the createOrder api.&lt;br&gt;
Now it is responsibility of createOrder function to callback proceedToPayment api&lt;/em&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Issues with Callback
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;1.&lt;/code&gt; Inversion of Control&lt;br&gt;
&lt;code&gt;2.&lt;/code&gt; Callback Hell&lt;/p&gt;
&lt;h4&gt;
  
  
  Inversion of Control
&lt;/h4&gt;

&lt;p&gt;Inversion of control is like you loose the control of code when you are using callback.&lt;/p&gt;
&lt;h4&gt;
  
  
  Callback Hell
&lt;/h4&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%2Fz52zdyiqmfesx63ggc8s.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%2Fz52zdyiqmfesx63ggc8s.png" alt="callback hell" width="800" height="625"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You are seeing now a nesting of functions here and code also looks scary and this is what we called &lt;strong&gt;Callback Hell&lt;/strong&gt;. For a big application it creates more nesting.&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%2Fchjtb7l3lptzundml1in.jpeg" 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%2Fchjtb7l3lptzundml1in.jpeg" alt="CallBack hell1" width="721" height="420"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To avoid this, we will see now &lt;strong&gt;Promises&lt;/strong&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Promises
&lt;/h2&gt;

&lt;p&gt;To fix the issue of Inversion of Control and Callback Hell, ES6(ECMAScript 6) Promise is the easier way to work with asynchronous programming in JavaScript.&lt;br&gt;
&lt;em&gt;A promise acts as a container for a future value.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For Example: &lt;code&gt;const promise = createOrder(cart)&lt;/code&gt;&lt;br&gt;
Whenever JavaScript engine executes this line, this &lt;code&gt;createOrder api&lt;/code&gt; will return us a promise.&lt;code&gt;(Promise is nothing but an empty object)&lt;/code&gt; and program will just go on and execute.&lt;br&gt;
But after fetching data from API, promise object get filled automatically.&lt;/p&gt;
&lt;h4&gt;
  
  
  Now how will we attach our callback to that promise?
&lt;/h4&gt;

&lt;p&gt;We will use &lt;code&gt;.then&lt;/code&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;promise.then(function(orderID){
        proceedToPayment(orderID);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This callback function runs automatically after fetching data from api in the promise object.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;Promise&lt;/strong&gt; is an object representing the eventual completion or failure of an asynchronous operation.&lt;/p&gt;

&lt;p&gt;There are three states of promise: &lt;br&gt;
1.pending&lt;br&gt;
2.fulfilled&lt;br&gt;
3.rejected&lt;/p&gt;

&lt;h3&gt;
  
  
  Promise Chaining
&lt;/h3&gt;

&lt;p&gt;Taking example of callback hell we can also do promise chaining&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%2Fmdt568rjsehc3qzicb3g.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%2Fmdt568rjsehc3qzicb3g.png" alt="promise-chaining" width="800" height="661"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;We always return a promise from a promise, when we are chaining it&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Create a Promise
&lt;/h3&gt;

&lt;h5&gt;
  
  
  Consumer Part
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const cart = ["shoes", "pants","kurta"];
const promise = createOrder(cart);
promise.then(function(orderID){
        proceedToPayment(orderID);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  Producer Part:
&lt;/h5&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function createOrder(cart){
   const pr = new Promise(function(resolve,reject){
       //create order
       //validate cart
       //orderID
      if(!validateCart(cart){
            const err = new Error("cart is not valid")
            reject(err);
         }
      const orderID= "1234"
      if(orderID){
         setTimeOut(function(){
              resolve(orderID);
             },5000);
        }
   });


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

&lt;/div&gt;



&lt;p&gt;Thanks for reading this long post! I hope it helped you understand these topics a little better. If you liked this post, then please do give me a few ❤️ and share it if you can. You are welcome to&lt;br&gt;
give any suggestions in comments and ask anything!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Next.js: Next-auth</title>
      <dc:creator>Md Anas Sabah</dc:creator>
      <pubDate>Fri, 14 Oct 2022 16:07:01 +0000</pubDate>
      <link>https://dev.to/mdanassabah/nextjs-next-auth-5856</link>
      <guid>https://dev.to/mdanassabah/nextjs-next-auth-5856</guid>
      <description>&lt;p&gt;In this article, you will see how to authenticate our &lt;strong&gt;Next&lt;/strong&gt; application with &lt;strong&gt;Google&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Next?
&lt;/h3&gt;

&lt;p&gt;Next is a full stack , open source react framework for production application by the company named Vercel.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started with Next-auth.
&lt;/h2&gt;

&lt;p&gt;First setup your Next application&lt;br&gt;
&lt;code&gt;npx create-next-app app-name&lt;/code&gt;&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%2F478cofs9omvph260dl3d.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%2F478cofs9omvph260dl3d.png" alt="npx" width="800" height="261"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Note: npx stands for Node Package Execute and it comes with the npm to execute CLI command.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This CLI tool enables you to quickly start building a new Next.js application, with everything set up for you. You can create a new app using the default Next.js template.&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%2Fxvgekvmp2bgc9q5ikkcl.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%2Fxvgekvmp2bgc9q5ikkcl.png" alt="nmpx" width="290" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These folders/files will be created after running CLI.&lt;/p&gt;

&lt;p&gt;To add NextAuth.js to a project create a file called [...nextauth].js in pages/api/auth. This contains the dynamic route handler for NextAuth.js which will also contain all of your global NextAuth.js configurations.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;In [...nextauth].js file add the following code&lt;/code&gt;&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%2Fooedsocifagx737ruics.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%2Fooedsocifagx737ruics.png" alt="Image-auth" width="800" height="712"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Store your google api and client_secret in .env.local file&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To use authentication in your application first wrap your application with Session Provider.&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%2F2kpmtf1mmwdhqjqi14p4.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%2F2kpmtf1mmwdhqjqi14p4.png" alt="Image-session-provider" width="800" height="434"&gt;&lt;/a&gt;&lt;br&gt;
To be able to use useSession first you'll need to expose the session context,&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;&amp;lt;SessionProvider /&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
at the top level of your application&lt;/p&gt;

&lt;p&gt;Now, to implement Sign-In and Sign-Out method, we have to import these to methods from next-auth/react and create a function on div or button where ever you want.&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%2Fr4m89stzpparsker4utz.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%2Fr4m89stzpparsker4utz.png" alt="sign-in" width="800" height="592"&gt;&lt;/a&gt;&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%2F9s6rbyarv0jciwnt6vjm.jpg" 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%2F9s6rbyarv0jciwnt6vjm.jpg" alt="example" width="800" height="388"&gt;&lt;/a&gt;&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%2Fun6hgj7xafgfisfnjqpw.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%2Fun6hgj7xafgfisfnjqpw.png" alt="example-1" width="800" height="380"&gt;&lt;/a&gt;&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%2Fdszxtgmws4911qjza3bp.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%2Fdszxtgmws4911qjza3bp.png" alt="example-2" width="800" height="386"&gt;&lt;/a&gt;&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%2F01g0fr0urcw7kw4jlz5k.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%2F01g0fr0urcw7kw4jlz5k.png" alt="example-4" width="800" height="386"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can checkout the code of my new project Challan-X on &lt;a href="https://github.com/md-anas-sabah/challan-x-2.0" rel="noopener noreferrer"&gt;Github&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Thank you for reading and let's connect
&lt;/h2&gt;

&lt;p&gt;Thank you for reading my blog. Feel free to connect on &lt;a href="https://twitter.com/MdAnasSabah" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; or &lt;a href="https://www.instagram.com/md_anas_sabah/" rel="noopener noreferrer"&gt;Instagram&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>nextjs</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>React + Redux</title>
      <dc:creator>Md Anas Sabah</dc:creator>
      <pubDate>Sat, 16 Jul 2022 15:39:12 +0000</pubDate>
      <link>https://dev.to/mdanassabah/react-redux-4ldk</link>
      <guid>https://dev.to/mdanassabah/react-redux-4ldk</guid>
      <description>&lt;h3&gt;
  
  
  What is Redux?
&lt;/h3&gt;

&lt;p&gt;"Redux is a predictable state container for JavaScript apps".&lt;br&gt;
To understand what this means, lets break it down into three parts.&lt;br&gt;
1.It is for JavaScript App.&lt;br&gt;
2.It is a state container.&lt;br&gt;
3.It is predictable.&lt;/p&gt;

&lt;p&gt;Let's take a look at these parts individually.&lt;/p&gt;

&lt;h5&gt;
  
  
  Redux is for JavaScript Applications.
&lt;/h5&gt;

&lt;p&gt;Redux is not tied to react. It can be used with any UI Library or Framework such as React, Angular, Vue or even Vanilla JavaScript.&lt;/p&gt;

&lt;p&gt;So if you have this mental model where Redux and react are tightly coupled, now its a good time to get rid of it. Instead you should remember that Redux is a library for JavaScript application.&lt;/p&gt;

&lt;h5&gt;
  
  
  Redux is a state container
&lt;/h5&gt;

&lt;p&gt;Redux stores the state of your application.&lt;/p&gt;

&lt;p&gt;But what exactly do we mean by state of an application? Well consider a react app, we all learned about state of the component for example if we have a login form the state of the component is simply an object that holds user name password and a submitting flag to indicate the submit action happening in the background.&lt;/p&gt;

&lt;p&gt;Or if we had a list of users to display the state of the component would be an object that contains an array of users.&lt;/p&gt;

&lt;p&gt;Extending on this knowledge we can say that the state of an application is simply the state represented by all the individual components of that application this includes the data and the UI logic if your application is medium to large in size the state of the application could be something like his user logged in what is their username their profile pic URL a list of online users is a particular model opened is data being currently fetched and so on Redux will basically store and manage this application state. All right that clears tutoring of the definition Redux is a state container for JavaScript apps.&lt;/p&gt;

&lt;h5&gt;
  
  
  Redux is predictable
&lt;/h5&gt;

&lt;p&gt;Predictable in what way? Redux is a state container and in any JavaScript application the state of application can change. &lt;br&gt;
For example: In todo list app -- item(pending) -&amp;gt; item(completed)&lt;br&gt;
In Redux, all state transitions are explicit and it is possible to keep track of them. In other words, the changes of your application's state become predictable.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why React + Redux
&lt;/h2&gt;

&lt;p&gt;Component in react have their own state. Why do we need another tool to help manage state?&lt;/p&gt;

&lt;p&gt;React is generally fast, but by default any updates to a component will cause React to re-render all of the components inside that part of the component tree. This does require work, and if the data for a given component hasn't changed, then re-rendering is likely some wasted effort because the requested UI output would be the same.&lt;/p&gt;

&lt;p&gt;If performance is a concern, the best way to improve performance is to skip unnecessary re-renders, so that components only re-render when their data has actually changed. React Redux implements many performance optimizations internally, so that your own component only re-renders when it actually needs to.&lt;/p&gt;

&lt;p&gt;In addition, by connecting multiple components in your React component tree, you can ensure that each connected component only extracts the specific pieces of data from the store state that are needed by that component. This means that your own component will need to re-render less often, because most of the time those specific pieces of data haven't changed.&lt;/p&gt;

&lt;h4&gt;
  
  
  React Redux Setup
&lt;/h4&gt;

&lt;p&gt;Create react application using:&lt;/p&gt;

&lt;h6&gt;
  
  
  npx create-react-app app-name
&lt;/h6&gt;

&lt;p&gt;Next we install the two require packages i.e, redux and react-redux.&lt;/p&gt;

&lt;h6&gt;
  
  
  npm intsall redux react-redux
&lt;/h6&gt;

&lt;p&gt;Now we will create component folder in src folder, inside component we will create CakeContainer.js 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzjd97287ea3u8ftjq449.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%2Fzjd97287ea3u8ftjq449.png" alt="CakeContainer" width="800" height="748"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In App.js we include CakeContainer Component.&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%2F02obfl1tbk5ljroi3myg.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%2F02obfl1tbk5ljroi3myg.png" alt="App.js" width="800" height="582"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After including CakeContainer component in App.js, let's define Actions and Action Creators.&lt;/p&gt;

&lt;p&gt;Here, we will create cakeAction.js file and inside this file we will create a function called buyCake that returns an Action.&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%2Fhpul72fpe26qh6dsixpj.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%2Fhpul72fpe26qh6dsixpj.png" alt="Action" width="800" height="570"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h6&gt;
  
  
  Action is a object with a type property and Action creator is a function(here: buyCake) that returns a object.
&lt;/h6&gt;

&lt;p&gt;Next we are going to implement Reducer. &lt;/p&gt;

&lt;p&gt;We know that a reducer is a function that accepts state and action as parameters and returns the new state.&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%2Flp271k3b51ypfd37x214.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%2Flp271k3b51ypfd37x214.png" alt="Reducer" width="800" height="727"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Create Redux Store(state) and provide it our React application. &lt;/p&gt;

&lt;p&gt;Lets create store.js file and within this file we create our store for which we use createStore method from redux. &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%2F7wvf65aftwr53cmucxx5.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%2F7wvf65aftwr53cmucxx5.png" alt="Store" width="800" height="519"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At last, In app.js import Provider from react-redux and wrap the div tag in the return statement with this provider component &lt;br&gt;
and for provider component to know our redux store we specify it as a prop.&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%2Fiqgtspejy9yyt3chwr5p.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%2Fiqgtspejy9yyt3chwr5p.png" alt="App.js" width="800" height="678"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's all, I hope you found this article helpful.🙂&lt;/p&gt;

</description>
      <category>react</category>
      <category>redux</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Life Cycle of a Component</title>
      <dc:creator>Md Anas Sabah</dc:creator>
      <pubDate>Fri, 08 Jul 2022 08:34:49 +0000</pubDate>
      <link>https://dev.to/mdanassabah/life-cycle-of-a-component-56cp</link>
      <guid>https://dev.to/mdanassabah/life-cycle-of-a-component-56cp</guid>
      <description>&lt;p&gt;Life cycle of a component can be defined as the series of methods that are invoked in different stages of the component existence.&lt;br&gt;
Stages are:&lt;/p&gt;

&lt;p&gt;• Initialization&lt;br&gt;
• Mounting&lt;br&gt;
• Updating&lt;br&gt;
• Unmounting&lt;/p&gt;

&lt;h4&gt;
  
  
  Function of each Phase of Cycle
&lt;/h4&gt;

&lt;h5&gt;
  
  
  1. Initialization
&lt;/h5&gt;

&lt;p&gt;In this phase, we have to define the props and initial state of the component. This is done in the constructor of the component.&lt;/p&gt;

&lt;h5&gt;
  
  
  2. Mounting
&lt;/h5&gt;

&lt;p&gt;In this phase, Initialization of the component is completed and the component  is mounted on the DOM and rendered on the first time on web page.&lt;/p&gt;

&lt;p&gt;• componentWillMount() Function&lt;br&gt;
• componentDidMount() Function&lt;/p&gt;

&lt;h5&gt;
  
  
  3. Updating
&lt;/h5&gt;

&lt;p&gt;It is the phase where the states and the props of a component are updated followed by some user events like click or press keyboard button etc.&lt;/p&gt;

&lt;p&gt;• componentWillRecieveProps() Function&lt;br&gt;
• setState() Function&lt;br&gt;
• shouldComponentUpdate() Function&lt;br&gt;
• componentWillUpdate() Function&lt;br&gt;
• componentDidUpdate() Function&lt;/p&gt;

&lt;h5&gt;
  
  
  4. Unmounting
&lt;/h5&gt;

&lt;p&gt;This is the final phase of the life cycle of the component that is the phase of unmounting the component from the DOM.&lt;br&gt;
•  componentWillUnmount() Function&lt;/p&gt;

&lt;h6&gt;
  
  
  Note: &lt;em&gt;React follows a default procedure in the Naming Conventions of these predefined functions where the functions containing “Will” represents before some specific phase and “Did” represents after the completion of that phase.&lt;/em&gt;
&lt;/h6&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%2Fu9n91nq7xtj0713uhdsy.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%2Fu9n91nq7xtj0713uhdsy.png" alt="Image description" width="800" height="1342"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>TypeScript + React</title>
      <dc:creator>Md Anas Sabah</dc:creator>
      <pubDate>Tue, 28 Jun 2022 15:18:19 +0000</pubDate>
      <link>https://dev.to/mdanassabah/typescript-react-2d4b</link>
      <guid>https://dev.to/mdanassabah/typescript-react-2d4b</guid>
      <description>&lt;h2&gt;
  
  
  Why TypeScript + React
&lt;/h2&gt;

&lt;p&gt;You all think why we need TypeScript when we are just happy creating React App using JavaScript. Now, I was at that stage as well but having used TypeScript for a while I can safely say that it has improved the overall development experience for me.&lt;/p&gt;

&lt;p&gt;• With static type checking, you get to learn potential bugs as you're typing the code, than heading to the browser and figure out at run time.&lt;/p&gt;

&lt;p&gt;• It also provides a way to describe the shape of an object hence providing better documentation and autocomplete.&lt;/p&gt;

&lt;p&gt;• TypeScript even make maintenance and refactoring large code bases much easier.&lt;/p&gt;

&lt;p&gt;As you can see there are some pretty good points to help you make the decision of adopting TypeScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;h6&gt;
  
  
  Install create-react-app
&lt;/h6&gt;

&lt;p&gt;create-react-app provides us a TypeScript template we can use:&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%2Fk4723sneafctxoydlnih.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%2Fk4723sneafctxoydlnih.png" alt="create-react-app" width="800" height="264"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: npx stands for Node Package Execute and it comes with the npm to excecute CLI command.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now run the command  npm start on your terminal. The command will open the browser on localhost:3000 with your basic react typescript application up and running.&lt;/p&gt;

&lt;p&gt;In src folder, we see index.tsx and an app.tsx file.&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%2Fi4km82i77tbk7bieic36.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%2Fi4km82i77tbk7bieic36.png" alt="index.tsx" width="" height=""&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;index.tsx is the entry point to our react app where we mount our app component onto the root DOM node&lt;/em&gt;&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%2Fa99au12fhpr80nbprfmh.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%2Fa99au12fhpr80nbprfmh.png" alt="app.tsx" width="800" height="850"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;app.tsx contains our app component which is the root component&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Function Component
&lt;/h2&gt;

&lt;p&gt;To demonstrate a functional component with props we will create Greet Component. It will receive a prop "name" that will welcome the user. &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%2Ff6ql4cd37anlf7ea35rs.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%2Ff6ql4cd37anlf7ea35rs.png" alt="function" width="800" height="637"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While adding props in TypeScript you need to tell typescript what is the type of props you're passed in.&lt;br&gt;
So, way to inform the type of props to typescript is by using "type" keyword. &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%2F96xk8hj4d1k98g4k27hk.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%2F96xk8hj4d1k98g4k27hk.png" alt="props" width="800" height="518"&gt;&lt;/a&gt;&lt;br&gt;
Now a component props is an object so within Greetprops object the key will be name and data type is string.&lt;br&gt;
To inform typescript about this, after props within parenthesis we specify colon and then type name(Greetprops).&lt;/p&gt;

&lt;h2&gt;
  
  
  Class Component
&lt;/h2&gt;

&lt;p&gt;In class component, we will create Description component and in it we will create a counter. One of the key differences between a class and functional component is that a class component can maintain its own state. &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%2Fmv7f11jss9cx1axi5vgq.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%2Fmv7f11jss9cx1axi5vgq.png" alt="description" width="800" height="1056"&gt;&lt;/a&gt;&lt;br&gt;
In here, we declare a interface for both the CProps and CState. There will be an optional prop call countby which will determine the increment value.&lt;/p&gt;

&lt;p&gt;And now Inside our App.tsx we import Description.tsx&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%2Fr5xqyk5it4xnu65kgn90.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%2Fr5xqyk5it4xnu65kgn90.png" alt="count" width="800" height="616"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's all, I hope you found this article helpful.🙂&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>react</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
