<?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: Junaid</title>
    <description>The latest articles on DEV Community by Junaid (@__junaidshah).</description>
    <link>https://dev.to/__junaidshah</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%2F410001%2Fa4619c91-66d7-40a1-a77b-74b8767cd452.jpg</url>
      <title>DEV Community: Junaid</title>
      <link>https://dev.to/__junaidshah</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/__junaidshah"/>
    <language>en</language>
    <item>
      <title>Boosting Web Performance: A Guide for Frontend Developers</title>
      <dc:creator>Junaid</dc:creator>
      <pubDate>Thu, 24 Oct 2024 07:35:05 +0000</pubDate>
      <link>https://dev.to/__junaidshah/boosting-web-performance-a-guide-for-frontend-developers-fhk</link>
      <guid>https://dev.to/__junaidshah/boosting-web-performance-a-guide-for-frontend-developers-fhk</guid>
      <description>&lt;p&gt;Hey everyone! It’s been a while since I last wrote a blog, and I’ll admit, it makes me a bit sad. The reality is, there’s so much to learn, and sometimes it feels like there’s never enough time to dive into everything. Who am I kidding, though? The truth is, I’ve been procrastinating a lot lately.&lt;/p&gt;

&lt;p&gt;But recently, I’ve been exploring web performance—a crucial topic for any frontend developer—and I’m excited to share what I’ve learned. &lt;strong&gt;Performance optimization&lt;/strong&gt; is one of those things that, when done right, can make a world of difference in how users experience your website or web app. Not only does it improve the user experience, but it also boosts SEO and can even impact conversion rates.&lt;/p&gt;

&lt;p&gt;So, let’s dive in!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Web Performance Matters&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In today’s fast-paced world, users expect websites to load quickly and interact smoothly. If your site is slow, users will leave—it's as simple as that. Studies show that a delay of even a few seconds can lead to higher bounce rates and lower engagement. As frontend developers, we’re responsible for ensuring that our applications not only look good but perform well under various conditions.&lt;/p&gt;

&lt;p&gt;When it comes to measuring performance, Google is often considered the gold standard. Google provides a set of key metrics, known as Core Web Vitals, that help developers track and improve the performance of their websites. Let’s break them down:&lt;/p&gt;

&lt;p&gt;As per the lord &lt;strong&gt;Google&lt;/strong&gt;  these things matter in performance&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;FCP (First Contentful Paint)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;LCP (Largest Contentful Paint)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;CLS (Cummulative Layout Shift)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;TTI (Time To Interactive)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;INP (Interaction to Next Paint)&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Lets Explore them more closely&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FCP (First Contentful Paint)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it Measures:&lt;/strong&gt; FCP measures the time it takes for the first piece of content (text, images, etc.) to appear on the screen after a user navigates to your page. It’s a critical metric because it gives users feedback that the page is loading. The quicker the FCP, the better the user experience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to Improve FCP:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Minimize Render-Blocking Resources:&lt;/strong&gt; Reduce or eliminate resources that block the rendering of the page, such as synchronous JavaScript or CSS. Use &lt;code&gt;&amp;lt;link rel="preload"&amp;gt;&lt;/code&gt; for critical resources.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Defer Non-Critical JavaScript:&lt;/strong&gt; Use the &lt;strong&gt;defer&lt;/strong&gt; or &lt;strong&gt;async&lt;/strong&gt; attributes for non-essential scripts to ensure they don’t block the initial paint.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Use Server-Side Rendering (SSR): *&lt;/em&gt; SSR helps deliver the initial HTML faster, especially for dynamic content, so that users can see meaningful content sooner.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Optimize CSS Delivery:&lt;/strong&gt; Minimize the size of your CSS and inline critical CSS, so the browser can render content faster.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use a Content Delivery Network (CDN):&lt;/strong&gt; Serve static assets from a CDN to reduce latency and speed up resource delivery.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;LCP (Largest Contentful Paint)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it Measures:&lt;/strong&gt; &lt;strong&gt;LCP&lt;/strong&gt; focuses on the time it takes for the largest element (typically a hero image, large text block, or video) to fully render within the viewport. It’s a great indicator of perceived load speed, as users consider the page ready once the largest content has loaded. Aim to keep LCP under &lt;strong&gt;2.5 seconds&lt;/strong&gt; for a fast experience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to Improve LCP:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Optimize and Compress Images:&lt;/strong&gt; Use modern image formats like WebP, compress images, and ensure the right image sizes are served using srcset and sizes attributes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lazy Load Below-the-Fold Images:&lt;/strong&gt; Implement lazy loading for images that aren’t immediately visible to prioritize the loading of above-the-fold content.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Preload Important Resources:&lt;/strong&gt; Use the  tag to load important resources like fonts, hero images, or large media files more quickly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Minimize Render-Blocking CSS:&lt;/strong&gt; Just like with FCP, minimize the use of large CSS files that could block rendering.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reduce Third-Party Scripts:&lt;/strong&gt; Third-party ads, analytics, or other scripts can slow down LCP. Defer or asynchronously load non-essential scripts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CLS (Cumulative Layout Shift)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it Measures:&lt;/strong&gt; CLS measures the visual stability of your page. Have you ever been reading something, and suddenly the layout shifts, causing you to lose your place or click the wrong button? That’s a bad CLS score. CLS tracks how much elements on the page shift unexpectedly during the load process. A low CLS is essential for smooth user experiences, especially on mobile.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to Improve CLS:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Set Dimensions for Images and Videos:&lt;/strong&gt; Always include width and height attributes on images, or use CSS aspect ratio boxes to reserve space for media elements before they load.&lt;/p&gt;

&lt;p&gt;Avoid Inserting Content Above Existing Content: Avoid dynamically adding content above existing content unless it’s absolutely necessary (e.g., ads).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Font Loading Strategies:&lt;/strong&gt; When loading custom fonts, use font-display: swap; to avoid layout shifts caused by font loading.&lt;/p&gt;

&lt;p&gt;Avoid Injecting New Ads or Popups Without Space: Ensure that dynamically loaded ads, banners, or pop-ups are accounted for in the layout space to avoid unexpected shifts.&lt;/p&gt;

&lt;p&gt;Use Image placeholders or loaders with the same space as the image&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TTI (Time to Interactive)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it Measures:&lt;/strong&gt; TTI measures how long it takes for the page to become fully interactive. This means all buttons, inputs, and links are usable, and the main thread is free to respond to user input. A fast TTI ensures that users can engage with your content quickly without feeling like the site is sluggish or unresponsive.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to Improve TTI:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reduce JavaScript Execution Time:&lt;/strong&gt; Break down large JavaScript bundles and load only essential scripts for the first interaction. Use code splitting in React (with React.lazy()) or dynamic imports in JavaScript.&lt;br&gt;
&lt;strong&gt;Use Web Workers:&lt;/strong&gt; Offload heavy, non-UI blocking tasks to Web Workers to keep the main thread responsive.&lt;br&gt;
&lt;strong&gt;Defer Long Tasks:&lt;/strong&gt; Split long JavaScript tasks into smaller tasks to avoid blocking the main thread for too long.&lt;br&gt;
&lt;strong&gt;Preload Critical Resources:&lt;/strong&gt; Ensure that essential resources needed for interactivity (scripts, styles) are preloaded to avoid delays in TTI.&lt;br&gt;
&lt;strong&gt;Optimize CSS and JavaScript:&lt;/strong&gt; Minify, compress, and prioritize essential code. Use tree-shaking to eliminate dead code and ensure faster script execution. Use GZIP or BROTLI Compression mechanism&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;INP (Interaction to Next Paint)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What it Measures:&lt;/strong&gt; A relatively newer metric, INP tracks the time it takes for a page to respond to user interactions (like clicking buttons, scrolling, or typing) and update the UI accordingly. It helps measure overall interactivity beyond just the initial load, ensuring that your app remains snappy throughout the user session.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to Improve INP:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reduce Input Latency:&lt;/strong&gt; Make sure that user inputs (clicks, keypresses) are handled quickly by avoiding long JavaScript tasks that block the main thread.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prioritize Input Responsiveness:&lt;/strong&gt; Use requestAnimationFrame or requestIdleCallback to handle non-urgent work during idle time, leaving the main thread open for interaction handling.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Debouncing and Throttling:&lt;/strong&gt; When handling frequent user interactions (like scrolling or typing), debounce or throttle the event handlers to prevent the UI from becoming unresponsive.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lazy Load Non-Critical Code:&lt;/strong&gt; Defer loading of non-critical functionality until after the initial interaction. &lt;br&gt;
For instance, you can lazy load components in React using &lt;code&gt;React.lazy()&lt;/code&gt; and Suspense.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tools to use for checking performance&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://pagespeed.web.dev/" rel="noopener noreferrer"&gt;Pagespeed&lt;/a&gt; by chrome 
-&lt;a href="https://gtmetrix.com/" rel="noopener noreferrer"&gt;GTMetrix&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By following these strategies, you can significantly improve these key metrics and deliver a faster, more responsive user experience. These optimizations, especially when applied together, help ensure your site not only passes Google's Core Web Vitals tests but provides an exceptional experience for your users&lt;/p&gt;

&lt;p&gt;I hope you found this blog useful and you were able to get some key insights from it to help in your next performance improvement strategy.&lt;/p&gt;

&lt;p&gt;For more amazing blogs on performance , web security , react, angular, vue keep following me&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>learning</category>
    </item>
    <item>
      <title>Hygen - Never Repeat your frontend tasks</title>
      <dc:creator>Junaid</dc:creator>
      <pubDate>Wed, 15 Nov 2023 15:41:34 +0000</pubDate>
      <link>https://dev.to/__junaidshah/hygen-never-repeat-your-frontend-tasks-1jcb</link>
      <guid>https://dev.to/__junaidshah/hygen-never-repeat-your-frontend-tasks-1jcb</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As JavaScript developers, we are constantly seeking ways to enhance our productivity and streamline our workflows. One tool that has gained popularity in recent years for its ability to generate consistent, maintainable code is Hygen. In this article, we will explore the fundamentals of Hygen and dive into practical examples of how it can be seamlessly integrated into React projects to automate code generation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Hygen?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Hygen is a code generation tool that allows developers to create and manage templates for generating boilerplate code. It provides a simple and flexible solution to reduce repetitive tasks, enforce best practices, and maintain consistency across a codebase.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Getting Started with Hygen&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To begin using Hygen, you'll need to install it using npm or yarn:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;npm install hygen
