<?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: Muhammad Azfar Aslam</title>
    <description>The latest articles on DEV Community by Muhammad Azfar Aslam (@muhammadazfaraslam).</description>
    <link>https://dev.to/muhammadazfaraslam</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%2F909073%2F3cebf7f2-a81b-4370-9bd5-ddd57c5e86a5.png</url>
      <title>DEV Community: Muhammad Azfar Aslam</title>
      <link>https://dev.to/muhammadazfaraslam</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/muhammadazfaraslam"/>
    <language>en</language>
    <item>
      <title>Implementing Google Publisher Tag Ads in Next.js 15 Single Page Application 2025</title>
      <dc:creator>Muhammad Azfar Aslam</dc:creator>
      <pubDate>Mon, 20 Jan 2025 07:59:01 +0000</pubDate>
      <link>https://dev.to/muhammadazfaraslam/implementing-google-publisher-tag-ads-in-nextjs-15-single-page-application-2025-3kof</link>
      <guid>https://dev.to/muhammadazfaraslam/implementing-google-publisher-tag-ads-in-nextjs-15-single-page-application-2025-3kof</guid>
      <description>&lt;p&gt;Hi, Salut, Hola, Bonjour, Salam,&lt;/p&gt;

&lt;p&gt;I’m back with another informative tutorial! Whenever I encounter a tricky problem and can’t find a proper solution or guide compiled in one place on the Internet, I take it as an opportunity to create one. This way, I contribute to our developer community and ensure that others don’t experience the same frustrations I did.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Google Publisher Tag (GPT)&lt;/strong&gt; ads can be challenging to implement in a Single-Page Application (SPA) due to issues such as ads only loading on the first-page load, failing to reload on route changes, and layout shifts causing Cumulative Layout Shift (CLS). In this blog, I’ll share my solution for implementing GPT ads in Next.js 15 SPA, ensuring they work seamlessly on route changes while addressing CLS issues.&lt;/p&gt;

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

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Ads Only Load on First Page:&lt;/strong&gt; In SPAs, scripts often execute only on the initial load. As a result, ads might not refresh when navigating to a new route.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cumulative Layout Shift (CLS):&lt;/strong&gt; Ads loading asynchronously often cause layout shifts, which impact the user experience and Core Web Vitals.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The Solution
&lt;/h2&gt;

&lt;p&gt;After thorough research and experimentation, I came up with a solution to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Ensure ads load dynamically on route changes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Predefine ad sizes to avoid CLS.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Adding the GPT Script
&lt;/h2&gt;

&lt;p&gt;To start, include the GPT script in the root layout file to ensure it’s available throughout the app. In rootlayout.js:&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
  async
  src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"
&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script
  dangerouslySetInnerHTML={{
    __html: `window.googletag = window.googletag || { cmd: [] };
      // Pushes a function to the GPT command queue to define and display the ad slot dynamically
      googletag.cmd.push(() =&amp;gt; {
        googletag.pubads().enableSingleRequest();
        googletag.enableServices();
      });`,
  }}
/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Ad Banner Component
&lt;/h2&gt;

&lt;p&gt;Next, create a reusable AdBanner.jsx component. This component ensures each ad slot has a predefined height and width, which prevents CLS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react";
import Ad from "@/components/common/Ad";