// or use yarn
yarn hygen
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This will install hygen in your code base and creates a &lt;strong&gt;_&lt;em&gt;templates&lt;/em&gt;&lt;/strong&gt; folder in your app&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%2Fw89b2ukyohrl4as7kdvr.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%2Fw89b2ukyohrl4as7kdvr.png" alt="Hygen with react examples" width="480" height="102"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;you can put that folder inside your app if its not inside.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;After the setup you need to create a generator&lt;/strong&gt; &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A generator is basically where whatever repetitive tasks you want to avoid , you create a generator for that.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In our app , every time i create a component i need to :-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;create a folder with the component name&lt;/li&gt;
&lt;li&gt;Inside the folder should be a index.tsx with the basic structure of a react component in place &lt;/li&gt;
&lt;li&gt;I also need a css file for the component &lt;/li&gt;
&lt;li&gt;I might also need a test file and a story file &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For simplicity i am taking two files only &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;index.tsx&lt;/li&gt;
&lt;li&gt;index.css&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So we will create a generator for this task called&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;npx hygen generator new componentBase
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now our generator is ready and if you look inside it , it will have two folders&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;new&lt;/li&gt;
&lt;li&gt;with-prompt&lt;/li&gt;
&lt;/ul&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%2F6wupzwu0q4v881d07lli.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%2F6wupzwu0q4v881d07lli.png" alt="React Hygen" width="480" height="96"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to use prompts while creating a component (which we will use since we have to name the component everytime we create one) we will be using the with-prompt one&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Going inside this , we see two files &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;hello.ejs.t&lt;/li&gt;
&lt;li&gt;prompt.js&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&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%2Fcfpalpjzwvqffbwa61gl.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%2Fcfpalpjzwvqffbwa61gl.png" alt="Hygen with react" width="552" height="156"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will be adding files to however we want with different names.&lt;/p&gt;

&lt;p&gt;Since we want to create two files , we will create two files &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;hello.ejs.t&lt;/li&gt;
&lt;li&gt;main.ejs.t&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Inside each file we have to explain what we would like to do&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;*For our first file , we want to create a react component with base structure in place , here is the structure for the same&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;---&lt;/span&gt;
&lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;components&lt;/span&gt;&lt;span class="o"&gt;/&amp;lt;%=&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="sr"&gt;/index.j&lt;/span&gt;&lt;span class="err"&gt;s
&lt;/span&gt;&lt;span class="o"&gt;---&lt;/span&gt;
&lt;span class="k"&gt;import&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="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;%=&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="o"&gt;%&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;children&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt; &lt;span class="nx"&gt;className&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;%= h.changeCase.paramCase(message) %&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;children&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;blockquote&gt;
&lt;p&gt;Notice we are putting &lt;strong&gt;&amp;lt;%=message%&amp;gt;&lt;/strong&gt; as folder and component name , this is the prompt message which the user will be providing.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The path will be given as you like - for me i would like to put these folders inside components / &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;we can also put some default styling for out css file
&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="o"&gt;---&lt;/span&gt;
&lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;src&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="nx"&gt;components&lt;/span&gt;&lt;span class="o"&gt;/&amp;lt;%=&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="sr"&gt;/index.cs&lt;/span&gt;&lt;span class="err"&gt;s
&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;lt;%=&lt;/span&gt; &lt;span class="nx"&gt;h&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;changeCase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;paramCase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&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="na"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;black&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;Now there is one more file called prompt.js&lt;br&gt;
This file is responsible for what the user will see and it will have some thing like this code inside&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;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="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;input&lt;/span&gt;&lt;span class="dl"&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;message&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Name of the folder you would like to have?&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Notice the name is message , this can be different for you - the same name has to be used in the above components&lt;/p&gt;

&lt;p&gt;Ok ! awesome we are good to go &lt;/p&gt;

&lt;p&gt;Now to make our life easy , we will create a shortcut for generating the component so that we dont have to type a long command everytime &lt;/p&gt;

&lt;p&gt;Go inside your package.json and put this inside&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;scripts&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hygen-generate&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="s2"&gt;npx hygen mygen with-prompt&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;Superb , we are good to goooo&lt;/p&gt;

&lt;p&gt;Drumrollll &lt;/p&gt;

&lt;p&gt;Go inside the terminal and type&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx hygen-generate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Give a name to your component and your component will be created .&lt;/p&gt;

&lt;p&gt;This is one of thousands of examples we can do with hygen &lt;br&gt;
I would love to see what you guys come up with , with this amazing tool &lt;/p&gt;

&lt;p&gt;Tag me or comment below what you created with this beautiful tool .&lt;/p&gt;

&lt;p&gt;I have created this as a project as well , here is the repo for you guys to check and explore &lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fassets.dev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/jsh854" rel="noopener noreferrer"&gt;
        jsh854
      &lt;/a&gt; / &lt;a href="https://github.com/jsh854/react-hygen-boilerplate" rel="noopener noreferrer"&gt;
        react-hygen-boilerplate
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      This repo is the boiler plate for react with hygen for code generation
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;This repo is for react with hygen for code generation&lt;/h1&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;Run ** npm i ** initially&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Here is how to use and get started with this&lt;/h2&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;Go inside the terminal&lt;/li&gt;
&lt;li&gt;Run npm run hygen-generate&lt;/li&gt;
&lt;li&gt;Give a proper name for the folder you would want to create&lt;/li&gt;
&lt;li&gt;It will create a folder with the name provided under src/components and files
&lt;ul&gt;
&lt;li&gt;.js&lt;/li&gt;
&lt;li&gt;.ts&lt;/li&gt;
&lt;li&gt;.css&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Customisation&lt;/h1&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;If you would like to customise the folder generation , maybe add more files or add different content for the generated files
&lt;ul&gt;
&lt;li&gt;Go inside _templates &amp;gt; mygen &amp;gt; with-prompt&lt;/li&gt;
&lt;li&gt;Three .ejs.t files are there .
- In order to add more files , create a new file with different name but same extension of .ejs.t&lt;/li&gt;
&lt;li&gt;Each file has a purpose and you can customize how they look accordingly&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;br&gt;
  &lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/jsh854/react-hygen-boilerplate" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Vue 2 vs vue 3 - The Differences</title>
      <dc:creator>Junaid</dc:creator>
      <pubDate>Mon, 05 Jun 2023 13:31:25 +0000</pubDate>
      <link>https://dev.to/__junaidshah/vue-2-vs-vue-3-the-differences-13lk</link>
      <guid>https://dev.to/__junaidshah/vue-2-vs-vue-3-the-differences-13lk</guid>
      <description>&lt;h2&gt;
  
  
  whats new in vue 3 that developers can start taking advantage of
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://vuejs.org/" rel="noopener noreferrer"&gt;Vue JS&lt;/a&gt; as we all know is  great tool to get you up and running with frontend development .&lt;/p&gt;

&lt;p&gt;It has got all the things a frontend developer needs in 2023&lt;/p&gt;

&lt;p&gt;I have got the privilege of working on &lt;a href="https://v2.vuejs.org/" rel="noopener noreferrer"&gt;Vue 2&lt;/a&gt; couple of months ago and its really amazing framework to work with . &lt;/p&gt;

&lt;p&gt;Today what i am going to focus about more is "what are the new things that came in Vue 3 " and are the new features useful to an average Vue developer&lt;/p&gt;

&lt;p&gt;_First lets dive into options API _&lt;br&gt;
So as you vue developers know , in vue 2 we are using the good "Options Api" . The &lt;a href="https://v2.vuejs.org/v2/api/#Options-Data" rel="noopener noreferrer"&gt;Options API&lt;/a&gt; is the traditional way of structuring and defining components. It involves defining a component using a set of options.&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="nf"&gt;data&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, Vue!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This above is an example of options api usage .&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We also have 'Methods' for functions , props for props (obviously ) , watchers , lifecycle methods like created , mounted , updated etc in Options Api
&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="nx"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newVal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;oldVal&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Message changed from &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;oldVal&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; to &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;newVal&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;  

&lt;span class="nf"&gt;created&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Component created&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="nf"&gt;mounted&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Component mounted&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="nf"&gt;destroyed&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Component destroyed&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now in Vue 3 , we also have &lt;strong&gt;Composition Api&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://vuejs.org/guide/introduction.html#api-styles" rel="noopener noreferrer"&gt;Composition API&lt;/a&gt; is an alternative way of structuring and organizing code within Vue components. It provides a more flexible and scalable approach compared to the Options API. Instead of separating component options into different sections, the Composition API encourages grouping related logic together.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Here are the key concepts and features of the Composition API in Vue 3:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Setup function&lt;/strong&gt;: In the Composition API, each component consists of a setup function that returns an object containing the component's properties, methods, and other reactive references. The setup function is run before the component is created, allowing you to set up the component's reactive state and define the component's logic.
&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;reactive&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;computed&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;vue&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="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;setup&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;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;reactive&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, Vue!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;increment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&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;doubleCount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;computed&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;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nx"&gt;increment&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nx"&gt;doubleCount&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;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reactive state&lt;/strong&gt;: The Composition API provides the reactive function, which allows you to create reactive objects. Any changes made to reactive properties will trigger reactivity and update the component's view accordingly.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Computed properties&lt;/strong&gt;: Computed properties can be created using the computed function. Computed properties are derived values that are automatically updated when their dependencies change.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Methods&lt;/strong&gt;: You can define component methods within the setup function. These methods can be accessed and used within the component's template or programmatically.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Lifecycle hooks&lt;/strong&gt;: The Composition API provides lifecycle hooks similar to the Options API. However, they are prefixed with on, such as onMounted, onUpdated, and onUnmounted. These hooks allow you to perform actions at different stages of the component's lifecycle.&lt;br&gt;
&lt;/p&gt;&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;onMounted&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;onUnmounted&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;vue&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="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;setup&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;onMounted&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Component mounted&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="nf"&gt;onUnmounted&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Component unmounted&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;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Ref&lt;/strong&gt;: The Composition API introduces the ref function, which allows you to create a reactive reference to a value. Refs are particularly useful when dealing with primitive values that need reactivity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Watch&lt;/strong&gt;: The Composition API provides the watch function, which allows you to perform operations based on changes to reactive state or refs.&lt;br&gt;
&lt;/p&gt;&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="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;watch&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;vue&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="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;setup&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;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nf"&gt;watch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newValue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;oldValue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Count changed from &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;oldValue&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; to &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;newValue&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="nx"&gt;count&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the main core difference in vue 2 vs vue 3 which came along and is going to improve code quality and performance of vue. However Options api is not going anywhere , its going to stay as is and will be available in vue 3 as well .&lt;/p&gt;

&lt;p&gt;The Other differences include &lt;br&gt;
&lt;strong&gt;Reactivity System:&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Vue 3&lt;/em&gt; introduces a revamped reactivity system, which is more efficient and performs better compared to Vue 2. The new system, known as the Proxy-based reactivity system, offers improved reactivity tracking, resulting in faster and more accurate updates.&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;// Vue 2&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;message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, Vue!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Vue 3&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;reactive&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;vue&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;state&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;reactive&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, Vue!&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;&lt;strong&gt;Performance Improvements:&lt;/strong&gt;&lt;br&gt;
Vue 3 brings significant performance improvements over its predecessor. The virtual DOM (VDOM) algorithm has been optimized to reduce memory allocation and increase rendering speed. The new static tree hoisting technique in Vue 3 eliminates redundant re-rendering of static content, leading to better performance in complex applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Smaller Bundle Size:&lt;/strong&gt;&lt;br&gt;
Vue 3 comes with a smaller bundle size compared to Vue 2. This is achieved through better tree shaking and improved module system. The modular design of Vue 3 allows developers to import only the necessary features, reducing the overall size of the application bundle.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TypeScript Integration:&lt;/strong&gt;&lt;br&gt;
While Vue 2 had limited TypeScript support, Vue 3 takes full advantage of TypeScript's static typing capabilities. The Vue 3 codebase is written in TypeScript, which ensures better type inference and provides enhanced autocompletion and tooling support for TypeScript users.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The major focus in vue 3 have been performance and optimisation . Well many can argue that composition api is great and everyone should switch to it right away - i can confidentaly say that many would want to stick with options api due to some obvious reasons. &lt;br&gt;
The core differences are Composition API, revamped reactivity system, enhanced performance, smaller bundle sizes, improved TypeScript integration. &lt;br&gt;
While it may take some time to switch to vue 3 , the improvements are worthwhile. &lt;/p&gt;

&lt;p&gt;I hope you find this article usefull and i was able to help you in someway . &lt;br&gt;
Checkout my website for more articles that will be coming soon . &lt;a href="https://www.jayshawcodes.com/" rel="noopener noreferrer"&gt;Jayshahcodes&lt;/a&gt; &lt;br&gt;
I am also open for dev articles , if you have a article in mind or want me to write dev articles for you , lets discuss.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.buymeacoffee.com/jshahcodes" rel="noopener noreferrer"&gt;Support me here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>vue</category>
      <category>tutorial</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Typescript - For React Developers</title>
      <dc:creator>Junaid</dc:creator>
      <pubDate>Sat, 04 Mar 2023 09:20:18 +0000</pubDate>
      <link>https://dev.to/__junaidshah/typescript-for-react-developers-3e6e</link>
      <guid>https://dev.to/__junaidshah/typescript-for-react-developers-3e6e</guid>
      <description>&lt;h2&gt;
  
  
  Lets get React Developers armoured with TS
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;React&lt;/strong&gt; is a popular JavaScript library used for building user interfaces. It is a great tool for creating dynamic and responsive web applications. However, as your application grows in complexity, it can become harder to maintain and debug. This is where TypeScript comes in. &lt;br&gt;
TypeScript is a static typing language that can be used with React to improve code quality and maintainability. In this post, we will discuss the benefits of using TypeScript in React and how to get started with it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Benefits of Using TypeScript in React&lt;/strong&gt;&lt;br&gt;
Here are some key benefits of using TypeScript in React:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Type Safety&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;One of the main benefits of using TypeScript with React is type safety. TypeScript provides a way to catch errors early in development by providing type checking for components, props, state, and other variables. This helps catch errors before they become bigger issues, making your code more reliable and easier to maintain.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Improved Code Readability and Maintainability&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;TypeScript provides better documentation for your code and helps ensure consistency across your project. This improves the readability and maintainability of your codebase, making it easier for developers to understand and modify your code.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Better Tooling Support&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;TypeScript integrates well with many popular development tools, including IDEs, linters, and testing frameworks. This makes it easier to work with, and ensures that your code is consistent and follows best practices.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Faster Development and Easier Refactoring&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;TypeScript provides better autocompletion and refactoring support, making it easier to write and modify code. This results in faster development times and a more efficient workflow.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Getting Started with TypeScript in React&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To use TypeScript in a React project, you need to add a few dependencies to your project and configure your development environment. Here are the steps to get started:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Step 1: Install Dependencies&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you are starting a fresh React App here is the template that will configure typescript for you directly
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;//using npx
npx create-react-app my-app &lt;span class="nt"&gt;--template&lt;/span&gt; typescript
// using yarn
yarn create react-app my-app &lt;span class="nt"&gt;--template&lt;/span&gt; typescript
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;If you already have a react app and you want to add Typescript support now , here is the code:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;//using npm
npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;--save&lt;/span&gt; typescript @types/node @types/react @types/react-dom @types/jest

//using yarn
yarn add typescript @types/node @types/react @types/react-dom @types/jest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This will install TypeScript and the necessary type definitions for React and ReactDOM.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2: Use TypeScript in Your Code&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now that your project is configured, you can start writing components and other code using TypeScript syntax. Here are some examples:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Defining Types for Props and State&lt;/strong&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="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="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Props&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;State&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;isOn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;MyComponent&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&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;State&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;State&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;isOn&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="nx"&gt;handleClick&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setState&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before we go any further here are some basics for typescript you need to know &lt;br&gt;
&lt;strong&gt;Basic Types&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Defining variables with types&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;30&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;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;John Doe&lt;/span&gt;&lt;span class="dl"&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;isStudent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;boolean&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;hobbies&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="o"&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;reading&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="s2"&gt;swimming&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="s2"&gt;traveling&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// Defining functions with types&lt;/span&gt;
&lt;span class="kd"&gt;function&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;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="k"&gt;void&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="nx"&gt;name&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kr"&gt;number&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;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;y&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;strong&gt;Interface&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An interface is a TypeScript feature that allows you to define the shape of an object or class. Interfaces are often used for describing the structure of objects that will be passed as arguments or returned from functions. Here's an example of how to define an interface in TypeScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;email&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In this example, we define an interface called Person that has three properties: name of type string, age of type number, and email of type string.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Interfaces are often used for describing the shape of objects that will be passed around in your code. They can be extended and combined to create more complex types.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Type&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A type is another TypeScript feature that allows you to define custom types. Types are often used for defining union types, intersection types, and other complex types. Here's an example of how to define a type in TypeScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Car&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;make&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;year&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In this example, we define a type called Car that has three properties: make of type string, model of type string, and year of type number.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Types are often used for defining more complex types that cannot be described by interfaces. They can also be used for defining union types, intersection types, and other advanced types.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Differences&lt;/strong&gt;&lt;br&gt;
The main differences between type and interface in TypeScript are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Interface can be extended to create new interfaces, while type can be used to define union types, intersection types, and other complex types.&lt;/li&gt;
&lt;li&gt;Type can be used to define computed properties, while interface cannot.&lt;/li&gt;
&lt;li&gt;Type is more flexible than interface in some cases, because it allows you to define more complex types that cannot be described by interfaces.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Union&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In TypeScript, a union type is a type that can represent values of multiple types. You can use the vertical bar (|) to combine two or more types into a union type.&lt;/p&gt;

&lt;p&gt;Here's an example of a union type in TypeScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;MyType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, MyType is a union type that can represent values of either string or number.&lt;/p&gt;

&lt;p&gt;You can use union types in various scenarios to make your code more flexible. For example, you might want to define a variable that can accept either a string or a number value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Typing Arrays&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To define an array type, you can use the following syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Type&lt;/span&gt;&lt;span class="p"&gt;[];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, Type is the type of elements that the array can hold.&lt;/p&gt;

&lt;p&gt;For example, if you want to define an array of strings, you can do the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myArray&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, myArray can only hold string values.&lt;/p&gt;

&lt;p&gt;You can also define an array of union types by using the following syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myArray&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="p"&gt;)[];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, myArray can hold values of either string or number type.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Typing Objects&lt;/strong&gt;&lt;br&gt;
To define an object type, you can use the following syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;key1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Type1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;key2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Type2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;strong&gt;Type1&lt;/strong&gt; and &lt;strong&gt;Type2&lt;/strong&gt; are the types of values that the keys key1 and key2 can hold. You can define as many key-value pairs as you want.&lt;/p&gt;

&lt;p&gt;For example, if you want to define an object that has a name property of type string and an age property of type number, you can do the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myObject&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also define an object with dynamic keys using the following syntax:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;myObject&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;key&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="nx"&gt;Type&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Here, &lt;strong&gt;key&lt;/strong&gt; is the name of the dynamic key, and Type is the type of values that the key can hold. This syntax allows you to define an object with any number of keys, as long as the key names are strings.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Generics:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Generics are a powerful feature in TypeScript that allow you to create reusable functions, classes, and interfaces that can work with a variety of types. The basic syntax for generics is to define a type parameter in angle brackets &amp;lt;&amp;gt;, which can be used throughout the function, class, or interface. Here's an example of a generic function that returns the first element of an array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Defining a generic function that works with any type&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;identity&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;arg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;arg&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Using the identity function with a string&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;identity&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;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;hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// result1 is "hello"&lt;/span&gt;