const AdBanner = ({ width = "728px", height = "90px", adId, slot }) =&amp;gt; {
  return (
    &amp;lt;div className="headerTopAdInner" style={{ width, height }}&amp;gt;
      &amp;lt;Ad adId={adId} slot={slot} /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Ad Component
&lt;/h2&gt;

&lt;p&gt;The Ad component dynamically loads and renders ads. It ensures cleanup on unmount to prevent memory leaks and stale ads:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useEffect } from "react";
import { ads } from "@/utils/ads";

function Ad({ adId, slot }) {
  // This component handles dynamic ad loading by defining and displaying ad slots
  // It ensures proper cleanup on unmount to avoid memory leaks and stale ads
  // Fetching the ad configuration for the given adId from a predefined list of ads
  const ad = ads[adId];

  useEffect(() =&amp;gt; {
    const { googletag } = window;

    // This check ensures the ad configuration exists before attempting to define the ad slot
    if (!ad) {
      console.error(`Ad configuration not found for adId: ${adId}`);
      return;
    }

    googletag.cmd.push(() =&amp;gt; {
      console.log(`Defining slot for adId: ${adId}`);

      const existingSlot = googletag.pubads().getSlots().find(
        (slot) =&amp;gt; slot.getSlotElementId() === adId
      );
      if (existingSlot) {
        googletag.destroySlots([existingSlot]);
      }

      const mapping = googletag
        .sizeMapping()
        .addSize([1024, 0], ad.mapping[1024] || [])
        .addSize([0, 0], ad.mapping[0] || [])
        .build();

      googletag
        .defineSlot(slot, ad.sizes, adId)
        .defineSizeMapping(mapping)
        .addService(googletag.pubads());

      googletag.display(adId);
    });

    // This return function acts as a cleanup mechanism, removing the ad slot when the component unmounts
    return () =&amp;gt; {
      googletag.cmd.push(() =&amp;gt; {
        const currentSlot = googletag.pubads().getSlots().find(
          (slot) =&amp;gt; slot.getSlotElementId() === adId
        );
        if (currentSlot) {
          googletag.destroySlots([currentSlot]);
        }
      });
    };
  }, [ad, adId, slot]);

  if (!ad) {
    return &amp;lt;div&amp;gt;Error: Ad configuration not found for adId: {adId}&amp;lt;/div&amp;gt;;
  }

  return &amp;lt;div id={adId}&amp;gt;&amp;lt;/div&amp;gt;;
}

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Ad Configuration
&lt;/h2&gt;

&lt;p&gt;Define all your ad configurations in a centralized file (ads.js):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const ads = {
  top: {
    sizes: [
      [728, 90],
      [300, 250],
    ],
    mapping: {
      0: [300, 250],
      1024: [728, 90],
    },
  },
  bottom: {
    sizes: [300, 250],
    mapping: {
      0: [300, 250],
      1024: [],
    },
  },
  sidebar: {
    sizes: [
      [728, 90],
      [300, 250],
    ],
    mapping: {
      0: [300, 250],
      1024: [728, 90],
    },
  },
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Using AdBanner
&lt;/h2&gt;

&lt;p&gt;Finally, integrate AdBanner into your components. For example, in the rootlayout.js, place ads above the header and in the footer:&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;AdBanner adId="top" slot="/2233445566/someName/top" /&amp;gt;
&amp;lt;AdBanner adId="bottom" slot="/2233445566/someName/bottom" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For article detail pages, add ads in the sidebar:&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;AdBanner adId="sidebar" slot="/2233445566/someName/sidebar" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Replace 2233445566 and someName with your Google Ad Manager account details.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Benefits of the Solution
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dynamic Ad Loading:&lt;/strong&gt; The useEffect hook ensures ads reload dynamically on route changes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;CLS Prevention:&lt;/strong&gt; Predefined dimensions for each ad slot eliminate layout shifts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Slot Cleanup:&lt;/strong&gt; Destroying slots on unmount prevents stale ads and memory leaks.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;Implementing Google Publisher Tag ads in a Next.js 15 SPA requires careful handling of script initialization, dynamic loading, and slot cleanup. By following this approach, you can ensure your ads work seamlessly across route changes while maintaining a smooth user experience.&lt;/p&gt;

&lt;p&gt;I hope this will be helpful, love to connect with you on &lt;a href="https://www.linkedin.com/in/muhammad-azfar-aslam" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Few more articles&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/managing-global-state-with-usereducer-and-context-api-in-next-js-14-2m17"&gt;Managing Global State with useReducer and Context API in Next JS 14&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/react-design-patterns-compound-component-pattern-2p0a"&gt;React Design Patterns: Compound Component Pattern&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/how-to-configure-react-js-app-on-wsl2-windows-10-3d1n"&gt;How to configure React JS app on WSL2 Windows 10&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/custom-tooltip-component-using-tailwind-and-react-js-186g"&gt;Custom 'Tooltip' component using Tailwind and React Js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/javascript-and-react-interview-questions-juniormid-level-2023-hd1"&gt;JavaScript and React Interview questions (Junior/Mid-level) 2023&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>nextjs</category>
      <category>gptads</category>
      <category>tutorial</category>
      <category>learning</category>
    </item>
    <item>
      <title>React Design Patterns: Compound Component Pattern</title>
      <dc:creator>Muhammad Azfar Aslam</dc:creator>
      <pubDate>Wed, 10 Jul 2024 10:27:30 +0000</pubDate>
      <link>https://dev.to/muhammadazfaraslam/react-design-patterns-compound-component-pattern-2p0a</link>
      <guid>https://dev.to/muhammadazfaraslam/react-design-patterns-compound-component-pattern-2p0a</guid>
      <description>&lt;p&gt;Salut, Hola, Bonjour, Hi and Salam to Everyone&lt;/p&gt;

&lt;p&gt;React's flexibility allows developers to create highly reusable and customizable components. One powerful design pattern that leverages this flexibility is the Compound Component Pattern. This pattern enables developers to build components composed of multiple, related sub-components. In this blog post, we'll explore the Compound Component Pattern and demonstrate its use through an example of a card component.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the Compound Component Pattern?
&lt;/h2&gt;

&lt;p&gt;The Compound Component Pattern involves creating a parent component that manages state and behavior, and child components that consume and display this state. This pattern allows you to build components that are highly flexible and reusable. The parent component provides context and state, while the child components use this context to render their UI parts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Advantages of the Compound Component Pattern
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Flexibility: Child components can be rearranged, omitted, or repeated in different orders.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reusability: Components can be reused in different contexts with varying content.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Separation of Concerns: State management and UI rendering are separated, making components easier to maintain and test.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example: Card Component&lt;/strong&gt;&lt;br&gt;
Let's build a card component using the Compound Component Pattern. The card will have an image, a title, and a description.&lt;br&gt;
There are two ways to achieve this pattern, I will share both ways. &lt;/p&gt;

&lt;h2&gt;
  
  
  Approach 1
&lt;/h2&gt;

&lt;p&gt;In this way, we will use normal functions to create compound components as &lt;strong&gt;Arrow functions&lt;/strong&gt; are not hoisted, so you cannot use them before initialization, that's why I am using regular functions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create a Card Component&lt;/strong&gt;&lt;br&gt;
Create a Card.jsx file. In this card component, we will create compound components.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import React from "react";


function Card({ children }) {
  return &amp;lt;div className="card"&amp;gt;{children}&amp;lt;/div&amp;gt;;
}

Card.Image = Image;
Card.Title = Title;
Card.Description = Description;

export default Card;

function Image({ src, alt }) {
  return &amp;lt;img className="card-image" src={src} alt={alt} /&amp;gt;;
}

function Title({ children }) {
  return &amp;lt;h2 className="card-title"&amp;gt;{children}&amp;lt;/h2&amp;gt;;
}

function Description({ children }) {
  return &amp;lt;p className="card-description"&amp;gt;{children}&amp;lt;/p&amp;gt;;
}


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Create a styles.css&lt;/strong&gt;&lt;br&gt;
Let's create a style file to write some basic styling. This is not a CSS tutorial so not going to put much effort into this part. Just some normal CSS.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

.app {
  text-align: center;
  display: flex;
  justify-content: center;
  padding-top: 20px;
  gap: 20px;
}
.card {
  border: 1px solid #ddd;
  border-radius: 4px;
  overflow: hidden;
  width: 300px;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.card-image {
  width: 100%;
  height: auto;
}

.card-title {
  font-size: 1.5rem;
  margin: 16px;
  color: Blue;
}

.card-description {
  font-size: 1rem;
  margin: 16px;
}



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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;How to use Compound Component&lt;/strong&gt;&lt;br&gt;
Now let's use these components inside our App.jsx. The styles file is the same as above.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import Card from "./Card";
import "./styles.css";

const App = () =&amp;gt; {
  return (
    &amp;lt;div className="app"&amp;gt;
      &amp;lt;Card&amp;gt;
        &amp;lt;Card.Image
          src="/reactjs.jpeg"
          alt="Placeholder Image"
        /&amp;gt;
        &amp;lt;Card.Title&amp;gt;I'm Azfar Aslam&amp;lt;/Card.Title&amp;gt;
        &amp;lt;Card.Description&amp;gt;
          This is a description for the first card. If you like this tutorial,
          please like, subscribe, and share.
        &amp;lt;/Card.Description&amp;gt;
      &amp;lt;/Card&amp;gt;
      &amp;lt;Card&amp;gt;
        &amp;lt;Card.Image
          src="/reactjs.jpeg"
          alt="Placeholder Image"
        /&amp;gt;
        &amp;lt;Card.Title&amp;gt;I'm Lead Web Developer&amp;lt;/Card.Title&amp;gt;
        &amp;lt;Card.Description&amp;gt;
          This is a description for the second card. If you like this tutorial,
          please like, subscribe, and share.
        &amp;lt;/Card.Description&amp;gt;
      &amp;lt;/Card&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default App;


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Final Result&lt;/strong&gt;&lt;br&gt;
This is how it will look like at the end. You can see how much control we have in this pattern and reusability.&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Approach 2
&lt;/h2&gt;

&lt;p&gt;In this way, we will create compound components using arrow functions. I am making it all inside one card component file but you can also create separate files.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create a Card Component&lt;/strong&gt;&lt;br&gt;
Create a Card.jsx file. In this card component, we will create compound components.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import React from "react";

const Card = ({ children }) =&amp;gt; {
  return &amp;lt;div className="card"&amp;gt;{children}&amp;lt;/div&amp;gt;;
};

export default Card;

export const CardImage = ({ src, alt }) =&amp;gt; {
  return &amp;lt;img className="card-image" src={src} alt={alt} /&amp;gt;;
};

export const CardTitle = ({ children }) =&amp;gt; {
  return &amp;lt;h2 className="card-title"&amp;gt;{children}&amp;lt;/h2&amp;gt;;
};

export const CardDescription = ({ children }) =&amp;gt; {
  return &amp;lt;p className="card-description"&amp;gt;{children}&amp;lt;/p&amp;gt;;
};



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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;How to use Compound Component&lt;/strong&gt;&lt;br&gt;
Now let's use these components inside our App.jsx. The styles file is the same as above.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import Card from "./Card";
import { CardDescription } from "./Card";
import { CardTitle } from "./Card";
import { CardImage } from "./Card";
import "./styles.css";

const App = () =&amp;gt; {
  return (
    &amp;lt;div className="app"&amp;gt;
      &amp;lt;Card&amp;gt;
        &amp;lt;CardImage
          src="/reactjs.jpeg"
          alt="Placeholder Image"
        /&amp;gt;
        &amp;lt;CardTitle&amp;gt;Hello World&amp;lt;/CardTitle&amp;gt;
        &amp;lt;CardDescription&amp;gt;
          This is a description for the first card. If you like this tutorial,
          please like, subscribe, and share.
        &amp;lt;/CardDescription&amp;gt;
      &amp;lt;/Card&amp;gt;
      &amp;lt;Card&amp;gt;
        &amp;lt;CardImage
          src="/reactjs.jpeg"
          alt="Placeholder Image"
        /&amp;gt;
        &amp;lt;CardTitle&amp;gt;This is Second Card&amp;lt;/CardTitle&amp;gt;
        &amp;lt;CardDescription&amp;gt;
          This is a description for the second card. If you like this tutorial,
          please like, subscribe, and share.
        &amp;lt;/CardDescription&amp;gt;
      &amp;lt;/Card&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default App;



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

&lt;/div&gt;

&lt;p&gt;The result will be the same.&lt;/p&gt;

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

&lt;p&gt;The Compound Component Pattern in React allows for building flexible, reusable components by separating state management from UI rendering. By using this pattern, you can create components that are easy to maintain and extend. The card component examples demonstrates how to implement this pattern effectively, providing a robust and scalable solution for complex UIs.&lt;/p&gt;

&lt;p&gt;With this pattern, you can create a wide range of components that can be easily customized and reused across your application, enhancing both the developer experience and the application's overall structure.&lt;/p&gt;

&lt;p&gt;I hope this will be helpful, love to connect with you on &lt;a href="https://www.linkedin.com/in/muhammad-azfar-aslam" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Few more articles&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/managing-global-state-with-usereducer-and-context-api-in-next-js-14-2m17"&gt;Managing Global State with useReducer and Context API in Next JS 14&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/highlight-on-the-new-features-of-next-js-14-config-2023-4lbe"&gt;Highlight on the new features of Next JS 14 config 2023&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/how-to-configure-react-js-app-on-wsl2-windows-10-3d1n"&gt;How to configure React JS app on WSL2 Windows 10&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/custom-tooltip-component-using-tailwind-and-react-js-186g"&gt;Custom 'Tooltip' component using Tailwind and React Js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/javascript-and-react-interview-questions-juniormid-level-2023-hd1"&gt;JavaScript and React Interview questions (Junior/Mid-level) 2023&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>designpatterns</category>
      <category>nextjs</category>
    </item>
    <item>
      <title>Managing Global State with useReducer and Context API in Next JS 14</title>
      <dc:creator>Muhammad Azfar Aslam</dc:creator>
      <pubDate>Wed, 03 Apr 2024 07:33:02 +0000</pubDate>
      <link>https://dev.to/muhammadazfaraslam/managing-global-state-with-usereducer-and-context-api-in-next-js-14-2m17</link>
      <guid>https://dev.to/muhammadazfaraslam/managing-global-state-with-usereducer-and-context-api-in-next-js-14-2m17</guid>
      <description>&lt;p&gt;Salut,&lt;br&gt;
I've been a big fan of Next JS since the beginning but since Next JS 13, many things changed compared to Next JS 12. One of the main differences is Redux and Global State. Managing a global state can be a challenging task, especially when the state needs to be shared across multiple components. One reason is that Redux is only available on the client side. The question is how can we manage the global state on the server side? I came up with the solution context API. However, if we have to manage complex logic, the combination of useReducer and the Context API provides an elegant solution to this problem. In this tutorial, we will create a simple counter application to demonstrate how to use useReducer and the Context API to manage the global state in React. Let's dive in to the example.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1: Setting Up the Context and Reducer
&lt;/h2&gt;

&lt;p&gt;First, let's create a new context for our counter application and define a reducer function that will handle state updates:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use client";
import React, { createContext, useContext, useReducer } from 'react';

// Create a new context for the counter
const CounterContext = createContext();

// Reducer function
const reducer = (state, action) =&amp;gt; {
  switch (action.type) {
    case 'increment':
      return { count: state.count + 1 };
    case 'decrement':
      return { count: state.count - 1 };
    default:
      throw new Error();
  }
};

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

&lt;/div&gt;



&lt;p&gt;In this code, we define a new context called CounterContext using React's createContext function. We also define a reducer function that takes the current state and an action, and returns the new state based on the action type.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Creating the Counter Provider
&lt;/h2&gt;

&lt;p&gt;Next, let's create a CounterProvider component that will use the useReducer hook to manage the state and provide the state and dispatch function to its children:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Counter provider component
const CounterProvider = ({ children }) =&amp;gt; {
  const [state, dispatch] = useReducer(reducer, { count: 0 });

  return (
    &amp;lt;CounterContext.Provider value={{ state, dispatch }}&amp;gt;
      {children}
    &amp;lt;/CounterContext.Provider&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;p&gt;In this code, we use the useReducer hook to create a state and dispatch function pair. We then use the CounterContext.Provider component to wrap the children components, providing them with the state and dispatch function via the context.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Consuming the Counter Context
&lt;/h2&gt;

&lt;p&gt;Now, let's create a custom hook called useCounter that will allow us to consume the counter context in our components:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Custom hook to consume the CounterContext
const useCounter = () =&amp;gt; {
  const context = useContext(CounterContext);
  if (!context) {
    throw new Error('useCounter must be used within a CounterProvider');
  }
  return context;
};

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

&lt;/div&gt;



&lt;p&gt;In this code, we use React's useContext hook to access the counter context. We also perform a check to ensure that the hook is used within a CounterProvider component, throwing an error if it is not.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Creating Components Using the Counter Context
&lt;/h2&gt;

&lt;p&gt;Finally, let's create two components, CounterDisplay and CounterControls, that will use the useCounter hook to interact with the counter state:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const CounterDisplay = () =&amp;gt; {
  const { state } = useCounter();

  return &amp;lt;div&amp;gt;Count: {state.count}&amp;lt;/div&amp;gt;;
};

const CounterControls = () =&amp;gt; {
  const { dispatch } = useCounter();

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; dispatch({ type: 'increment' })}&amp;gt;Increment&amp;lt;/button&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; dispatch({ type: 'decrement' })}&amp;gt;Decrement&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;p&gt;In these components, we use the useCounter hook to access the counter state and dispatch function. The CounterDisplay component displays the current count, while the CounterControls component provides buttons to increment and decrement the count.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Using the Counter Provider in the App
&lt;/h2&gt;

&lt;p&gt;Finally, let's use the CounterProvider component in our App component to wrap the CounterDisplay and CounterControls components:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const HomePageWrapper = () =&amp;gt; {
  return (
    &amp;lt;CounterProvider&amp;gt;
      &amp;lt;CounterDisplay /&amp;gt;
      &amp;lt;CounterControls /&amp;gt;
    &amp;lt;/CounterProvider&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;p&gt;In this code, we wrap the CounterDisplay and CounterControls components with the CounterProvider component to provide them with access to the counter state and dispatch function.&lt;/p&gt;

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

&lt;p&gt;In this tutorial, we have learned how to use useReducer and the Context API to manage the global state in a Next JS 14 application. By using these tools, we can create a centralized state management system that makes it easy to share state across multiple components.&lt;/p&gt;

&lt;p&gt;I hope this will be helpful, love to connect with you on &lt;a href="https://www.linkedin.com/in/muhammad-azfar-aslam" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Few more articles&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/react-design-patterns-compound-component-pattern-2p0a"&gt;React Design Patterns: Compound Component Pattern&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/highlight-on-the-new-features-of-next-js-14-config-2023-4lbe"&gt;Highlight on the new features of Next JS 14 config 2023&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/how-to-configure-react-js-app-on-wsl2-windows-10-3d1n"&gt;How to configure React JS app on WSL2 Windows 10&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/custom-tooltip-component-using-tailwind-and-react-js-186g"&gt;Custom 'Tooltip' component using Tailwind and React Js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/javascript-and-react-interview-questions-juniormid-level-2023-hd1"&gt;JavaScript and React Interview questions (Junior/Mid-level) 2023&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>nextjs</category>
      <category>react</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Highlight on the new features of Next JS 14 config 2023</title>
      <dc:creator>Muhammad Azfar Aslam</dc:creator>
      <pubDate>Fri, 27 Oct 2023 13:44:43 +0000</pubDate>
      <link>https://dev.to/muhammadazfaraslam/highlight-on-the-new-features-of-next-js-14-config-2023-4lbe</link>
      <guid>https://dev.to/muhammadazfaraslam/highlight-on-the-new-features-of-next-js-14-config-2023-4lbe</guid>
      <description>&lt;p&gt;Hi again and welcome to the new Next JS 14. Yes, you've read it correctly, Within 12 months, Next JS 14 is out. I've experienced attending config again and what a startling presentation by Guillermo Rauch, CEO of Vercel and creator of Next JS. No new API, we are following the same Next JS 13 APIs but with some excellent improvements. Some of the main topics are mentioned below.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Turbopack&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Server Actions (Stable)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Partial Prerendering (Preview)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next.js Learn (New)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Turbopack&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Guillermo Rauch asked many people should work on Performance or Feature and Performance wins. Now they think should we change our source language or what but they continue to same. Next JS 14 is still using Rust Engine. &lt;/p&gt;

&lt;p&gt;5,000 integration tests for the next dev are now passing with Turbopack, our underlying Rust engine. These tests include 7 years of bug fixes and reproductions.&lt;/p&gt;

&lt;p&gt;While testing on vercel.com, a large Next.js application, we've seen:&lt;/p&gt;

&lt;p&gt;Up to 53.3% faster local server startup&lt;br&gt;
Up to 94.7% faster code updates with Fast Refresh&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Server Actions (Stable)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Guillermo said, we were doing great in Next JS 13 but there was one piece missing and that was Server Actions. Now with Next JS 14, Server Actions are stable and we can call them from anywhere. No external API is required, you can fetch data directly from &lt;code&gt;sql&lt;/code&gt;.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

export default function Page() {
  async function create(formData: FormData) {
    'use server';
    const id = await createItem(formData);
  }

  return (
    &amp;lt;form action={create}&amp;gt;
      &amp;lt;input type="text" name="name" /&amp;gt;
      &amp;lt;button type="submit"&amp;gt;Submit&amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;
  );
}


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

&lt;/div&gt;

&lt;p&gt;Mutating data, re-rendering the page, or redirecting can happen in one network roundtrip, ensuring the correct data is displayed on the client, even if the upstream provider is slow. Further, you can compose and reuse different actions, including many different actions in the same route.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Partial Prerendering (Preview)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As a front-end developer, my favorite feature is this. Partial Prerendering. Sam Selikoff Founder, Build UI addressed at the conference that he was really impressed with React useSWR and he wanted to do something amazing inside Next JS and he did well. &lt;/p&gt;

&lt;p&gt;He said, according to him. React JS works like LEGOS and small LEGOS work together to form anything. Similarly, small components can work together like a charm and can produce some amazing work. Nike is also using Next JS.&lt;/p&gt;

&lt;p&gt;Partial Prerendering is defined by your Suspense boundaries. Here's how it works. Consider the following ecommerce page:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

export default function Page() {
  return (
    &amp;lt;main&amp;gt;
      &amp;lt;header&amp;gt;
        &amp;lt;h1&amp;gt;My Store&amp;lt;/h1&amp;gt;
        &amp;lt;Suspense fallback={&amp;lt;CartSkeleton /&amp;gt;}&amp;gt;
          &amp;lt;ShoppingCart /&amp;gt;
        &amp;lt;/Suspense&amp;gt;
      &amp;lt;/header&amp;gt;
      &amp;lt;Banner /&amp;gt;
      &amp;lt;Suspense fallback={&amp;lt;ProductListSkeleton /&amp;gt;}&amp;gt;
        &amp;lt;Recommendations /&amp;gt;
      &amp;lt;/Suspense&amp;gt;
      &amp;lt;NewProducts /&amp;gt;
    &amp;lt;/main&amp;gt;
  );
}


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Next.js Learn (New)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Mr. Guillermo also introduced a brand new, free course on Next.js Learn. This course teaches:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Next.js App Router&lt;/li&gt;
&lt;li&gt;Styling and Tailwind CSS&lt;/li&gt;
&lt;li&gt;Optimizing Fonts and Images&lt;/li&gt;
&lt;li&gt;Creating Layouts and Pages&lt;/li&gt;
&lt;li&gt;Navigating Between Pages&lt;/li&gt;
&lt;li&gt;Setting Up Your Postgres Database&lt;/li&gt;
&lt;li&gt;Fetching Data with Server Components&lt;/li&gt;
&lt;li&gt;Static and Dynamic Rendering&lt;/li&gt;
&lt;li&gt;Streaming&lt;/li&gt;
&lt;li&gt;Partial Prerendering (Optional)&lt;/li&gt;
&lt;li&gt;Adding Search and Pagination&lt;/li&gt;
&lt;li&gt;Mutating Data&lt;/li&gt;
&lt;li&gt;Handling Errors&lt;/li&gt;
&lt;li&gt;Improving Accessibility&lt;/li&gt;
&lt;li&gt;Adding Authentication&lt;/li&gt;
&lt;li&gt;Adding Metadata&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Houssein Djirdeh - Senior Software Engineer, at Google who is working under Aurora to develop third parties for Next JS announced some enhancements as well.&lt;/p&gt;

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

&lt;p&gt;Most developers like myself face a similar problem when they import 3rd parties and that is a performance issue in Google page speed. LCP increases that cost performance. He is trying to overcome this issue. Had a huge amount of success already but still working on it. &lt;/p&gt;

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

&lt;p&gt;With new third-party scripting, they have achieved 65x faster loading.&lt;/p&gt;

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

&lt;p&gt;Some example of these scripts from conference are below.&lt;/p&gt;

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

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

&lt;p&gt;All images are from the Next JS 14 conference and some text is taken from the official &lt;a href="https://nextjs.org/blog/next-14" rel="noopener noreferrer"&gt;blog&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;I hope this will be helpful, love to connect with you on &lt;a href="https://www.linkedin.com/in/muhammad-azfar-aslam" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Few more articles&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/highlight-on-the-new-features-of-next-js-13-config-2022-1a3i"&gt;Highlight on the new features of Next JS 13 config 2022&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/how-to-configure-react-js-app-on-wsl2-windows-10-3d1n"&gt;How to configure React JS app on WSL2 Windows 10&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/custom-tooltip-component-using-tailwind-and-react-js-186g"&gt;Custom 'Tooltip' component using Tailwind and React Js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/javascript-and-react-interview-questions-juniormid-level-2023-hd1"&gt;JavaScript and React Interview questions (Junior/Mid-level) 2023&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>nextjs</category>
      <category>react</category>
      <category>javascript</category>
      <category>community</category>
    </item>
    <item>
      <title>API Driven React-Hook Form (Dynamic Forms)</title>
      <dc:creator>Muhammad Azfar Aslam</dc:creator>
      <pubDate>Thu, 24 Aug 2023 10:04:45 +0000</pubDate>
      <link>https://dev.to/muhammadazfaraslam/api-driven-react-hook-form-dynamic-forms-3njb</link>
      <guid>https://dev.to/muhammadazfaraslam/api-driven-react-hook-form-dynamic-forms-3njb</guid>
      <description>&lt;p&gt;Salut,&lt;/p&gt;

&lt;h1&gt;
  
  
  Table of content
&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;Dynamic Form Data&lt;/li&gt;
&lt;li&gt;React Hook Form&lt;/li&gt;
&lt;li&gt;Text Input Field&lt;/li&gt;
&lt;li&gt;Text Area Field&lt;/li&gt;
&lt;li&gt;Radio Field&lt;/li&gt;
&lt;li&gt;Dropdown Field&lt;/li&gt;
&lt;li&gt;Checkbox Field&lt;/li&gt;
&lt;li&gt;Error Component&lt;/li&gt;
&lt;li&gt;Complete Input Component&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;API-driven forms refer to the practice of using APIs (Application Programming Interfaces) to integrate and manage forms within web applications. This approach offers several benefits that can enhance the functionality and user experience of forms on websites or applications. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dynamic Data Loading&lt;/li&gt;
&lt;li&gt;Real-time Validation&lt;/li&gt;
&lt;li&gt;Flexibility and Customization&lt;/li&gt;
&lt;li&gt;Secure Data Handling&lt;/li&gt;
&lt;li&gt;Seamless Integration with Backends&lt;/li&gt;
&lt;li&gt;Consistency Across Platforms&lt;/li&gt;
&lt;li&gt;Reduced Development Time&lt;/li&gt;
&lt;li&gt;Scalability&lt;/li&gt;
&lt;li&gt;Easier Updates and Maintenance&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Prerequisite - React Hook Form. As this article is related to API-driven forms, that's why I'll now elaborate on the working of React Hook Form. However, if you need an understanding of this library, just leave a comment and I'll explain it in another article.&lt;/p&gt;

&lt;h3&gt;
  
  
  Dynamic Form Data
&lt;/h3&gt;

&lt;p&gt;When we call an API for form fields, it should have the following payload. I am going to write my code accordingly to this payload if you guys want a different payload. You will be required to make changes in the code accordingly. I am not calling any API in this article, just creating a variable "dynamicForm" and assigning payload to it.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const dynamicForm = {
  firstName: {
    label: "First Name",
    type: "text",
    placeholder: "",
    defaultValue: "Yes",
    rules: {
      required: true,
    },
  },
  lastName: {
    label: "Last Name",
    type: "text",
    placeholder: "",
    defaultValue: "",
    rules: {
      required: true,
    },
  },
  email: {
    label: "Email",
    type: "email",
    placeholder: "",
    defaultValue: "",
    rules: {
      required: true,
    },
  },
  subject: {
    label: "Subject",
    type: "dropdown",
    options: ["Chemistry", "Physics", "Arts"],
    defaultValue: "",
    rules: {
      required: true,
    },
  },
  message: {
    label: "Message",
    type: "textarea",
    placeholder: "",
    defaultValue: "",
    rules: {
      required: false,
    },
  },
}


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  React Hook Form
&lt;/h3&gt;

&lt;p&gt;I will make a component named "Input" but for now let's suppose there is a component. Now, let's call the form and this Input component.&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const {
    handleSubmit,
    control,
    formState: { errors },
  } = useForm();


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

&lt;/div&gt;

&lt;p&gt;Let's convert dynamicForm object to array and map through it the Input component.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const formInputs = Object.keys(dynamicForm).map((e, i) =&amp;gt; {
    const { rules, defaultValue, label } = dynamicForm[e];

    return (
      &amp;lt;section key={i}&amp;gt;
        &amp;lt;label className="grey"&amp;gt;
          {label} {rules?.required ? &amp;lt;span className="red"&amp;gt;*&amp;lt;/span&amp;gt; : ""}
        &amp;lt;/label&amp;gt;
        &amp;lt;Controller
          name={e}
          control={control}
          rules={rules}
          defaultValue={defaultValue}
          render={({ field }) =&amp;gt; (
            &amp;lt;div&amp;gt;
              &amp;lt;Input
                cClass="input-1"
                value={field.value}
                onChange={field.onChange}
                {...dynamicForm[e]}
              /&amp;gt;
            &amp;lt;/div&amp;gt;
          )}
        /&amp;gt;
        {errors[e] &amp;amp;&amp;amp; &amp;lt;Error&amp;gt;This field is required&amp;lt;/Error&amp;gt;}
      &amp;lt;/section&amp;gt;
    );
  });


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

&lt;/div&gt;

&lt;p&gt;Now, add a submit handler and form to our main component.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const onSubmit = (data) =&amp;gt; console.log(data);

  return (
    &amp;lt;div className="wrapper"&amp;gt;
      &amp;lt;form onSubmit={handleSubmit(onSubmit)}&amp;gt;
        {formInputs}
        &amp;lt;div&amp;gt;
          &amp;lt;button type="submit" className="btn-1"&amp;gt;
            Submit
          &amp;lt;/button&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/form&amp;gt;
    &amp;lt;/div&amp;gt;
  );


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  Text Input Field
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const Input = ({ cClass, value, onChange, type, ...rest }) =&amp;gt; {
 return (
                &amp;lt;input
                    type='text'
                    placeholder={rest?.placeholder}
                    onChange={(e) =&amp;gt; onChange(e.target.value)}
                    value={value}
                    className={cClass}
                /&amp;gt;
            );
}


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  Text Area Field
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const Input = ({ cClass, value, onChange, type, ...rest }) =&amp;gt; {
 return (
                &amp;lt;textarea name="" id="" cols="30" rows="10" className={cClass} onChange={(e) =&amp;gt; onChange(e.target.value)}&amp;gt;{value}&amp;lt;/textarea&amp;gt;
            );
}


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  Radio Field
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const Input = ({ cClass, value, onChange, type, ...rest }) =&amp;gt; {
 return rest?.options.map((i) =&amp;gt; (
                &amp;lt;label&amp;gt;
                    &amp;lt;input
                        type='radio'
                        key={i}
                        value={i}
                        onChange={(e) =&amp;gt; onChange(e.target.value)}
                        checked={value === i}
                    /&amp;gt;
                    {i}
                &amp;lt;/label&amp;gt;
            ));
}


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  Dropdown Field
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const Input = ({ cClass, value, onChange, type, ...rest }) =&amp;gt; {
 return (
                &amp;lt;select value={value} onChange={(e) =&amp;gt; onChange(e.target.value)} className={cClass}&amp;gt;
                    &amp;lt;option value=""&amp;gt;Select an option&amp;lt;/option&amp;gt;
                    {rest?.options.map((option) =&amp;gt; (
                        &amp;lt;option key={option} value={option}&amp;gt;
                            {option}
                        &amp;lt;/option&amp;gt;
                    ))}
                &amp;lt;/select&amp;gt;
            );
}


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  CheckBox Field
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const Input = ({ cClass, value, onChange, type, ...rest }) =&amp;gt; {
 return (
               &amp;lt;label&amp;gt;
                    &amp;lt;input
                        type="checkbox"
                        onChange={(e) =&amp;gt; onChange(e.target.checked)}
                        checked={value}
                    /&amp;gt;
                    {rest?.checkboxLabel}
                &amp;lt;/label&amp;gt;
            );
}


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

&lt;/div&gt;

&lt;p&gt;I used a switch statement to check the type.&lt;/p&gt;

&lt;h3&gt;
  
  
  Error Component
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

export const Error = ({ children }) =&amp;gt; &amp;lt;p style={{ color: "red" }}&amp;gt;{children}&amp;lt;/p&amp;gt;;


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

&lt;/div&gt;
&lt;h3&gt;
  
  
  Complete Input Component
&lt;/h3&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

const Input = ({ cClass, value, onChange, type, ...rest }) =&amp;gt; {
    switch (type) {
        case "text":
            return (
                &amp;lt;input
                    type='text'
                    placeholder={rest?.placeholder}
                    onChange={(e) =&amp;gt; onChange(e.target.value)}
                    value={value}
                    className={cClass}
                /&amp;gt;
            );
        case "email":
            return (
                &amp;lt;input
                    type='email'
                    placeholder={rest?.placeholder}
                    onChange={(e) =&amp;gt; onChange(e.target.value)}
                    value={value}
                    className={cClass}
                /&amp;gt;
            );
        case "textarea":
            return (
                &amp;lt;textarea name="" id="" cols="30" rows="10" className={cClass} onChange={(e) =&amp;gt; onChange(e.target.value)}&amp;gt;{value}&amp;lt;/textarea&amp;gt;
            );
        case "radio":
            return rest?.options.map((i) =&amp;gt; (
                &amp;lt;label&amp;gt;
                    &amp;lt;input
                        type='radio'
                        key={i}
                        value={i}
                        onChange={(e) =&amp;gt; onChange(e.target.value)}
                        checked={value === i}
                    /&amp;gt;
                    {i}
                &amp;lt;/label&amp;gt;
            ));
        case "dropdown":
            return (
                &amp;lt;select value={value} onChange={(e) =&amp;gt; onChange(e.target.value)} className={cClass}&amp;gt;
                    &amp;lt;option value=""&amp;gt;Select an option&amp;lt;/option&amp;gt;
                    {rest?.options.map((option) =&amp;gt; (
                        &amp;lt;option key={option} value={option}&amp;gt;
                            {option}
                        &amp;lt;/option&amp;gt;
                    ))}
                &amp;lt;/select&amp;gt;
            );

        case "checkbox":
            return (
                &amp;lt;label&amp;gt;
                    &amp;lt;input
                        type="checkbox"
                        onChange={(e) =&amp;gt; onChange(e.target.checked)}
                        checked={value}
                    /&amp;gt;
                    {rest?.checkboxLabel}
                &amp;lt;/label&amp;gt;
            );
        default:
            return null;
    }
};

export default Input


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

&lt;/div&gt;

&lt;p&gt;Frontend would render like this.&lt;/p&gt;

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

&lt;p&gt;Thank you for reading this far. This is a brief introduction of &lt;strong&gt;API Driven forms&lt;/strong&gt;&lt;br&gt;
If you find this article useful, please like ❤ and share this article. Someone could find it useful too. If you find anything technically inaccurate please feel free to leave a comment.&lt;br&gt;
Hope it's a nice and informative read for you. Follow me on &lt;a href="https://www.linkedin.com/in/muhammad-azfar-aslam" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; for more helpful resources or reach out for any mutual opportunity.&lt;/p&gt;

&lt;p&gt;Few more articles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/highlight-on-the-new-features-of-next-js-13-config-2022-1a3i"&gt;Highlight on the new features of Next JS 13 config 2022&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/how-to-configure-react-js-app-on-wsl2-windows-10-3d1n"&gt;How to configure React JS app on WSL2 Windows 10&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/custom-tooltip-component-using-tailwind-and-react-js-186g"&gt;Custom 'Tooltip' component using Tailwind and React Js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/javascript-and-react-interview-questions-juniormid-level-2023-hd1"&gt;JavaScript and React Interview questions (Junior/Mid-level) 2023&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>api</category>
      <category>javascript</category>
      <category>frontend</category>
    </item>
    <item>
      <title>JavaScript and React Interview questions (Junior/Mid-level) 2023</title>
      <dc:creator>Muhammad Azfar Aslam</dc:creator>
      <pubDate>Mon, 10 Jul 2023 05:40:16 +0000</pubDate>
      <link>https://dev.to/muhammadazfaraslam/javascript-and-react-interview-questions-juniormid-level-2023-hd1</link>
      <guid>https://dev.to/muhammadazfaraslam/javascript-and-react-interview-questions-juniormid-level-2023-hd1</guid>
      <description>&lt;p&gt;Hi, I am working as Frontend/JavaScript developer for the past 5+ years. I've taken multiple interviews. I want to share some questions I used to ask from candidates. Hope it'll be helpful for you guys. Let's dive into it.&lt;/p&gt;

&lt;h2&gt;
  
  
  JavaScript Questions:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;What is an Event loop?&lt;/li&gt;
&lt;li&gt;What are the various data types that exist in JavaScript?&lt;/li&gt;
&lt;li&gt;Difference between Primitive and non-primitive?&lt;/li&gt;
&lt;li&gt;What are the scopes of a variable in JavaScript?&lt;/li&gt;
&lt;li&gt;What is Hoisting in JS?&lt;/li&gt;
&lt;li&gt;What is the ‘this’ keyword in JavaScript?&lt;/li&gt;
&lt;li&gt;What is ES6/ES7?&lt;/li&gt;
&lt;li&gt;What is Callback in JavaScript?&lt;/li&gt;
&lt;li&gt;What is the difference between var, let, and const?&lt;/li&gt;
&lt;li&gt;What is the difference between splice and slice?&lt;/li&gt;
&lt;li&gt;What is the difference between a map and foreach?&lt;/li&gt;
&lt;li&gt;What is the difference between an arrow function and a normal function?&lt;/li&gt;
&lt;li&gt;What is a generator function?&lt;/li&gt;
&lt;li&gt;What is the difference between cookies, sessions, and local storage?&lt;/li&gt;
&lt;li&gt;What are Closures in JavaScript?&lt;/li&gt;
&lt;li&gt;What is the difference between Document and Window in JavaScript?&lt;/li&gt;
&lt;li&gt;What is the difference between Undefined and Undeclared in JavaScript?&lt;/li&gt;
&lt;li&gt;What is the difference between Call and Apply?&lt;/li&gt;
&lt;li&gt;Difference between “ == “ and “ === “ operators?&lt;/li&gt;
&lt;li&gt;What is NaN property in JavaScript?&lt;/li&gt;
&lt;li&gt;What is the difference between Passed by value and passed by reference?&lt;/li&gt;
&lt;li&gt;What is an Immediately Invoked Function in JavaScript?&lt;/li&gt;
&lt;li&gt;What are Higher Order Functions?&lt;/li&gt;
&lt;li&gt;What is currying in JavaScript?&lt;/li&gt;
&lt;li&gt;How many Types of errors are in JavaScript?&lt;/li&gt;
&lt;li&gt;What is BOM?&lt;/li&gt;
&lt;li&gt;Difference between client-side and server-side?&lt;/li&gt;
&lt;li&gt;What is a spread operator?&lt;/li&gt;
&lt;li&gt;What are promises in JS?&lt;/li&gt;
&lt;li&gt;What is Object Destructuring?&lt;/li&gt;
&lt;li&gt;Difference between Async and Promise?&lt;/li&gt;
&lt;li&gt;What is the role of deferred scripts?&lt;/li&gt;
&lt;li&gt;What is the difference between Event Capturing and Event Bubbling?&lt;/li&gt;
&lt;li&gt;What is the Strict mode in JavaScript?&lt;/li&gt;
&lt;li&gt;What is the difference between filter and find?&lt;/li&gt;
&lt;li&gt;Is JavaScript Case-Sensitive?&lt;/li&gt;
&lt;li&gt;How can you convert an object to an array?&lt;/li&gt;
&lt;li&gt;What Is Garbage Collection in JavaScript?&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  React Js:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Differentiate between Real DOM and Virtual DOM.&lt;/li&gt;
&lt;li&gt;What is the significance of keys in React?&lt;/li&gt;
&lt;li&gt;What is the purpose of render() in React?&lt;/li&gt;
&lt;li&gt;What are Props?&lt;/li&gt;
&lt;li&gt;What is a state in React?&lt;/li&gt;
&lt;li&gt;Differentiate between stateful and stateless components.&lt;/li&gt;
&lt;li&gt;What are lifecycle methods in React?&lt;/li&gt;
&lt;li&gt;What is the difference between class and functional components?&lt;/li&gt;
&lt;li&gt;What is an event in React?&lt;/li&gt;
&lt;li&gt;What are Refs in React?&lt;/li&gt;
&lt;li&gt;Explain useEffect in detail?&lt;/li&gt;
&lt;li&gt;What are Higher Order Components(HOC)?&lt;/li&gt;
&lt;li&gt;What are Pure Components?&lt;/li&gt;
&lt;li&gt;What is the significance of keys in React?&lt;/li&gt;
&lt;li&gt;What is JSX? &lt;/li&gt;
&lt;li&gt;What is Redux?&lt;/li&gt;
&lt;li&gt;What are the principles of Redux?&lt;/li&gt;
&lt;li&gt;How can you access value from Redux?&lt;/li&gt;
&lt;li&gt;What is the difference between controlled and uncontrolled components?&lt;/li&gt;
&lt;li&gt;What is the difference between useMemo and useCallback?&lt;/li&gt;
&lt;li&gt;What is the difference between useEffect and useLayoutEffect?&lt;/li&gt;
&lt;li&gt;What is SPA?&lt;/li&gt;
&lt;li&gt;What are custom hooks?&lt;/li&gt;
&lt;li&gt;When to use util or custom hook?&lt;/li&gt;
&lt;li&gt;How do you handle optimization in a large React application?&lt;/li&gt;
&lt;li&gt;What is Context API?&lt;/li&gt;
&lt;li&gt;Explain the concept of a Portal in React?&lt;/li&gt;
&lt;li&gt;How do you handle asynchronous data loading in a React application?&lt;/li&gt;
&lt;li&gt;How do you handle localization in a React application?&lt;/li&gt;
&lt;li&gt;What is the difference between static and dynamic components in React?&lt;/li&gt;
&lt;li&gt;How do you handle server-side rendering in a React application?&lt;/li&gt;
&lt;li&gt;What is PropTypes?&lt;/li&gt;
&lt;li&gt;Explain the concept of Memoization in React?&lt;/li&gt;
&lt;li&gt;Does React have one or two-way binding?&lt;/li&gt;
&lt;li&gt;How do you send data from the child to the parent component?&lt;/li&gt;
&lt;li&gt;Does useEffect triggers when we change by reference?&lt;/li&gt;
&lt;li&gt;How to convert functional components to pure components?&lt;/li&gt;
&lt;li&gt;What is Axios interceptor?&lt;/li&gt;
&lt;li&gt;How to validate forms in React?&lt;/li&gt;
&lt;li&gt;What is unit testing?&lt;/li&gt;
&lt;li&gt;What is JWT?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If you find this standalone react app (microservice) helpful then please like ❤ and share it with your friends, follow me on &lt;a href="https://www.linkedin.com/in/muhammad-azfar-aslam" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; for more helpful resources.&lt;/p&gt;




&lt;h2&gt;
  
  
  Other links:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/highlight-on-the-new-features-of-next-js-13-config-2022-1a3i"&gt;Highlight on the new features of Next JS 13 config 2022&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/how-to-configure-react-js-app-on-wsl2-windows-10-3d1n"&gt;How to configure React JS app on WSL2 Windows 10&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/custom-tooltip-component-using-tailwind-and-react-js-186g"&gt;Custom 'Tooltip' component using Tailwind and React Js&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>career</category>
      <category>learning</category>
    </item>
    <item>
      <title>How to create React Micro Frontend/Microservice (example) cloning NY Times sidebar widget</title>
      <dc:creator>Muhammad Azfar Aslam</dc:creator>
      <pubDate>Wed, 28 Dec 2022 12:07:37 +0000</pubDate>
      <link>https://dev.to/muhammadazfaraslam/react-microservice-cloning-ny-times-sidebar-widget-ldg</link>
      <guid>https://dev.to/muhammadazfaraslam/react-microservice-cloning-ny-times-sidebar-widget-ldg</guid>
      <description>&lt;p&gt;Bonjour,&lt;br&gt;
Today, I will try to demonstrate a concept of microservice in react js. We all know that Cloud Microservice Architecture is the favorite architecture of many developers these days. One of the popular examples in production with monthly traffic of 387.17M (Oct, 22) is &lt;strong&gt;"Netflix"&lt;/strong&gt;. My example is just a small widget, nothing compared to Netflix of course.&lt;/p&gt;

&lt;p&gt;I am going to clone a sidebar widget of &lt;strong&gt;NY times&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Steps 1&lt;/strong&gt;&lt;br&gt;
For this just create a new react app using this command&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx create-react-app ny-times-microservice-widget-clone&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now, download some packages&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm i axios&lt;/code&gt;&lt;br&gt;
&lt;code&gt;npm i parcel&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Then add the following code in the package.json file.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;"build:widget": "parcel build src/index.js --no-source-maps --dist-dir widget",&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now let's start some coding :)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Steps 2&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a folder &lt;strong&gt;components&lt;/strong&gt; inside the src folder.&lt;/li&gt;
&lt;li&gt;Create a new file inside named &lt;em&gt;PostsWidget.jsx&lt;/em&gt; &lt;/li&gt;
&lt;li&gt;Write the following lines of code.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const PostsWidget = () =&amp;gt; {
  return (
    &amp;lt;section&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;h3&amp;gt;Tags&amp;lt;/h3&amp;gt;
        &amp;lt;h3&amp;gt;This is a title&amp;lt;/h3&amp;gt;
        &amp;lt;p&amp;gt;1 Reactions&amp;lt;/p&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/section&amp;gt;
  );
};

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

&lt;/div&gt;


&lt;p&gt;Here we just created a component that will render two headings and one paragraph at the front-end. Let's add some styling (Note: all styling is copied from NY Times).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a new file inside &lt;strong&gt;components&lt;/strong&gt; folder named &lt;em&gt;PostsWidget.module.css&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.storyWrapper{
 border-bottom: 1px solid #dfdfdf;
 padding: 16px 0px
}

.subHeading{
    color: #727272;
    font-size: 0.6875rem;
    font-weight: 700;
    text-transform: uppercase;
    line-height: 1.35em !important;
    letter-spacing: 1px !important;
    margin-bottom: 0.25rem;
}

.mainHeadind{
    color: #121212;
    font-size: 1.375rem;
    line-height: 1.2em;
    letter-spacing: 0.01em;
    font-weight: 700;
    -webkit-font-smoothing: antialiased;
    margin: 0;
}

.reactions{
    color:  #727272;
    font-size: 0.625rem;
    line-height: 1.25em;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin: 0;
    margin-top: 0.25rem;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import styles from "./PostsWidget.module.css";
...
&amp;lt;h3 className={styles.subHeading}&amp;gt;Tags&amp;lt;/h3&amp;gt;
&amp;lt;h3 className={styles.mainHeadind}&amp;gt;This is a title&amp;lt;/h3&amp;gt;
&amp;lt;p className={styles.reactions}&amp;gt;1 Reactions&amp;lt;/p&amp;gt;
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Steps 3&lt;/strong&gt;&lt;br&gt;
API integration, I am using dummyjson.com for dummy data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [articles, setArticles] = useState([]);
...
useEffect(() =&amp;gt; {
    axios
      .get(`https://dummyjson.com/posts?skip=0&amp;amp;limit=5`)
      .then(function (response) {
        console.log("response", response?.data);
        setArticles(response.data);
      })
      .catch(function (error) {
        setError("error");
      });
  }, [limit, skip]);
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 4&lt;/strong&gt;&lt;br&gt;
A div with data attributes to pass props and render this widget. &lt;br&gt;
&lt;code&gt;&amp;lt;div class="post-widget" data-skip="0" data-limit="5"&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 5&lt;/strong&gt;&lt;br&gt;
Targeting this div and passing props to our component. Go to src/index.js. Now, we'll use a JavaScript selector (querySelectorAll) to target the div. Then we will loop through it so we can render this widget as many times as we want on the same page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
import PostsWidget from './components/PostsWidget.jsx';

const widgets = document.querySelectorAll('.post-widget')

widgets.forEach(widget =&amp;gt; {
    ReactDOM.render(
        &amp;lt;React.StrictMode&amp;gt;
            &amp;lt;PostsWidget widget={widget} /&amp;gt;
        &amp;lt;/React.StrictMode&amp;gt;,
        widget
    );
})
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, get this prop inside component and passing it to API endpoint.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
const PostsWidget = ({ widget }) =&amp;gt; {
  const skip = widget.getAttribute("data-skip") || 0;
  const limit = parseInt(widget.getAttribute("data-limit") ?? 5);
...
  const [error, setError] = useState(false);

  useEffect(() =&amp;gt; {
    axios
      .get(`https://dummyjson.com/posts?skip=${skip}&amp;amp;limit=${limit}`)
      .then(function (response) {
        console.log("response", response?.data);
        setArticles(response.data);
      })
      .catch(function (error) {
        setError("error");
      });
  }, [limit, skip]);

  if (error) {
    return &amp;lt;div&amp;gt;{error}&amp;lt;/div&amp;gt;;
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now map all the articles&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
{articles?.posts?.map((article) =&amp;gt; {
        return (
          &amp;lt;div className={styles.storyWrapper} key={article.id}&amp;gt;
            &amp;lt;h3 className={styles.subHeading}&amp;gt;{article?.tags?.toString()}&amp;lt;/h3&amp;gt;
            &amp;lt;h3 className={styles.mainHeadind}&amp;gt;
            {article?.title}
            &amp;lt;/h3&amp;gt;
            &amp;lt;p className={styles.reactions}&amp;gt;{article?.reactions} Reactions&amp;lt;/p&amp;gt;
          &amp;lt;/div&amp;gt;
        );
})}
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step 6&lt;/strong&gt;&lt;br&gt;
Build, a normal react build will create multiple static files but we need a single file for JavaScript and CSS to target this widget. For this purpose, we install &lt;strong&gt;Parcel&lt;/strong&gt; at the start. Let's create a build using this package.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;yarn build:widget&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 7&lt;/strong&gt;&lt;br&gt;
Host your widget somewhere. For learning purposes, I've served this build locally and used it inside an HTML file to show you guys.&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;link rel="stylesheet" href="http://192.100.00.00:3000/index.css"&amp;gt;
....
&amp;lt;body&amp;gt;
  &amp;lt;div class="post-widget" data-skip="0" data-limit="5"&amp;gt;&amp;lt;/div&amp;gt;
  &amp;lt;script src="http://192.100.00.00:3000/index.js"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can find the complete code &lt;a href="https://github.com/MuhammadAzfarAslam/ny-times-microservice-widget-clone" rel="noopener noreferrer"&gt;here&lt;/a&gt;. My vscode directory before the build.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fojpo1n89sginpnnbhzlc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fojpo1n89sginpnnbhzlc.png" alt="Image description" width="231" height="305"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;My vscode directory after the build.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnf4amc57jeslse1sktnu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnf4amc57jeslse1sktnu.png" alt="Image description" width="220" height="393"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;NY times widget for reference&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fggsx1gzvizmrl17ipcfk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fggsx1gzvizmrl17ipcfk.png" alt="Image description" width="800" height="365"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is how &lt;em&gt;react widget&lt;/em&gt; will look.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz71kc4uo2x4nzxl3t4a1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz71kc4uo2x4nzxl3t4a1.png" alt="Image description" width="800" height="370"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What if we need only the JS link and HTML div, no CSS link&lt;/strong&gt;&lt;br&gt;
Yes, we can do it. just need to add another hook. Go to your PostWidget.js file and write following code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;useEffect(() =&amp;gt; {
    const fetchCSS = async () =&amp;gt; {
      try {
        const response = await axios.get('http://192.100.00.00:3000/index.css');
        const style = document.createElement('style');
        style.textContent = response.data;
        document.head.appendChild(style);
      } catch (error) {
        console.error(error);
      }
    };
    fetchCSS();
  }, []);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This hook will add your CSS code in the head direct. This is one way of doing it, not sure which one is better. Let me know your opinion in the comments.&lt;/p&gt;

&lt;p&gt;If you find this standalone react app (microservice) helpful then please like ❤ and share it with your friends, follow me on &lt;a href="https://www.linkedin.com/in/muhammad-azfar-aslam" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; for more helpful resources.&lt;/p&gt;




&lt;h2&gt;
  
  
  Other links:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/highlight-on-the-new-features-of-next-js-13-config-2022-1a3i"&gt;Highlight on the new features of Next JS 13 config 2022&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/how-to-configure-react-js-app-on-wsl2-windows-10-3d1n"&gt;How to configure React JS app on WSL2 Windows 10&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/custom-tooltip-component-using-tailwind-and-react-js-186g"&gt;Custom 'Tooltip' component using Tailwind and React Js&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>microservices</category>
      <category>javascript</category>
      <category>learning</category>
      <category>react</category>
    </item>
    <item>
      <title>How to create an equal border with a display grid - Hack (HTML5 and CSS3)</title>
      <dc:creator>Muhammad Azfar Aslam</dc:creator>
      <pubDate>Thu, 22 Dec 2022 13:28:35 +0000</pubDate>
      <link>https://dev.to/muhammadazfaraslam/how-to-create-an-equal-border-with-a-display-grid-hack-html5-an-css3-421b</link>
      <guid>https://dev.to/muhammadazfaraslam/how-to-create-an-equal-border-with-a-display-grid-hack-html5-an-css3-421b</guid>
      <description>&lt;p&gt;We have different types of displays in CSS, the most famous are as follows&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Block&lt;/li&gt;
&lt;li&gt;Flex&lt;/li&gt;
&lt;li&gt;Grid&lt;/li&gt;
&lt;li&gt;Table etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Today, I want to discuss &lt;strong&gt;Grid&lt;/strong&gt;. We can fully control grid rows and columns. Grid is one of the most used CSS properties to create a Masonry gallery. Recently I was creating a table dynamically whose columns are fixed but the number of rows increases based on the number of items. Therefore, a normal table is not possible for this case scenario. Grid was the solution, I can create table alike layout and generates a dynamically exact number of columns and rows as well. The only problem left was the border. If I use &lt;em&gt;border&lt;/em&gt; property of CSS then it will cause a double border between and one single border of the box. &lt;/p&gt;

&lt;p&gt;I was using tailwind. A sample code and UI are something 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;&amp;lt;div class="grid grid-cols-4"&amp;gt;
   &amp;lt;div class="border"&amp;gt;
      &amp;lt;h3 class="text-center py-6"&amp;gt;1&amp;lt;/h3&amp;gt;
   &amp;lt;/div&amp;gt;
   .....
   .....
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F70iul2t1pxu9mmywe04i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F70iul2t1pxu9mmywe04i.png" alt="Image description" width="777" height="263"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you guys can see the problem. I searched but no solution was available on the internet. Most of the solutions were about nth-child() but I didn't have a fixed number of items so nth-child() was not for me. I came up with a solution I wanted to share with you guys, I hope maybe it can help anyone. I used a &lt;strong&gt;gap&lt;/strong&gt; and &lt;strong&gt;background&lt;/strong&gt; for the border. So, this is how my code and UI look after this idea.&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;div
  class="grid grid-cols-4 bg-black border border-black"
  style="gap: 1px"&amp;gt;
    &amp;lt;div class="bg-white"&amp;gt;
       &amp;lt;h3 class="text-center py-6"&amp;gt;1&amp;lt;/h3&amp;gt;
    &amp;lt;/div&amp;gt;
    ....
    ....
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn7c9mcol0jn54hmqo48f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn7c9mcol0jn54hmqo48f.png" alt="Image description" width="769" height="254"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thank you for your time. &lt;/p&gt;




&lt;h2&gt;
  
  
  Other links:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/highlight-on-the-new-features-of-next-js-13-config-2022-1a3i"&gt;Highlight on the new features of Next JS 13 config 2022&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/how-to-configure-react-js-app-on-wsl2-windows-10-3d1n"&gt;How to configure React JS app on WSL2 Windows 10&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/custom-tooltip-component-using-tailwind-and-react-js-186g"&gt;Custom 'Tooltip' component using Tailwind and React Js&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>html</category>
      <category>css</category>
      <category>codenewbie</category>
      <category>design</category>
    </item>
    <item>
      <title>Highlight on the new features of Next JS 13 config 2022</title>
      <dc:creator>Muhammad Azfar Aslam</dc:creator>
      <pubDate>Tue, 01 Nov 2022 05:32:51 +0000</pubDate>
      <link>https://dev.to/muhammadazfaraslam/highlight-on-the-new-features-of-next-js-13-config-2022-1a3i</link>
      <guid>https://dev.to/muhammadazfaraslam/highlight-on-the-new-features-of-next-js-13-config-2022-1a3i</guid>
      <description>&lt;p&gt;Welcome to the new era of Next JS 13. I've experienced attending config22 and what a startling presentation by Guillermo Rauch, CEO of Vercel. I believe it is bringing some exceptional new features, and all would love to work with them. Some of the main topics are mentioned below.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/highlight-on-the-new-features-of-next-js-13-config-2022-1a3i#turbo-pack"&gt;Turbopack.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/highlight-on-the-new-features-of-next-js-13-config-2022-1a3i#new-next-js-router"&gt;New Next JS router.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/highlight-on-the-new-features-of-next-js-13-config-2022-1a3i#improved-nextjs-image-and-font-component"&gt;Improved Next JS Image and Font component.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/highlight-on-the-new-features-of-next-js-13-config-2022-1a3i#open-graph-images"&gt;Open Graph Images.&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Turbopack
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fywzxmunvdd17rekp2050.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fywzxmunvdd17rekp2050.png" alt="Turbopack next 13" width="800" height="434"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next JS 13 is introducing &lt;strong&gt;Turbopack&lt;/strong&gt; which is the fastest compiler infrastructure for JS and Typescript projects. We are moving to a world where running your app locally and making an incremental change can happen in as little as 10 milliseconds. Building for production will happen in single-digit seconds, even for large code bases. Turbopack is 10x faster updates than Vite, 4x faster cold starts than Webpack, and 700x faster updates than Webpack. Here are some visual comparisons according to the Next JS team.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk27f1oe3yh8xdmm3pk2a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fk27f1oe3yh8xdmm3pk2a.png" alt="3000 turbo comparison" width="800" height="569"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F03dmqumkcszj4n5dvx5k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F03dmqumkcszj4n5dvx5k.png" alt="5000 turbo comparison" width="800" height="582"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzwanbdhenu4igcbi8fyy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzwanbdhenu4igcbi8fyy.png" alt="1000 turbo comparison" width="800" height="386"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  New Next JS router
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8o0lasgxw2pri5ykw608.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F8o0lasgxw2pri5ykw608.png" alt="Next 13 router cover" width="800" height="458"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next JS has introduced &lt;strong&gt;Layouts&lt;/strong&gt; in the router. Previously we create a component and use it as a layout. We can either add it inside _app.js or with the help of middleware. But the new router-optimized layout issue means that all the benefits of ISR,  static data fetching, service side data fetching, and even SWR are now all in one hybrid solution. Thanks to the new React primitives, we're enabling ergonomic ways to handle loading and error states, streaming UI as it's rendered, and in the future, even mutate data. Here is a visual of the file and folder structure for layout.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5giyvtig597z5ixf8e2r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5giyvtig597z5ixf8e2r.png" alt="folder structure" width="263" height="370"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Improved Next JS Image and Font component
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl8rxnll0ajgea9zzmgv3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fl8rxnll0ajgea9zzmgv3.png" alt="Toolkit Next js cover" width="800" height="436"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Improved image component that performs better and maintains its familiar interface. Next JS team has also reimagined how developers use fonts with a brand-new font system developed in collaboration with the chrome team. &lt;/p&gt;

&lt;p&gt;This built-in module, not only optimizes your fonts but also removes any external request for improved privacy and performance by eliminating connection setup times to third-party hosts. The new font module can automatically avoid 99% of layout shifts caused by custom fonts and 100% of visual disruption from missing fonts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Open Graph Images
&lt;/h2&gt;

&lt;p&gt;We all know how much social sharing is important these days. This is also an important part of Social media optimization (SMO). According to a study, Facebook has the highest conversion rate, on the second it's Instagram, and then Twitter, LinkedIn, YouTube, etc. &lt;/p&gt;

&lt;p&gt;Next 13, announcing Vercel OG image generation, a new solution for instantaneously generating dynamic social cards. This approach is five times faster than existing solutions.&lt;/p&gt;

&lt;p&gt;(All images by &lt;a href="https://nextjs.org/" rel="noopener noreferrer"&gt;Next13&lt;/a&gt; via config22)&lt;/p&gt;




&lt;h2&gt;
  
  
  Other links:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/how-to-configure-react-js-app-on-wsl2-windows-10-3d1n"&gt;How to configure React JS app on WSL2 Windows 10&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/custom-tooltip-component-using-tailwind-and-react-js-186g"&gt;Custom 'Tooltip' component using Tailwind and React Js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/falsyfalse-and-truthytrue-values-explanation-with-example-4470"&gt;JavaScript: Falsy(False) and Truthy(True) values explanation with example&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>nextjs</category>
      <category>javascript</category>
      <category>react</category>
      <category>news</category>
    </item>
    <item>
      <title>How to configure React JS app on WSL2 Windows 10</title>
      <dc:creator>Muhammad Azfar Aslam</dc:creator>
      <pubDate>Tue, 18 Oct 2022 13:00:39 +0000</pubDate>
      <link>https://dev.to/muhammadazfaraslam/how-to-configure-react-js-app-on-wsl2-windows-10-3d1n</link>
      <guid>https://dev.to/muhammadazfaraslam/how-to-configure-react-js-app-on-wsl2-windows-10-3d1n</guid>
      <description>&lt;p&gt;Salut,&lt;br&gt;
If you use a windows machine with windows installed on it but also want to work using Linux/Ubuntu environment. There are mainly three approaches. (There can be more)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Virtual Machine&lt;/li&gt;
&lt;li&gt;Dual Boot&lt;/li&gt;
&lt;li&gt;WSL&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I would recommend you WSL because of two reasons. One, the first two approaches would be required a lot of resources like RAM and Hard Drive memory, etc. WSL consumes minimal resources and secondly, it allows you to export its image and import it on another computer within minutes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Enable Windows Subsystem for Linux&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open Start on Windows 10.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Search for Turn Windows features on or off and click the top result to open the experience.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Check the “Windows Subsystem for Linux” option.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F12ug9u8234ala8xxlu58.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F12ug9u8234ala8xxlu58.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Click the OK button.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click the Restart button.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Enable Virtual Machine Platform&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open Start, Search for PowerShell, right-click the top result, and select the Run as administrator option.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Type the following command to enable the Virtual Machine Platform feature and press Enter:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform


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

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Install WSL2 on Windows 10&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Search for Command Prompt, right-click the top result, and select the Run as administrator option.&lt;/p&gt;

&lt;p&gt;Type the following command to install the WSL on Windows 10 and press Enter:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

wsl --install


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

&lt;/div&gt;

&lt;p&gt;Another way is to go to the Microsoft store and install Ubuntu 18.04.&lt;/p&gt;

&lt;p&gt;Once you install Ubuntu run following commands.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

sudo apt update


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

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

sudo apt-get install curl


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

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash


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

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

source ~/.bashrc


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

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

nvm install 16


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

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

sudo apt-get install build-essential


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

&lt;/div&gt;

&lt;p&gt;Now go to your home directory and install react js app.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cd /home&lt;/code&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npx create-react-app my-app-on-wsl


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

&lt;/div&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

npm start


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

&lt;/div&gt;

&lt;p&gt;You may face a permission error (mostly this occurs with the Next JS app). To resolve this error you need to give app folder permission to your user as well.&lt;br&gt;
I hope this would be helpful for you guys. Do like and follow for more updates. &lt;/p&gt;

&lt;p&gt;**&lt;/p&gt;

&lt;h2&gt;
  
  
  Other links:
&lt;/h2&gt;

&lt;p&gt;**&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/custom-tooltip-component-using-tailwind-and-react-js-186g"&gt;Custom 'Tooltip' component using Tailwind and React Js&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/muhammadazfaraslam/falsyfalse-and-truthytrue-values-explanation-with-example-4470"&gt;JavaScript: Falsy(False) and Truthy(True) values explanation with example&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>linux</category>
      <category>ubuntu</category>
    </item>
    <item>
      <title>Custom 'Tooltip' component using Tailwind and React Js</title>
      <dc:creator>Muhammad Azfar Aslam</dc:creator>
      <pubDate>Mon, 19 Sep 2022 12:29:28 +0000</pubDate>
      <link>https://dev.to/muhammadazfaraslam/custom-tooltip-component-using-tailwind-and-react-js-186g</link>
      <guid>https://dev.to/muhammadazfaraslam/custom-tooltip-component-using-tailwind-and-react-js-186g</guid>
      <description>&lt;p&gt;&lt;strong&gt;Bonjour&lt;/strong&gt;&lt;br&gt;
I hope you all guys are good in health. I always prefer creating custom components (like a tooltip) instead of libraries because libraries mostly bring extra code. Of course, for major functionality. You should use a library as its code is optimized and provide a variety of possibilities.&lt;/p&gt;

&lt;p&gt;Let's come back to our original topic. The reason behind choosing Tailwind instead of bootstrap.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It is Highly Customizable.&lt;/li&gt;
&lt;li&gt;It Has Common Utility Patterns.&lt;/li&gt;
&lt;li&gt;It Can Be Optimized Using Purge CSS.&lt;/li&gt;
&lt;li&gt;It Enables Building Complex Responsive Layouts Freely.&lt;/li&gt;
&lt;li&gt;It Facilitates Fluid Community Interaction.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I would not explain these points in detail but I hope they're enough to give an idea.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { ReactNode, useState } from "react";

export const Tooltip = ({ message, children }: { message: string; children: ReactNode }) =&amp;gt; {
  const [show, setShow] = useState(false);
  return (
    &amp;lt;div className="relative flex flex-col items-center group"&amp;gt;
      &amp;lt;span className="flex justify-center" onMouseEnter={() =&amp;gt; setShow(true)} onMouseLeave={() =&amp;gt; setShow(false)}&amp;gt;
        {children}
      &amp;lt;/span&amp;gt;
      &amp;lt;div className={`absolute whitespace-nowrap bottom-full flex flex-col items-center  group-hover:flex ${!show ? "hidden" : null}`}&amp;gt;
        &amp;lt;span className="relative z-10 p-2 text-xs leading-none text-white whitespace-no-wrap bg-gray-600 shadow-lg rounded-md"&amp;gt;
          {message}
        &amp;lt;/span&amp;gt;
        &amp;lt;div className="w-3 h-3 -mt-2 rotate-45 bg-gray-600" /&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you can simply import this and call it like below&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;Tooltip message="Hello, world!"&amp;gt;
   &amp;lt;InfoIcon /&amp;gt;
&amp;lt;/Tooltip&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can style your tooltip box of any type. Also, it will allow you to style info text which you can not normally with an npm package. I hope it was helpful, &lt;br&gt;
Please like and share this post.&lt;br&gt;
You can also connect with me on &lt;a href="https://www.linkedin.com/in/muhammad-azfar-aslam" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; 😉&lt;/p&gt;

</description>
      <category>react</category>
      <category>tailwindcss</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>JavaScript: Falsy(False) and Truthy(True) values explanation with example</title>
      <dc:creator>Muhammad Azfar Aslam</dc:creator>
      <pubDate>Mon, 15 Aug 2022 13:03:00 +0000</pubDate>
      <link>https://dev.to/muhammadazfaraslam/falsyfalse-and-truthytrue-values-explanation-with-example-4470</link>
      <guid>https://dev.to/muhammadazfaraslam/falsyfalse-and-truthytrue-values-explanation-with-example-4470</guid>
      <description>&lt;p&gt;Bonjour, for a long time at beginning of my career I thought some statement is true if two values comparison is equal and false when some condition does not meet. The above statement is not wrong but incomplete. If we don't understand the all possibilities of truly(true) and falsy(false) values, we will not be able to understand all possible solutions/outcomes we can achieve with this concept. I recently came across a problem/challenge posted by "Hackerrank" in which I am going to explain the concept of True and False statements. &lt;/p&gt;

&lt;p&gt;So, the problem is to count all socks whose pairs are available in a pile. The pile may also contain a single sock with no pair available. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyspizx3tsm7gs3fzg16u.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyspizx3tsm7gs3fzg16u.jpg" alt="Image description" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Input Format&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The first line contains an integer representing the number of socks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The second line contains space-separated integers, the colors of the socks in the pile.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This can be solved by multiple approaches but I am going to use for loop just to explain what I am trying here to share with you guys.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function sockCount(n, ar) {
    let temp = {}
    let count = 0
    for (var i = 0; i &amp;lt; n; i++) {
        temp[ar[i]] = !temp[ar[i]]
        if (!temp[ar[i]]) count++
    }
    return count
}

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

&lt;/div&gt;



&lt;p&gt;And I pass values as following&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const n = 9;
const ar = [10, 20, 20, 10, 10, 30, 50, 10, 20]
sockCount(n, ar)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, all values are true except false, 0, -0, 0n, "", null, undefined, and NaN. &lt;/p&gt;

&lt;p&gt;At the start, temp is initialized by the empty object. It contains no value. This means if we check anything on this object, it'll return false due to undefined properties. So with all that in mind, we check to see if temp[ar[i]] exists.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Case (No)&lt;/strong&gt; The object temp does not contain the value stored at ar[i]. So in that case, we want to set the value of storage[ar[i]] to the opposite of its current value, which is undefined. Since undefined is falsy, the opposite is true. So we are setting storage[ar[i]] to true. So if our array is temp = { 1: true, 2: false} and we check for temp[3], we get undefined, so we update temp to { 1: true, 2: false, 3: true}&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Case (Yes)&lt;/strong&gt; If sock color is already in temp array, we inverse its value from true to false.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Case (False check)&lt;/strong&gt; If we get a false in the current iteration, we just increase the count by one.&lt;/p&gt;

&lt;p&gt;I hope you guys grab more clear explanation of falsy and truthy values after reading this article. If you do, do like this post.&lt;br&gt;
But if you loved it? man you gotta connect with me on &lt;a href="https://www.linkedin.com/in/muhammad-azfar-aslam" rel="noopener noreferrer"&gt;LinkedIn&lt;/a&gt; 😉&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