&lt;span class="c1"&gt;// Using the identity function with a number&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;identity&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;number&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// result2 is 42&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Using Typescript in React&lt;/strong&gt;&lt;br&gt;
Now that we have the basics all known to us , lets see how we can put typescript magic in react and make it typesafe&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;User Events&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Using Typescipt for giving types to different user events in React&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Before we start giving types to the events, we need to import the React types. These can be imported as follows:&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="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ChangeEvent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;MouseEvent&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, we are importing the ChangeEvent and MouseEvent types for use in our component.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Giving types to events&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;onClick
The onClick event is used to handle mouse clicks on an element. Here's an example of how to give proper types to the onClick event:
&lt;/li&gt;
&lt;/ul&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;handleClick&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;MouseEvent&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;HTMLButtonElement&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Button clicked&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;MyButton&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&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="nx"&gt;handleClick&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Click me&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&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;blockquote&gt;
&lt;p&gt;In this example, we give the handleClick function a type of MouseEvent. This means that the function expects a MouseEvent object, with the target element being a button element.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;onChange&lt;/strong&gt;&lt;br&gt;
The onChange event is used to handle changes in the value of an input element. Here's an example of how to give proper types to the onChange event:&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;handleChange&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;ChangeEvent&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;HTMLInputElement&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="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Input value changed:&lt;/span&gt;&lt;span class="dl"&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="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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;MyInput&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&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="nx"&gt;handleChange&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;In this example, we give the handleChange function a type of &lt;strong&gt;ChangeEvent&lt;/strong&gt;. This means that the function expects a ChangeEvent object, with the target element being an input element.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;onSubmit&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The onSubmit event is used to handle form submissions. Here's an example of how to give proper types to the onSubmit event:&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;handleSubmit&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;FormEvent&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;HTMLFormElement&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="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;preventDefault&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Form submitted&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;MyForm&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;form&lt;/span&gt; &lt;span class="na"&gt;onSubmit&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleSubmit&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="nt"&gt;button&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;"submit"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Submit&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&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;form&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we give the handleSubmit function a type of &lt;strong&gt;FormEvent&lt;/strong&gt;. This means that the function expects a FormEvent object, with the target element being a form element.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Read More About available types &lt;a href="https://react-typescript-cheatsheet.netlify.app/docs/basic/getting-started/forms_and_events" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Typing State in React&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When building React components, it's often useful to define the shape of the component's state. This can help catch type-related errors at compile time, making your code more robust and easier to maintain. Here's how to type the state of a React component using TypeScript:&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="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&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="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;State&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;MyComponent&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;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setState&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;State&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello, world!&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleClick&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;setState&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="p"&gt;({&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="na"&gt;count&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="nx"&gt;count&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;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;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Count: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&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="nx"&gt;handleClick&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Increment count&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&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;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="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;MyComponent&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we define an interface called State that has a count property of type number and a message property of type string. We use the useState hook to define the component's state, and pass in an initial state object of type State. We then use the handleClick function to update the state by incrementing the count property. We can access the state properties using state.count and state.message.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The &lt;em&gt;as&lt;/em&gt; operator&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;as&lt;/strong&gt; operator in TypeScript is used for type assertions. It allows you to explicitly cast a value to a specified type, telling the TypeScript compiler to treat the value as if it were of that type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;unknown&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello, world!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Error: Property 'toUpperCase' does not exist on type 'unknown'.&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;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Using the 'as' operator to assert that 'value' is a string.&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;valueAsString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// No error: 'valueAsString' is now treated as a string by the TypeScript compiler.&lt;/span&gt;
&lt;span class="nx"&gt;valueAsString&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// "HELLO, WORLD!"&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;as&lt;/strong&gt; operator comes very handy in a lot of places when you are dealing with typescript in react&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Utility Types in Typescript&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Utility types in TypeScript are a set of built-in type transformations that can help you create new types based on existing ones. These types are defined in the utility-types module, which is included with TypeScript.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Here are some common utility types:&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Partial:&lt;/strong&gt; This utility type creates a new type that has all the properties of T, but with each property being optional. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;PartialPerson&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Partial&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Person&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Equivalent to:&lt;/span&gt;
&lt;span class="c1"&gt;// type PartialPerson = {&lt;/span&gt;
&lt;span class="c1"&gt;//   name?: string;&lt;/span&gt;
&lt;span class="c1"&gt;//   age?: number;&lt;/span&gt;
&lt;span class="c1"&gt;// };&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Required:&lt;/strong&gt; This utility type creates a new type that has all the properties of T, but with each property being required.&lt;br&gt;
This is just the opposite of Partial&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pick:&lt;/strong&gt; This utility type creates a new type by picking a set of properties of type K from T&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="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Person&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;address&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;PersonNameAndAge&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Pick&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;age&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Equivalent to:&lt;/span&gt;
&lt;span class="c1"&gt;// type PersonNameAndAge = {&lt;/span&gt;
&lt;span class="c1"&gt;//   name: string;&lt;/span&gt;
&lt;span class="c1"&gt;//   age: number;&lt;/span&gt;
&lt;span class="c1"&gt;// };&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Exclude:&lt;/strong&gt; This utility type creates a new type by excluding all the properties of U from T.&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="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Fruit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;apple&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;banana&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;orange&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;NonBananaFruit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;Exclude&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Fruit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;banana&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Equivalent to:&lt;/span&gt;
&lt;span class="c1"&gt;// type NonBananaFruit = "apple" | "orange";&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;There are other utility types also you can read about them &lt;a href="https://www.typescriptlang.org/docs/handbook/utility-types.html" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Types of Components&lt;/strong&gt;&lt;br&gt;
In React, there are two main ways to define a functional component: using the React.FC type or returning a JSX.Element directly from the 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="c1"&gt;// FC Type&lt;/span&gt;
&lt;span class="k"&gt;import&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="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Props&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="nx"&gt;string&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;MyComponent&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;FC&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Props&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&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;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello, &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;!&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;//JSX.Element Type&lt;/span&gt;
&lt;span class="k"&gt;import&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="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;Props&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="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;MyComponent&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="nx"&gt;Props&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="nx"&gt;JSX&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Element&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Hello, &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;!&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Both approaches are valid, but there are some differences to consider.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The &lt;strong&gt;React.FC&lt;/strong&gt; approach has some advantages, such as automatically providing the children prop and making it easy to define default props and prop types. However, it also has some disadvantages, such as making it more difficult to define props that are required or optional.&lt;/p&gt;

&lt;p&gt;On the other hand, returning a JSX.Element directly has the advantage of being more flexible and explicit about the component's return type. However, it also requires you to manually define default props and prop types, and it doesn't automatically provide the children prop.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using Generics in React For Advanced Types&lt;/strong&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="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="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Props&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="p"&gt;[];&lt;/span&gt;
  &lt;span class="nl"&gt;renderItem&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="na"&gt;item&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;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;ReactNode&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;List&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Props&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="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;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;renderItem&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="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="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;List&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;In this example, we define a generic type T that represents the type of data that the List component can render. The Props interface takes a generic type T and defines two properties:&lt;/p&gt;

&lt;p&gt;data: An array of type T.&lt;br&gt;
renderItem: A function that takes an item of type T and returns a ReactNode.&lt;br&gt;
The List component takes a generic type T and renders the list of items using the props.data.map() method. The props.renderItem() function is called for each item in the list, and the resulting ReactNode is rendered in the output.&lt;/p&gt;

&lt;p&gt;Here's how you can use the List component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&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="nx"&gt;List&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;./List&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;Item&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;items&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;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;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;Item 1&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="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&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;Item 2&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="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&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;Item 3&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;];&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;renderItem&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="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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;h3&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;h3&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;List&lt;/span&gt;&lt;span class="err"&gt;&amp;lt;&lt;/span&gt;&lt;span class="na"&gt;Item&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; data=&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; renderItem=&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;renderItem&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; /&amp;gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  );
}

export default App;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is a lot of other things that typescript offers , you can read more about best practices and use cases of typescript in react &lt;a href="https://react-typescript-cheatsheet.netlify.app/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope with this knowledge you will be able to tackle most of the problems of typescript and ace your react code with typescript superpowers and make it bulletproof.&lt;/p&gt;

&lt;p&gt;For more such tutorials ,React out to me on &lt;br&gt;
&lt;a href="https://www.linkedin.com/in/junaid-shah-ba2910a9/" rel="noopener noreferrer"&gt;linkedin&lt;/a&gt;&lt;br&gt;
Also keep an eye on my website for amazing content coming in&lt;br&gt;
&lt;a href="https://www.jayshawcodes.com/" rel="noopener noreferrer"&gt;jayshahcodes&lt;/a&gt;&lt;/p&gt;

</description>
      <category>dsa</category>
      <category>ai</category>
      <category>chatgpt</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Typescript - Basics and use cases</title>
      <dc:creator>Junaid</dc:creator>
      <pubDate>Tue, 01 Nov 2022 06:50:16 +0000</pubDate>
      <link>https://dev.to/__junaidshah/typescript-basics-and-use-cases-1el5</link>
      <guid>https://dev.to/__junaidshah/typescript-basics-and-use-cases-1el5</guid>
      <description>&lt;h2&gt;
  
  
  &lt;a href="https://www.typescriptlang.org/" rel="noopener noreferrer"&gt;Typescript&lt;/a&gt; as we all know is the what was missing in javascript from ages - A static type checking system since javascript itself is a weakly typed language
&lt;/h2&gt;

&lt;p&gt;With the help of typescript we can give type-safety to our js codebases like react.&lt;/p&gt;

&lt;p&gt;So lets get started with the basics of typescript&lt;/p&gt;

&lt;p&gt;First of lets cover the types of variables &lt;/p&gt;

&lt;p&gt;A variable in javascript can be of these types &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;string&lt;/li&gt;
&lt;li&gt;number &lt;/li&gt;
&lt;li&gt;boolean&lt;/li&gt;
&lt;li&gt;undefined *&lt;/li&gt;
&lt;li&gt;null *&lt;/li&gt;
&lt;li&gt;object&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;So lets cover them one by one&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If a variable is going to be a string we can simple put it inclusively&lt;br&gt;
&lt;strong&gt;item : string&lt;/strong&gt;&lt;br&gt;
This means that item is strictly going to be a string only&lt;br&gt;
similarly with the other types e.g&lt;br&gt;
&lt;strong&gt;item : number&lt;/strong&gt;. / for number&lt;br&gt;
&lt;strong&gt;item : boolean&lt;/strong&gt; / for boolean&lt;/p&gt;

&lt;p&gt;now these are the basic types , but for props that can be grouped together how do we create some thing that shows a group of types together &lt;/p&gt;

&lt;p&gt;That is where &lt;strong&gt;type and interface&lt;/strong&gt; comes into effect&lt;/p&gt;

&lt;p&gt;Both are used to create a group of types that a component is going to get &lt;/p&gt;

&lt;p&gt;e.g&lt;/p&gt;

&lt;p&gt;&lt;code&gt;type inputTypes{&lt;br&gt;
value:string,&lt;br&gt;
placeholder:string,&lt;br&gt;
type:string&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Similarly can be done with interface as well but there are some differences &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;object type can be shown in interface but not in type&lt;/li&gt;
&lt;li&gt;interface with same name in the same file gets merged but that is not for types - for them its just an error&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;now lets talk about creating types for objects and functions &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Objects&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Objects has two things to be taken care of i.e&lt;br&gt;
Key part and the value part &lt;br&gt;
so for objects we can set type as like this&lt;/p&gt;

&lt;p&gt;&lt;code&gt;[v:string]:string&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;you can use all the basic types as key and value types here &lt;/p&gt;

&lt;p&gt;this means the key is going to be a string and the value is also going to be a string&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Functions&lt;/strong&gt;&lt;br&gt;
Now with functions there are also two parts to it i.e&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Parameters that it is going to be getting&lt;/li&gt;
&lt;li&gt;and the return type that the function is going to be returning&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So an example is going to be like this &lt;/p&gt;

&lt;p&gt;type functionProps{&lt;br&gt;
name:string,&lt;br&gt;
age:number,&lt;br&gt;
isAboveThirty:boolean}&lt;/p&gt;

&lt;p&gt;&lt;code&gt;function getAgeSection({name,age,isAboveThirty}:functionProps):string{&lt;br&gt;
if(isAboveThirty){&lt;br&gt;
return 'the person is above thirty'&lt;br&gt;
}else{&lt;br&gt;
return 'He is below thirty'&lt;br&gt;
}&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;what this means is the function is going to accept the types which are functionProps and the return type is going to be a string&lt;/p&gt;

&lt;p&gt;If u don't provide a return type it is going to either infer the type from whatever u returned from the function , or if you don't return anything at all it will set it to void&lt;/p&gt;

&lt;p&gt;These are just the basic types just to get you started with typescript &lt;/p&gt;

&lt;p&gt;In the next post i will share how to use typescript in a react app with some advanced types like click events ,input events&lt;/p&gt;

</description>
    </item>
    <item>
      <title>What every junior developer should know</title>
      <dc:creator>Junaid</dc:creator>
      <pubDate>Fri, 18 Feb 2022 04:24:12 +0000</pubDate>
      <link>https://dev.to/__junaidshah/what-every-junior-developer-should-know-4doh</link>
      <guid>https://dev.to/__junaidshah/what-every-junior-developer-should-know-4doh</guid>
      <description>&lt;h2&gt;
  
  
  Let me get this straight - Every developer is a junior developer all his life.
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Get this as soon as possible.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Now let's talk about the actual junior developer , the people who are just to starting there career in development .
&lt;/h3&gt;

&lt;p&gt;Let's talk about you guys.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First thing first nobody knows every thing &lt;strong&gt;"nobody"&lt;/strong&gt; .&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Not even the best dev in your company would know every thing.&lt;/p&gt;

&lt;p&gt;So never feel like damn i don't know this , nobody does - just go ahead , research about the task you have been assigned  -  and learn &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ask as many relatable questions as you can .
Don't ever feel like by asking many questions your seniors will judge you, they wont.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If i were them i would think of you as a good dev who actually knows when to ask for help because let's get this clear every one needs help at one part or another .&lt;/p&gt;

&lt;p&gt;But what you should do is don't just go and ask for help all the time, do your research first.&lt;/p&gt;

&lt;p&gt;Try to do it on your own but if you feel like giving up only then ask for help and when you ask for help explain it to them what you did and where do you got stuck.&lt;/p&gt;

&lt;p&gt;That will give the seniors a clear idea that you have done a good job by researching a lot and now you are stuck somewhere and needs help.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now when you are a junior dev you will be given tasks that are doable by you as per the team so try to solve them by your own first only when you feel like stuck only then go and ask for help.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Alright now&lt;/strong&gt;&lt;br&gt;
Being a junior dev you will be baffled with new and crazy technologies and being a developer you would be so pumped to learn new tech(if you are not , you definitely should ask yourself is this what you want to do in life?)&lt;/p&gt;

&lt;p&gt;You will learn a lot of things , you should be open to it - maybe unlearn something to learn new things as done by the company.&lt;/p&gt;

&lt;p&gt;I started my first company by only knowing the basics of react , had done some small projects &lt;br&gt;
and just in one year i learned about &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Typescript&lt;/li&gt;
&lt;li&gt;Next js&lt;/li&gt;
&lt;li&gt;Flask&lt;/li&gt;
&lt;li&gt;Postgres&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;all these things and so much more things like patterns , code quality etc.&lt;/p&gt;

&lt;p&gt;So try to learn as much as you can and you will be amazed by where you will be even after six months.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I wish you all the junior dev's best of luck -  i know you will rock .&lt;/strong&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Interview questions for JS</title>
      <dc:creator>Junaid</dc:creator>
      <pubDate>Fri, 26 Nov 2021 05:32:10 +0000</pubDate>
      <link>https://dev.to/__junaidshah/interview-questions-for-js-4a4m</link>
      <guid>https://dev.to/__junaidshah/interview-questions-for-js-4a4m</guid>
      <description>&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%2Fn8jr92rc5beq630cclcv.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%2Fn8jr92rc5beq630cclcv.png" alt="Javascript Interview Questions" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Javascipt is a great language and i believe every web developer in todays world should definitely learn it.
&lt;/h2&gt;

&lt;p&gt;Not is it just awesome but also by just learning and understanding javascript you will be able to learn and use so many great frameworks that are buzzing in current job market &lt;br&gt;
like  &lt;strong&gt;React&lt;/strong&gt; , &lt;strong&gt;Angular&lt;/strong&gt; , &lt;strong&gt;Next JS&lt;/strong&gt;  etc.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;So this is a gist of some of the questions and concepts that i have came across in my interview for some product based startups.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Basics&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Basics of javascript should be clear very much , Things like arrays , objects , variables etc should be very clear before even you think of applying at any job as a js dev.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Arrays&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Arrays are very important and since you will be using them so much in your day to day use case as being a web dev you should definitely learn all the things that can be done in js for arrays like &lt;br&gt;
     * Push&lt;br&gt;
     * pop&lt;br&gt;
     * shift&lt;br&gt;
     * unshift&lt;br&gt;
also you should learn how we iterate over arrays &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Also learn these :-&lt;br&gt;
      * Slice&lt;br&gt;
      * Splice&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Objects&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Every developer in his day to day life will definitely come across objects while working on a javascript project .&lt;br&gt;
So every interviewer expects you know the basics of Objects.&lt;/p&gt;

&lt;p&gt;Try to understand them and apply them in any of your projects.&lt;/p&gt;

&lt;p&gt;Objects will also be used while you work on things like json all that is is a big blob of object so you have to work with them .&lt;/p&gt;

&lt;p&gt;So try to understand all related topics to objects &lt;br&gt;
Things like how we add an item to an object&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to iterate through an object&lt;/li&gt;
&lt;li&gt;How can we delete an item from an object&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Try to also learn things like object.keys , object.freeze etc.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;More Good Topics&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Every interviewer will ask you questions related to these questions so its very necessary that you know these concepts and can explain them in detail &lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;Whats Execution context in js.&lt;/li&gt;
&lt;li&gt;Whats a promise and how to create one .&lt;/li&gt;
&lt;li&gt;What are callbacks &lt;/li&gt;
&lt;li&gt;whats async/await used for &lt;/li&gt;
&lt;li&gt;Difference between == and ===&lt;/li&gt;
&lt;li&gt;whats call , apply and bind .&lt;/li&gt;
&lt;li&gt;Difference between simple functions and arrow functions&lt;/li&gt;
&lt;li&gt;Whats 'this' in javascript&lt;/li&gt;
&lt;li&gt;What are closures &lt;/li&gt;
&lt;li&gt;whats memoization&lt;/li&gt;
&lt;li&gt;what is an IIFE(Immediately Invoked Function Expression).&lt;/li&gt;
&lt;li&gt;Difference between let and Var.&lt;/li&gt;
&lt;li&gt;Different stages of a promise.&lt;/li&gt;
&lt;li&gt;Difference between setTimeout and setInterval&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;There are other topics also which you should give a good go before going for the interview , not everyone will ask you these but its good to know them &lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;Whats prototype and prototypal inheritance&lt;/li&gt;
&lt;li&gt;what are anonymous functions&lt;/li&gt;
&lt;li&gt;Event bubbling and how do you prevent that.&lt;/li&gt;
&lt;li&gt;Whats promise.all&lt;/li&gt;
&lt;li&gt;whats a polyfill.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;There are many many topics in javascript that you would to know but for a fresher js or even for 1+ year of experience these are the most asked questions .&lt;br&gt;
You can also checkout the greats series by &lt;a href="https://youtu.be/pN6jk0uUrD8" rel="noopener noreferrer"&gt;Akshay Saini&lt;/a&gt; which explains all the javascript concepts in great detail.&lt;/p&gt;

&lt;p&gt;All right , i guess this will be hopefully helpful for any one out there .&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Feel free to reach out to me for any thing over email&lt;/em&gt;&lt;br&gt;
&lt;a href="https://linktr.ee/jshahcodes" rel="noopener noreferrer"&gt;junaid shah&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Create CI/CD pipeline using jenkins</title>
      <dc:creator>Junaid</dc:creator>
      <pubDate>Sat, 28 Aug 2021 05:16:42 +0000</pubDate>
      <link>https://dev.to/__junaidshah/create-ci-cd-pipeline-using-jenkins-4351</link>
      <guid>https://dev.to/__junaidshah/create-ci-cd-pipeline-using-jenkins-4351</guid>
      <description>&lt;h2&gt;
  
  
  For all the people who do not know what jenkins is , let me explain it to you
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Jenkins is a CI/CD tool that you can use on any project of yours or your companies to make your lives a little easier .&lt;br&gt;
What it does for you is a whole lot of things &lt;br&gt;
just for example &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;lets just say you want that whenever a team member pushes anything to a specific branch of your project all unit and integration tests should run first hand .&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can do that with jenkins .&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You want that everytime a push is made to the repo it gets re build , jenkins got you .&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;CI/CD is very powerful tool for any developer to have in this era and there are many tools that let you do this , &lt;strong&gt;Jenkins&lt;/strong&gt; being one of them.&lt;/p&gt;

&lt;p&gt;Ok , so now you understood what jenkins is , lets just use it in our project and try to create a pipeline.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go ahead and download &lt;a href="https://www.jenkins.io/download/" rel="noopener noreferrer"&gt;jenkins&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Once downloaded go to the directory using your terminal &lt;/li&gt;
&lt;li&gt;once inside the terminal , type the command
&lt;code&gt;Java -jar jenkins.war&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;This will start the jenkins on &lt;em&gt;localhost:8080&lt;/em&gt; and will also give you the password autogenerated 
&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%2F3zrkm4m0u4a1e2gl4xlt.png" alt="Jenkins password " width="800" height="418"&gt;
&lt;/li&gt;
&lt;li&gt;copy this password and go to &lt;em&gt;localhost:8080&lt;/em&gt; and you will be greeted by this screen
&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%2F6h8jumjb92kqj8bg9f1u.jpeg" alt="unlock jenkins" width="800" height="548"&gt;
&lt;/li&gt;
&lt;li&gt;Use the password you just copied from the terminal here&lt;/li&gt;
&lt;li&gt;If you want you can also create a user (we are not going to do that here).&lt;/li&gt;
&lt;li&gt;so every thing set up this page will appear in front of you(you wont be having the multitesting in front of you )
&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%2F3g001zdd8pvcvnwqxn1h.png" alt="jenkins" width="800" height="500"&gt;
&lt;/li&gt;
&lt;li&gt;Here what you can do is click on new item and this screen will be visible to you
&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%2Fueo90y82bdzhud0oz2ag.png" alt="new item jenkins" width="800" height="500"&gt;
&lt;/li&gt;
&lt;li&gt;Here give your project a name and click on multipipeline and click ok&lt;/li&gt;
&lt;li&gt;You will be greeted with a new screen here , that has a bunch of options to configure but what we want is we want to hook it up with our github repo . So first of all create a create a new github repo and make sure you create a file namely &lt;code&gt;Jenkinsfile&lt;/code&gt; in it .&lt;/li&gt;
&lt;li&gt;Inside that file paste this code
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipeline {
    agent any

    stages {
        stage('Build') {
            steps {
                echo 'Building..'
            }
        }
        stage('Test') {
            steps {
                echo 'Testing..'
            }
        }
        stage('Deploy') {
            steps {
                echo 'Deploying....'
            }
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Once this is done take the https github url from the clone like this 
&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%2F6prrla1b42zdpdmg06lv.png" alt="github url" width="800" height="500"&gt;
&lt;/li&gt;
&lt;li&gt;Ok perfect , now go back to your jenkins local host 
and from all those options find Branches &amp;gt; Click on Add Source and click on git&lt;/li&gt;
&lt;/ul&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%2Fb4jl13ldshjykqsrqhyc.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%2Fb4jl13ldshjykqsrqhyc.png" alt="git integration in jenkins" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Now paste your github url that you copied over here like this &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%2Fcm7ot7cvawrllpzhr4qv.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%2Fcm7ot7cvawrllpzhr4qv.png" alt="github integration jenkins" width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;perfect 👌  , now click on save .&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What it will do is it will scan your branches by itself and run the tests for you .&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;By this point of time you are basically done but just to make it a little interesting what you can do is push anything to your code base and then come to your github and click on scan multibranch pipeline now .&lt;br&gt;
This will force it to rescan the code and in any branch where it see the change it will re build that branch (On a real life scenario you dont have to do it manually , it will do it yourself via a github hook that will be made inside of the github , but since its on localhost git hub wont allow that )&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ok perfect you are done and can go ahead and learn more about the code in the jenkins file &lt;a href="https://www.jenkins.io/doc/book/pipeline/jenkinsfile/" rel="noopener noreferrer"&gt;here&lt;/a&gt; .&lt;br&gt;
You can do a lot of cool stuff with it , run cron jobs , run tests etc which is outside of the scope of this tutorial.&lt;/p&gt;

&lt;p&gt;Ok , i hope you guys have learnt anything new from this tutorial .&lt;br&gt;
Feel free to reach me at my &lt;a href="'https://www.linkedin.com/in/junaid-shah-ba2910a9/'"&gt;Linkedin&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Want to encourage me to create posts like this more &lt;br&gt;
&lt;a href="'https://www.buymeacoffee.com/jshahcodes'"&gt;Buy me a coffee&lt;/a&gt;&lt;/p&gt;

</description>
      <category>github</category>
      <category>git</category>
      <category>jenkins</category>
      <category>devops</category>
    </item>
    <item>
      <title>Whats new in Next Js 11</title>
      <dc:creator>Junaid</dc:creator>
      <pubDate>Thu, 19 Aug 2021 17:28:26 +0000</pubDate>
      <link>https://dev.to/__junaidshah/whats-new-in-next-js-11-5g9l</link>
      <guid>https://dev.to/__junaidshah/whats-new-in-next-js-11-5g9l</guid>
      <description>&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%2Feiz4s3guxkngasst7tdg.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%2Feiz4s3guxkngasst7tdg.png" alt="What new in next js 11" width="800" height="718"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Lets make the web faster with Next Js 11.
&lt;/h2&gt;

&lt;p&gt;Next Js people are working really hard and getting some amazing features to market in the product .&lt;/p&gt;

&lt;p&gt;The new features that are included are&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Conformance&lt;/li&gt;
&lt;li&gt;Improved Performance&lt;/li&gt;
&lt;li&gt;next/script&lt;/li&gt;
&lt;li&gt;next/image&lt;/li&gt;
&lt;li&gt;Webpack 5&lt;/li&gt;
&lt;li&gt;Create React App Migration (Experimental)&lt;/li&gt;
&lt;li&gt;Next.js Live&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Lets talk about all of them one by one&lt;/p&gt;

&lt;h2&gt;
  
  
  Conformance
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="'https://web.dev/conformance/"&gt;Conformance&lt;/a&gt; is a system that provides carefully crafted solutions and rules to support optimal loading and Core Web Vitals, with further additions coming to support other quality aspects like security and accessibility. These solutions free your team from memorizing all the latest rules for optimal loading performance, while still giving you the flexibility to make the right choices for your applications.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What conformance basically allows developers is it allows them to follow rules while writing code even if the developer will forget to use some good practice this system will automatically do it for them.&lt;/p&gt;

&lt;p&gt;It will also support &lt;a href="'https://eslint.org/'"&gt;Eslint&lt;/a&gt; out of the box.&lt;br&gt;
In order to use it you need to run&lt;br&gt;
&lt;code&gt;npx run lint&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Performance
&lt;/h2&gt;

&lt;p&gt;Since Next.js 10, next js team has  been obsessed with further improving the developer experience of Next.js. &lt;/p&gt;

&lt;p&gt;Next.js 11 includes another optimization to Babel to further reduce the startup time. They have  created a brand new implementation of the Babel loader for webpack, optimizing loading and adding an in-memory config caching layer. In practice, this means no change for developers but will ultimately mean a faster development experience.&lt;/p&gt;
&lt;h2&gt;
  
  
  next/script
&lt;/h2&gt;

&lt;p&gt;This is a very great feature that comes in next js 11 .&lt;br&gt;
What this lets you do is it lets you add scripts to your site  however you want like for example &lt;br&gt;
If there is a script that you want to run even before the page becomes interactive you can do that .&lt;br&gt;
If there is a script that can be delayed and can run after the page has been loaded it will allow you to do that as well.&lt;/p&gt;

&lt;p&gt;very cool and useful feature. &lt;br&gt;
To do this you must use the next/script component and then you can use the strategy&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;beforeInteractive:&lt;/strong&gt; For critical scripts that need to be fetched and executed before the page is interactive, such as bot detection and consent management. These scripts are injected into the initial HTML from the server and run before self-bundled JavaScript is executed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;afterInteractive (default):&lt;/strong&gt; For scripts that can fetch and execute after the page is interactive, such as tag managers and analytics. These scripts are injected on the client-side and will run after hydration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;lazyOnload&lt;/strong&gt; For scripts that can wait to load during idle time, such as chat support and social media widgets.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Script
  src="https://polyfill.io/v3/polyfill.min.js?features=Array.prototype.map"
  strategy="beforeInteractive" // lazyOnload, afterInteractive
/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  next/image
&lt;/h2&gt;

&lt;p&gt;Image component has improved quite a lot and this is also a useful feature and would be used by many developers globally.&lt;br&gt;
This update for the image will let you &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;use a placeholder for the image while it is being loaded (blur placeholder).&lt;/li&gt;
&lt;li&gt;You no longer need to give the height and width for the image now.
Example
&lt;code&gt;&amp;lt;Image src="abc.jpeg" alt="some very cool picture"/&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For using the blur you can do placeholder="blur" and it will automatically blur the image till the time it will be loaded&lt;br&gt;
Example&lt;br&gt;
&lt;code&gt;&amp;lt;Image src="apple.jpg" alt="an apple a day keeps doctor away" placeholder="blur"/&amp;gt;&lt;/code&gt;&lt;br&gt;
[Example of the blur]&lt;br&gt;
&lt;a href="https://nextjs.org/static/blog/next-11/Placeholder.mp4" rel="noopener noreferrer"&gt;https://nextjs.org/static/blog/next-11/Placeholder.mp4&lt;/a&gt;&lt;br&gt;
Next.js also supports blurring dynamic images by allowing you to provide a custom blurDataURL, which is provided by your backend.&lt;/p&gt;

&lt;h2&gt;
  
  
  webpack 5
&lt;/h2&gt;

&lt;p&gt;Another great feature allowing devs to upgrade to webpack 5 hassle free.&lt;br&gt;
They worked closely with the community to ensure a smooth transition to webpack 5, over 3,400 existing Next.js integration tests run on every pull request with webpack 5 enabled.&lt;br&gt;
They also said that if your application has a custom webpack configuration, we recommend following the &lt;a href="'https://nextjs.org/docs/messages/webpack5'"&gt;following steps&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  CRA Migration(Experimental)
&lt;/h1&gt;

&lt;p&gt;Since many people were switching from Create React App to next js so these people came up and made the journey effortless (still working on that but you get it)&lt;/p&gt;

&lt;p&gt;To help developers convert their applications to Next.js, they introduced a new tool to &lt;em&gt;@next/codemod&lt;/em&gt; that automatically converts Create React App applications to be Next.js compatible.&lt;/p&gt;

&lt;p&gt;To get started migrating your Create React App project use the following command:&lt;br&gt;
&lt;code&gt;npx @next/codemod cra-to-next&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Its still a experimental feature.&lt;/p&gt;

&lt;h2&gt;
  
  
  next js live
&lt;/h2&gt;

&lt;p&gt;&lt;a href="'https://nextjs.org/_next/image?url=%2Fstatic%2Fblog%2Fnext-11%2FBrowser.png&amp;amp;w=1920&amp;amp;q=75'"&gt;Next js live&lt;/a&gt; is a very very cool feature that allows users collaborate on the fly without using any other tool .&lt;/p&gt;

&lt;p&gt;By leveraging cutting-edge technology like ServiceWorker, WebAssembly, and ES Modules, Next.js Live puts the entire development process in the web browser. &lt;/p&gt;

&lt;p&gt;This opens up possibilities like collaborating and sharing instantaneously with a URL, without a build step. For developers, this means a faster feedback loop, less time waiting for builds, and real-time peer programming and editing within the browser.&lt;/p&gt;

&lt;p&gt;Want to encourage me to create posts like this more &lt;br&gt;
&lt;a href="'https://www.buymeacoffee.com/jshahcodes'"&gt;Buy me a coffee&lt;/a&gt;&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>javascript</category>
      <category>jamstack</category>
    </item>
    <item>
      <title>SQL Joins you should know</title>
      <dc:creator>Junaid</dc:creator>
      <pubDate>Sat, 14 Aug 2021 14:41:20 +0000</pubDate>
      <link>https://dev.to/__junaidshah/sql-joins-you-should-know-c6i</link>
      <guid>https://dev.to/__junaidshah/sql-joins-you-should-know-c6i</guid>
      <description>&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%2Frsu6ijc700bkdou9jdhd.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%2Frsu6ijc700bkdou9jdhd.png" alt="sql joins you should know" width="800" height="448"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We all as developers know what a database is , right&lt;br&gt;
Its a way of storing your data whether it be text , images , audio or video databases can be used to save all kinds of data and over the years databases have evolved from having just SQL to now having databases like Mongo db .&lt;/p&gt;

&lt;p&gt;But the basics of database can be learnt every time in order to better understand how databases work.&lt;/p&gt;

&lt;p&gt;So we know that a table is something that stores the table in a particular structure called &lt;strong&gt;columns&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So e.g we can have a table for login where in we can store the email and password of the user to authenticate him every time he tries to login and so on&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Joins&lt;/strong&gt; come into play when we have to join(as the name suggests) two tables in order to get a table that has some common ground(that we tell in the join itself ).&lt;br&gt;
So the most used joins that there are right now are&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Inner Join (also called as simply JOIN)&lt;br&gt;
Left Join&lt;br&gt;
Right Join&lt;br&gt;
Outer Join( also called FULL OUTER JOIN)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So lets go over each one of them one by one&lt;/p&gt;
&lt;h3&gt;
  
  
  Inner Join
&lt;/h3&gt;

&lt;p&gt;Inner join also can be called as simply “join” is a way getting data out of two tables that would be common among both the tables.&lt;br&gt;
This can be better understood by an example&lt;br&gt;
Lets just say we have a &lt;em&gt;facebook&lt;/em&gt; table Like this&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%2F1b9v5flzitbd4denrzev.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%2F1b9v5flzitbd4denrzev.png" alt="Inner Join Sql tablee" width="800" height="702"&gt;&lt;/a&gt;&lt;br&gt;
and lets say we also have another table of &lt;em&gt;instagram&lt;/em&gt; likes for some users&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%2F948db0bm4rsgx3dqhwys.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%2F948db0bm4rsgx3dqhwys.png" alt="Inner Join Sql table" width="800" height="702"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now the way we would use inner join on these two is like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM facebook JOIN instagram ON facebook.name = instagram.name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So the way this works is we are telling SQL to join both the tables and create a new table that has all the entries that are common to both these tables and satisfy the criteria that is &lt;strong&gt;facebook.name = instagram.name&lt;/strong&gt; , everything else will not be included in that table.&lt;/p&gt;

&lt;p&gt;So katie and kim will not be included in the join table.&lt;br&gt;
The Inner Join table will look like this then&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%2Fatuxzqqqu0v0v1svpohs.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%2Fatuxzqqqu0v0v1svpohs.png" alt="Inner Join " width="800" height="295"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Left Join
&lt;/h3&gt;

&lt;p&gt;Left join is another join that we can use to join the tables in a way that all the values of the left table are going to come in the joined table irrespective of if they have a match or not .&lt;/p&gt;

&lt;p&gt;If they don't have a match a null value is passed in that column&lt;/p&gt;

&lt;p&gt;Let's just take the previous example again.&lt;br&gt;
If we use a left join on those two tables , the query will look like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM facebook LEFT JOIN instagram ON facebook.name = instagram.name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Take a moment and think how the resulted table will look like .&lt;br&gt;
OK , so the table will look like this.&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%2Fvrvgt2gel6a1zcwb08sv.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%2Fvrvgt2gel6a1zcwb08sv.png" alt="Left Joined Table" width="800" height="374"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ok, so you can see that the first table in the query thats &lt;em&gt;Facebook&lt;/em&gt; , its all columns are put in the table where as in the &lt;em&gt;Instagram&lt;/em&gt; table , since there was not any match for that column of &lt;em&gt;Facebook&lt;/em&gt; name thats “kim” , so the column are put as null.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you would have written the query as &lt;em&gt;Instagram&lt;/em&gt; first and then &lt;em&gt;Facebook&lt;/em&gt; , then the query would have done the opposite of what it did here .&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It would have taken the &lt;em&gt;Instagram&lt;/em&gt; table put all its columns and when there would have been no match for any column the field would have been put as null.&lt;/p&gt;

&lt;p&gt;The opposite that i talked about here is what can also be called as &lt;em&gt;RIGHT JOIN&lt;/em&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Right join is exactly what a left join is , but opposite .&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What it will do is take the right table instead of left and do the same thing that it did in the left join .&lt;br&gt;
Right join can also be written as a left join as well (if you can visualise it , you get it).&lt;br&gt;
Lets do i Right join on the same exact query we did for the left join&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM facebook RIGHT JOIN instagram ON facebook.name = instagram.name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the table will look like this&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%2Fd6xg60ypcvflm6o5c3kt.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%2Fd6xg60ypcvflm6o5c3kt.png" alt="Right Join table" width="800" height="374"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the exact same as like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM instagram LEFT JOIN facebook ON facebook.name = instagram.name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So as i said left join can also be written as right join and vice versa.&lt;/p&gt;

&lt;h3&gt;
  
  
  FULL OUTER JOIN
&lt;/h3&gt;

&lt;p&gt;FULL OUTER JOIN is a way of joining tables such that both the tables columns will be available and whenever there is no match in the next column a null is placed for that .&lt;br&gt;
Lets take the previous example and do a full outer join on that one&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT * FROM facebook FULL OUTER JOIN instagram ON facebook.name = instagram.name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So the joined table will look like this&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%2Fzabwsjvg0styf0x95rxy.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%2Fzabwsjvg0styf0x95rxy.png" alt="Full Outer Join" width="800" height="443"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So as you can see in the joined table whenever there is no match a null is placed in the adjacent column for that .&lt;br&gt;
OK , so thats about it for JOINS in tables .&lt;br&gt;
I hope you guys got some value out of it and learnt something new today.&lt;br&gt;
You can always reach to me at &lt;a href="https://www.linkedin.com/in/junaid-shah-ba2910a9/" rel="noopener noreferrer"&gt;Junaid shah&lt;/a&gt;&lt;/p&gt;

</description>
      <category>sql</category>
      <category>database</category>
      <category>beginners</category>
      <category>postgres</category>
    </item>
    <item>
      <title>Smart VS Dumb Components</title>
      <dc:creator>Junaid</dc:creator>
      <pubDate>Wed, 11 Aug 2021 09:19:40 +0000</pubDate>
      <link>https://dev.to/__junaidshah/smart-vs-dumb-components-57b8</link>
      <guid>https://dev.to/__junaidshah/smart-vs-dumb-components-57b8</guid>
      <description>&lt;h2&gt;
  
  
  I was giving an interview some days back and every thing was going great .
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Then the interviewer asked &lt;em&gt;"Can you tell me the difference between a smart and a dumb component?&lt;/em&gt; "&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I had although worked in a product based company for about 3 months then but had no idea what makes a component smart or dumb.&lt;/p&gt;

&lt;p&gt;Obviously you don't have to go that road because today i am going to share with you what is the difference between a smart and dumb component in react.&lt;br&gt;
This question will not be asked to a junior but i believe everyone should have a fair understanding of the concepts.&lt;/p&gt;

&lt;p&gt;So lets get going &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dumb Component&lt;/strong&gt;&lt;br&gt;
Dumb component as the name suggests is "dumb" &lt;br&gt;
meaning that it doesn't care about anything just itself.&lt;br&gt;
It does not change any state or anything else .&lt;br&gt;
Its just dumb&lt;br&gt;
Dumb components are mostly made just for the UI based work.&lt;br&gt;
Here is an example of a Dumb Component&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input label={label} type={type} onChange={onChange}/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can guess that all the things that it needs that are changeable like label or type or a onchange callback is given as props and all it does is show the UI.&lt;br&gt;
You can use it wherever you want to &lt;br&gt;
You just have to pass the props it has and it will work like a breeze.&lt;br&gt;
&lt;strong&gt;Smart Component&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Smart components (or container components) on the other hand have a different responsibility. Because they have the burden of being smart, they are the ones that keep track of state and care about how the app works.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Smart Components has there own state inside of the components itself.&lt;br&gt;
Its can also then send down the same state to the dumb components so they can work as expected without worrying about the state.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A good example of a smart component can be the &lt;em&gt;root&lt;/em&gt; of the app which handles a lot of the state and can also pass along the state to other components as well.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So thats the comparison between smart and dumb components .&lt;br&gt;
I hope you guys got something to learn from it .&lt;/p&gt;

&lt;p&gt;Want to encourage me to create posts like this more &lt;br&gt;
&lt;a href="'https://www.buymeacoffee.com/jshahcodes'"&gt;Buy me a coffee&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>questions</category>
      <category>interview</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Creating a CRUD App using Flask and SqlAlchemy</title>
      <dc:creator>Junaid</dc:creator>
      <pubDate>Wed, 28 Jul 2021 05:00:28 +0000</pubDate>
      <link>https://dev.to/__junaidshah/creating-a-crud-app-using-flask-and-sqlalchemy-2m5k</link>
      <guid>https://dev.to/__junaidshah/creating-a-crud-app-using-flask-and-sqlalchemy-2m5k</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;Flask is a python library that lets you create dynamic webapps using python.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Flask has great powers that we will be looking into in a minute.&lt;/p&gt;

&lt;p&gt;In this tutorial we will be creating a simple Todo App using flask along with &lt;em&gt;sqlite&lt;/em&gt; using our ORM i.e &lt;em&gt;flask_sqlalchemy&lt;/em&gt; and &lt;em&gt;jinja2&lt;/em&gt; for using great powers inside of the html.&lt;/p&gt;

&lt;p&gt;ORM means object relational mapping meaning that you get to interact with the database using your language of choice instead of using SQL queries .&lt;/p&gt;

&lt;p&gt;ORM also comes helpful in a way that if you in the future would have to change your database for the app you do not have to write the whole schema for the database again .&lt;/p&gt;

&lt;p&gt;you just have to change the database url and its done (easy -peasy).&lt;/p&gt;

&lt;p&gt;OK , let's get started with the code.&lt;/p&gt;

&lt;p&gt;First of all what you need to do is Create a folder with your  app name &lt;br&gt;
&lt;strong&gt;e.g FlaskTodoApp&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;inside of the folder create a new folder called venv&lt;/p&gt;

&lt;p&gt;We are going to create a virtual environment for the flask to run inside of.&lt;br&gt;
open up your project in vscode and go the terminal&lt;br&gt;
Type&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;python3 -m venv venv&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;then type for mac users&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;. venv/bin/active.fish&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;For windows users type&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;venv/bin/active&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;and your environment will be created .&lt;br&gt;
Now create two more folders inside of the project but outside of the venv folder namely &lt;em&gt;templates&lt;/em&gt; and &lt;em&gt;static&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Template is where all the templates i.e html css files will be saved&lt;br&gt;
and if you have any static file like an image or anything that will be saved inside of the static folder.&lt;br&gt;
&lt;em&gt;Your folder structure should look like this&lt;/em&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%2Fa5pz8xlmeaccg0g7jemo.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%2Fa5pz8xlmeaccg0g7jemo.png" alt="Folder structure for flask" width="496" height="1196"&gt;&lt;/a&gt;&lt;br&gt;
now create a file namely &lt;em&gt;app.py&lt;/em&gt; and type this code inside of that:-&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello_world():   
    return "&amp;lt;p&amp;gt;Hello world from flask&amp;lt;/p&amp;gt;"

if __name__ == "__main__":
    app.run(debug=True)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you look closely there is a lot going on here&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;first the &lt;em&gt;@app.route&lt;/em&gt; is used to declare a route for the webpage ("/" means the index page i.e abc.com)&lt;/li&gt;
&lt;li&gt;Then we are telling the app to run in debug mode(until we create the app fully then we can go to production , don't push this to production).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can test this app by going to the terminal and typing&lt;br&gt;
&lt;code&gt;python app.py&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;and it will show you where it is running e.g &lt;em&gt;&lt;a href="http://127.0.0.1:5000/" rel="noopener noreferrer"&gt;http://127.0.0.1:5000/&lt;/a&gt;&lt;/em&gt; is the default .&lt;br&gt;
Head over to there and see magic 🥳.&lt;/p&gt;

&lt;p&gt;Great so we have just made a simple webpage which shows a &lt;em&gt;p&lt;/em&gt;  tag inside .&lt;br&gt;
But what if we want to display a whole webpage with some cool  images , text , headings and all that .&lt;br&gt;
Thats where the built in &lt;code&gt;render_template&lt;/code&gt; of flask comes into play.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;create a file inside of your templates e.g home.html&lt;/li&gt;
&lt;li&gt;write whatever html you would want to show to the user &lt;/li&gt;
&lt;li&gt;Head back over to your app.py&lt;/li&gt;
&lt;li&gt;Inside of that file the code will look like this now
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask import Flask, render_template

app = Flask(__name__)

@app.route("/")
def hello_world():   
    return render_template('home.html')

if __name__ == "__main__":
    app.run(debug=True)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Now head over to the url again and refresh the page and see the magic happening&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;If your webpage is working properly thats amazing ,&lt;br&gt;
Congratulations to you 🥳🥳.&lt;br&gt;
First part of the app is done .&lt;br&gt;
Now for the database part we will be using sqlite for the database and flasksqlalchemy as the ORM as already discussed and for the data to show to the user we will use Jinja2 for that.&lt;/p&gt;

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

&lt;p&gt;First install flask_sqlalchemy by&lt;br&gt;
&lt;code&gt;pip install flask_sqlalchemy&lt;/code&gt;&lt;br&gt;
and it should be installed for you.&lt;/p&gt;

&lt;p&gt;Now the boiler plate for creating a database connection is as follows&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///todo.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db=SQLAlchemy(app)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;type this code in the same app.py file of yours.&lt;/p&gt;

&lt;p&gt;now for creating a table in the database we need to use classes in python to create a model like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Todo(db.Model):
    sno=db.Column(db.Integer,primary_key=True)
    title=db.Column(db.String(200),nullable=False)
    description = db.Column(db.String(200), nullable=False)
    def __repr__(self) :
        return "{} is the title and {} is the description".format(self.title,self.description)


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

&lt;/div&gt;



&lt;p&gt;Here you can see we are creating a class for the todo table that has 3 columns:-&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;S.no this will act as a primary key and will be auto generated by the database&lt;/li&gt;
&lt;li&gt;Title of the todo&lt;/li&gt;
&lt;li&gt;Description of the todo.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Great , now let's create the database for the first time.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to your terminal &lt;/li&gt;
&lt;li&gt;type &lt;strong&gt;python&lt;/strong&gt; and hit Enter &lt;/li&gt;
&lt;li&gt;now type &lt;code&gt;from app import db&lt;/code&gt; and hit enter&lt;/li&gt;
&lt;li&gt;then type &lt;code&gt;db.create_all()&lt;/code&gt; and hit enter&lt;/li&gt;
&lt;li&gt;you should see the todo.db file created inside your project since we gave the database url as local file &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Great if everything works perfectly then congratulations, your database has now been created .&lt;/p&gt;

&lt;p&gt;Your Database is created &lt;br&gt;
Your table is created with the columns you wanted to have .&lt;br&gt;
Perfect.&lt;/p&gt;

&lt;p&gt;Now lets create a form inside of your home.html to upload the data to the database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;form action="/" id="formSubmission" method="POST"&amp;gt;
    &amp;lt;span&amp;gt;Title&amp;lt;/span&amp;gt;
    &amp;lt;input type="text"name="title" placeholder="enter your Title" id="name"&amp;gt;
    &amp;lt;span&amp;gt;Description&amp;lt;/span&amp;gt;
    &amp;lt;input type="text"name="description" placeholder="Enter your description" id="description"&amp;gt;
    &amp;lt;button type="submit"&amp;gt;Add Todo&amp;lt;/button&amp;gt;
  &amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;whats important here is you give name attribute to your inputs &lt;/li&gt;
&lt;li&gt;Lets also create a table to showcase the todos coming from the database
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; &amp;lt;ul id="data"&amp;gt;
   &amp;lt;li&amp;gt;Title&amp;lt;/li&amp;gt;
   &amp;lt;li&amp;gt;Time&amp;lt;/li&amp;gt;
   &amp;lt;li&amp;gt;Description&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will be using jinja for loop here to show the data but first lets get the C(create) part working.&lt;/p&gt;

&lt;p&gt;So lets create our end point for the creation of data in our database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@app.route("/",methods=['POST'])
def main_page():
    if request.method=='POST':
        title=request.form['title']
        description=request.form['description']
        todo=Todo(title=title ,description=description)
        db.session.add(todo)
        db.session.commit()
    alltodos=Todo.query.all()
    return render_template('index.html',todos=alltodos)

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;For adding values in your database the command is &lt;code&gt;db.session.add(your_data_object_here)&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;It wont get saved if you do not commit it so &lt;code&gt;db.session.commit()&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Perfect&lt;/li&gt;
&lt;li&gt;Here you can see that we are checking that if the request coming is a post request then get the data from the inputs and create a todo object with the details you want to save and then add to the database.&lt;/li&gt;
&lt;li&gt;If the request is not a post request then get all the todos that are saved in the database and send them over to the webpage using jinja . (here we have named it todos that we will be using in the webpage ).&lt;/li&gt;
&lt;li&gt;Now head over to your webpage and do the following changes
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; {% for user in todos %}
     &amp;lt;li&amp;gt;{{loop.index}}&amp;lt;/li&amp;gt;
  &amp;lt;li&amp;gt;{{user.title}}&amp;lt;/li&amp;gt;
     &amp;lt;li&amp;gt;{{user.description}}
         &amp;lt;div class="buttons"&amp;gt;


      &amp;lt;button&amp;gt;&amp;lt;a href="/delete/{{user.sno}}"&amp;gt;Delete&amp;lt;/a&amp;gt;
&amp;lt;button&amp;gt;&amp;lt;a href="/update/{{user.sno}}"&amp;gt;Delete&amp;lt;/a&amp;gt;&amp;lt;/button&amp;gt;

              &amp;lt;/div&amp;gt;
     &amp;lt;/li&amp;gt;

{% endfor %}

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;This is for loop that is given to us by jinja and we can use it.&lt;/li&gt;
&lt;li&gt;We have also put the buttons for deleting and updating the todo but lets ignore that for now.&lt;/li&gt;
&lt;li&gt;So you can see we extracted title and description from our todos array that we are getting.&lt;/li&gt;
&lt;li&gt;loop.index is the index just as we have index in any loop in any language , this is just used to give a number to the todo.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;OK 👍 Most of the heavy lifting is done.&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Lets look at some of the commands of sqlalchemy that we can use&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;we already saw&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;db.session.add()&lt;/li&gt;
&lt;li&gt;db.commit()&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;We also have&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;db.session.filter_by(criteria to filter e.g sno = 1)
This is used to filter the database based on the criteria we provide e.g filter the database and get me only the row where in we have sno = 1 and it will give it to you.
Now if the database has more than 1 with the same criteria it will give you all of that , so we can chain it up with &lt;code&gt;.first()&lt;/code&gt; in order to get only the first instance of it.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Then we also have &lt;code&gt;db.session.delete(todo_to_delete)&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Ok ! so upto now if you run the code you should be able to  view all the todos that are there and also save the new todos to the database.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now Let's delete them.&lt;/strong&gt;&lt;br&gt;
For deleting any todo you need something thats unique to it only e.g here we have the sno thats a primary key and that will be unique to every todo.&lt;br&gt;
Ok lets create the end point for deletion.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@app.route("/delete/&amp;lt;int:sno&amp;gt;")
def delete(sno):
    deletetodo = Todo.query.filter_by(sno=sno).first()
    db.session.delete(deletetodo)
    db.session.commit()
    return redirect("/")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Easy , right &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ok so here you can see that the end point needs a sno that would be an integer value and then we pass that to the function&lt;/li&gt;
&lt;li&gt;What we then do is query the database and then filter out the exact todo from the database&lt;/li&gt;
&lt;li&gt;Then pass that todo to the delete function &lt;/li&gt;
&lt;li&gt;Then we commit the changes&lt;/li&gt;
&lt;li&gt;Great ! Once all the changes would be saved we will be redirecting the user back to the index page using &lt;code&gt;redirect&lt;/code&gt; module imported from the flask&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sweet ! you now would be able to delete your todos as well .&lt;br&gt;
&lt;strong&gt;Now we are able to&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create the todo&lt;/li&gt;
&lt;li&gt;Delete the todo&lt;/li&gt;
&lt;li&gt;And View All the todos&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Now in order to Update the todo , its very easy as well&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Let me break it down to points for you&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First create the end point for the update where in we will get the sno of the todo (the same way we did for delete)&lt;/li&gt;
&lt;li&gt;Then create a new webpage for the update todo form&lt;/li&gt;
&lt;li&gt;send the todo that we will get from the end point to this page just as we did in the view end point for all todos.&lt;/li&gt;
&lt;li&gt;Then once you get the data there , once the user clicks on update send the request to the same endpoint but using a &lt;code&gt;POST&lt;/code&gt; request .&lt;/li&gt;
&lt;li&gt;And in the end point we will check that if the request is a  post request update the todo and then redirect the user back to the index page.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Lets code it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;we already have the button for the updation of the todo .so lets create the end point.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@app.route("/updatetodo/&amp;lt;int:sno&amp;gt;",methods=['POST'])
def update_todo(sno):

     if request.method == 'POST':
        updatetodo = Todo.query.filter_by(sno=sno).first()
        title = request.form['title']
        description = request.form['description']
        todo = Todo(title=title, description=description)
        updatetodo.title=title
        updatetodo.description=description
        db.session.commit()
        return redirect("/")
    updatetodo = Todo.query.filter_by(sno=sno).first()
    return render_template('update.html',
updatetodo=updatetodo)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;ok so the end point is created.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lets create a new file namely update.html for the update todo and put this code inside(along with the boiler plate for html obviously)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
&amp;lt;div class="container"&amp;gt;
  &amp;lt;form action="/updatetodo/{{updatetodo.sno}}" id="formSubmission" method="POST"&amp;gt;

    &amp;lt;span&amp;gt;Title&amp;lt;/span&amp;gt;
    &amp;lt;input type="text"name="title" placeholder="enter your Title" id="name" value="{{updatetodo.title}}"&amp;gt;
    &amp;lt;span&amp;gt;Description&amp;lt;/span&amp;gt;
    &amp;lt;input type="text"name="description" placeholder="Enter your description" id="description" value="{{updatetodo.description}}"&amp;gt;
    &amp;lt;button type="submit"&amp;gt;Update&amp;lt;/button&amp;gt;

  &amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ok , Great &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;So now when you click on the update button the user will be taken to this page with the fields already filled with the existing data .&lt;/li&gt;
&lt;li&gt;And on clicking the submit the post request will be sent to the end point and the details i.e title and description will be changed to the new data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;** If you have made it to this point congratulation ✨✨✨.***&lt;br&gt;
There is a lot that can be done afterwards but i will leave you guys to it.&lt;br&gt;
I hope you guys find it useful .&lt;br&gt;
Thankyou so much .&lt;br&gt;
Keep coding &lt;/p&gt;

&lt;p&gt;Want to encourage me to create posts like this more &lt;br&gt;
&lt;a href="'https://www.buymeacoffee.com/jshahcodes'"&gt;Buy me a coffee&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>postgres</category>
      <category>database</category>
      <category>orm</category>
    </item>
  </channel>
</rss>
