<?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: Nadeem Khan</title>
    <description>The latest articles on DEV Community by Nadeem Khan (@nadeemkhanrtm).</description>
    <link>https://dev.to/nadeemkhanrtm</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%2F557470%2F4b035a9e-b7f5-4e97-942a-d1878ae0c850.jpeg</url>
      <title>DEV Community: Nadeem Khan</title>
      <link>https://dev.to/nadeemkhanrtm</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nadeemkhanrtm"/>
    <language>en</language>
    <item>
      <title>How KEY plays a vital role in React ?</title>
      <dc:creator>Nadeem Khan</dc:creator>
      <pubDate>Sat, 08 Jun 2024 21:14:51 +0000</pubDate>
      <link>https://dev.to/nadeemkhanrtm/react-the-hidden-dangers-of-using-index-as-a-key-1mbi</link>
      <guid>https://dev.to/nadeemkhanrtm/react-the-hidden-dangers-of-using-index-as-a-key-1mbi</guid>
      <description>&lt;p&gt;In this blog, we will cover:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Why is a &lt;strong&gt;Key&lt;/strong&gt; Needed in React?&lt;/li&gt;
&lt;li&gt;Why Avoid Using the Index as a Key?&lt;/li&gt;
&lt;li&gt;How Using Index as Key Creates Problems?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Consider this example where we have a list of product categories like Beauty, Fragrances, Furniture, etc. When a category is selected, we display the product details of that category using data from the &lt;a href="https://dummyjson.com/docs/products#products-categories"&gt;dummyjson&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%2Fti4qhiigr1vqpxjbxulg.gif" 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%2Fti4qhiigr1vqpxjbxulg.gif" alt="React:Category List Example" width="600" height="332"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Code:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// src/app/page.tsx

import CategoryContainer from "@/components/home-container";
import "../styles/global.css";

export default async function Home() {
  const response = await fetch("https://dummyjson.com/products/category-list");
  const data: string[] = await response.json();
  return (
    &amp;lt;&amp;gt;
      &amp;lt;CategoryContainer data={data} /&amp;gt;
    &amp;lt;/&amp;gt;
  );
}

&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;// CategoryContainer.tsx

"use client";

import Image from "next/image";
import React, { FC, useEffect, useState } from "react";
import ProductResponse from "./from-type-folder-lets-assume";

type Props = {
  data: string[];
};


const CategoryContainer: FC&amp;lt;Props&amp;gt; = ({ data }) =&amp;gt; {
  const [selectedCategory, setSelectedCategory] = useState("");
  const [productDetails, setProductDetails] = useState&amp;lt;ProductResponse | null&amp;gt;(
    null
  );

  useEffect(() =&amp;gt; {
    (async () =&amp;gt; {
      const response = await fetch(
        "https://dummyjson.com/products/category/" + selectedCategory
      );
      const data: ProductResponse = await response.json();
      setProductDetails(data);
    })();
  }, [selectedCategory]);

  return (
    &amp;lt;div className="max-w-6xl mx-auto my-10"&amp;gt;
      {data?.map((item, index) =&amp;gt; {
        return (
          &amp;lt;button
            key={index}
            type="button"
            onClick={() =&amp;gt; setSelectedCategory(item)}
            className={`text-gray-900 border border-gray-300 font-medium rounded-full text-sm px-5 py-2.5 me-2 mb-2 uppercase ${
              item === selectedCategory ? "bg-gray-600 text-white" : "bg-white"
            }`}
          &amp;gt;
            {item}
          &amp;lt;/button&amp;gt;
        );
      })}
      &amp;lt;h1 className="my-5 italic"&amp;gt;
        {selectedCategory ? (
          &amp;lt;&amp;gt;
            Product Details of{" "}
            &amp;lt;span className="font-bold uppercase"&amp;gt;{selectedCategory}&amp;lt;/span&amp;gt;
          &amp;lt;/&amp;gt;
        ) : (
          "Please select a category from above"
        )}
      &amp;lt;/h1&amp;gt;

      &amp;lt;div className="grid grid-cols-3 gap-3"&amp;gt;
        {productDetails?.products?.map((product, index) =&amp;gt; {
          return (
            &amp;lt;div
              key={index}
              className="max-w-sm p-6 bg-white border border-gray-200 rounded-lg shadow dark:bg-gray-800 dark:border-gray-700"
            &amp;gt;
              &amp;lt;div&amp;gt;
                &amp;lt;h2&amp;gt;{product.title}&amp;lt;/h2&amp;gt;
                &amp;lt;p&amp;gt;{product.description}&amp;lt;/p&amp;gt;
                &amp;lt;Image
                  key={index}
                  width={100}
                  height={100}
                  className="w-full h-full"
                  src={product.images?.[0]}
                  alt={product.title}
                /&amp;gt;
              &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
          );
        })}
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

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

&lt;/div&gt;



&lt;p&gt;In the &lt;strong&gt;CategoryContainer&lt;/strong&gt;, we loop through two lists: one for categories and another for product details of the selected category. Initially, we used the index as the key for both loops. This caused issues where images were not updating correctly when switching categories, as shown in this visual&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%2Fh5nsi42xggtgxadxez3p.gif" 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%2Fh5nsi42xggtgxadxez3p.gif" alt="React: Image Issue due to key" width="600" height="332"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Debugging the Problem&lt;/strong&gt;&lt;br&gt;
When switching categories, the content updated immediately, but the images took some time to load. This suggested that React wasn't re-rendering the components correctly.&lt;/p&gt;

&lt;p&gt;By examining the code, we noticed that using the index as the key prevented React from recognizing that new components needed to be rendered. React was reusing components with old images, leading to the delay&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution&lt;/strong&gt;&lt;br&gt;
We needed to provide a unique key for each product. Fortunately, the API response included a unique id for each product:&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%2F10oh93oylrlwjkh0ddsh.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%2F10oh93oylrlwjkh0ddsh.png" alt="React: Solution Here" width="800" height="709"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Using product.id as the key resolved the issue, ensuring React correctly identified and rendered new components:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
In React, always use a unique identifier for keys instead of the index. This ensures efficient and correct re-rendering of components, preventing issues like delayed image updates or incorrect component states.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Creating a Reusable Component in React: Handling Unlimited Future Changes</title>
      <dc:creator>Nadeem Khan</dc:creator>
      <pubDate>Sat, 01 Jun 2024 18:39:33 +0000</pubDate>
      <link>https://dev.to/nadeemkhanrtm/creating-a-reusable-component-in-react-handling-unlimited-future-changes-mgi</link>
      <guid>https://dev.to/nadeemkhanrtm/creating-a-reusable-component-in-react-handling-unlimited-future-changes-mgi</guid>
      <description>&lt;p&gt;Hi Folks,&lt;/p&gt;

&lt;p&gt;When working with React, creating reusable components is essential for maintaining clean, manageable, and scalable code. One common component that frequently needs to be adaptable and flexible. In this blog post, we’ll explore how to build a reusable component that can handle various configurations and adapt to future changes without becoming overly complex.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Variants of Headers&lt;/strong&gt;&lt;br&gt;
Let's consider a header component that may need to support different variants. Below is an example of different header styles:&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%2Fwhq80q5wkg3ll2vrbu6i.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%2Fwhq80q5wkg3ll2vrbu6i.png" alt="UI/UX: Different Type of Header with variants"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Basic Header Component&lt;/strong&gt;&lt;br&gt;
A typical React header component might look something like this, where props are used to conditionally render elements like the logo, navigation items, search bar, and cart.&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%2F2um3c46mnm2x0jx9d4ro.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%2F2um3c46mnm2x0jx9d4ro.png" alt="React: Basic Header Component"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Using props, a developer might set up the header as follows:&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%2Fbdxblne9ugi12kq803e0.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%2Fbdxblne9ugi12kq803e0.png" alt="React Code: Props Component Overloaded"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Usage:&lt;/strong&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%2Fnr2x71gsbt6quklzbycz.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%2Fnr2x71gsbt6quklzbycz.png" alt="React Code: Component Usage Which has overloaded props"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Handling Future Changes&lt;/strong&gt;&lt;br&gt;
Now, let's consider a scenario where the requirements change. The header needs to include additional elements like a favorites section, user account details, and a top banner with image and text that can be shown or hidden. If we continue using the prop-based approach, the component might look 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%2Fzg5s4qi0nbg7j5uiajsi.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%2Fzg5s4qi0nbg7j5uiajsi.png" alt="React Code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, this approach quickly becomes unwieldy with 10-15 props. Managing such a prop-heavy component can lead to cumbersome and error-prone code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using Compound Components&lt;/strong&gt;&lt;br&gt;
To address this issue, we can use the &lt;strong&gt;compound component&lt;/strong&gt; pattern. This approach allows for more flexible and readable code by enabling the parent component to define the structure and the children to specify the content.&lt;/p&gt;

&lt;p&gt;Here's an example of how we can refactor our header component using compound components:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Header.js&lt;/strong&gt;&lt;br&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%2Fsg2xbj8yjl2v9k89uq03.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%2Fsg2xbj8yjl2v9k89uq03.png" alt="React Code: Compound Pattern"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Usage&lt;/strong&gt;&lt;br&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%2Fqhwqml22fq2pvrk1mxcc.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%2Fqhwqml22fq2pvrk1mxcc.png" alt="React Code: Compound Pattern"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Benefits of Compound Components&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Flexibility&lt;/strong&gt;: Compound components provide greater flexibility as they allow you to nest components and pass props directly to the specific parts of the header.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Readability&lt;/strong&gt;: The structure is more readable and maintains a clear hierarchy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scalability&lt;/strong&gt;: Adding new components or modifying existing ones becomes easier without making the parent component too complex.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reusability&lt;/strong&gt;: Each part of the header can be reused independently in different contexts or layouts.&lt;/p&gt;

&lt;p&gt;By using the compound component pattern, we ensure that our header component remains manageable and adaptable to future changes, providing a robust solution for complex UI requirements.&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Detect Scroll Direction ReactJS</title>
      <dc:creator>Nadeem Khan</dc:creator>
      <pubDate>Sun, 07 Nov 2021 04:58:39 +0000</pubDate>
      <link>https://dev.to/nadeemkhanrtm/detect-scroll-direction-reactjs-1gnp</link>
      <guid>https://dev.to/nadeemkhanrtm/detect-scroll-direction-reactjs-1gnp</guid>
      <description>&lt;p&gt;In these blog. I am detecting scroll direction either person id scrolling down or up. To use these concept you can make some better thing like Navbar. Render a Navbar when we scroll untill that it gets disappear. So I am explaining here only about scroll direction If you want the example then please let me know.&lt;/p&gt;


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

&lt;p&gt;import React, {useEffect, useState, useCallback} from 'react';&lt;br&gt;
import { Fragment } from 'react/cjs/react.production.min';&lt;br&gt;
import styles from "./App.module.css";&lt;/p&gt;

&lt;p&gt;const App = () =&amp;gt; {&lt;br&gt;
  const [y,&lt;br&gt;
    setY] = useState(document.scrollingElement.scrollHeight);&lt;br&gt;
  const [scrollDirection,&lt;br&gt;
    setScrollDirection] = useState("you have not scrolled yet");&lt;/p&gt;

&lt;p&gt;const handleNavigation = useCallback((e) =&amp;gt; {&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (y &amp;amp;gt; window.scrollY) {
  setScrollDirection("Scrolling Up");
  console.log("scrolling up");
} else if (y &amp;amp;lt; window.scrollY) {
  setScrollDirection("Scrolling Down");
  console.log("scrolling down");
}
setY(window.scrollY)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;}, [y]);&lt;/p&gt;

&lt;p&gt;useEffect(() =&amp;gt; {&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;window.addEventListener("scroll", handleNavigation);

return () =&amp;amp;gt; {
  window.removeEventListener("scroll", handleNavigation);
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;}, [handleNavigation]);&lt;/p&gt;

&lt;p&gt;return (&lt;br&gt;
    &amp;lt;Fragment&amp;gt;&lt;br&gt;
    &amp;lt;div className={styles.main_container}&amp;gt;&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;amp;lt;/div&amp;amp;gt;
  &amp;amp;lt;div&amp;amp;gt;{scrollDirection}&amp;amp;lt;/div&amp;amp;gt;
&amp;amp;lt;/Fragment&amp;amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;)&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;export default App&lt;/p&gt;

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

&lt;/div&gt;
&lt;h2&gt;
&lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  OutPut Result&lt;br&gt;
&lt;/h2&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%2F4u7rjv2rawd78voq6vv4.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4u7rjv2rawd78voq6vv4.gif" alt="Result"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>css</category>
    </item>
    <item>
      <title>React Local Time Theme Based Quote Generator.</title>
      <dc:creator>Nadeem Khan</dc:creator>
      <pubDate>Thu, 04 Nov 2021 13:39:24 +0000</pubDate>
      <link>https://dev.to/nadeemkhanrtm/react-local-time-theme-based-quote-generator-2al0</link>
      <guid>https://dev.to/nadeemkhanrtm/react-local-time-theme-based-quote-generator-2al0</guid>
      <description>&lt;h3&gt;
  
  
  Steps
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Create react project&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Static code of html and css&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Adding API for random quote&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Adding API for Theme Selection and some JS&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Result and Live Demo&lt;/strong&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  Step 1
&lt;/h1&gt;

&lt;p&gt;Create react project using following command:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: Make sure the npm is installed.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;npx create-react-project theme-based-quote-generator&lt;/code&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 2
&lt;/h1&gt;

&lt;p&gt;Folder Structure&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%2Fllngg5jhxni4yndsjxnj.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%2Fllngg5jhxni4yndsjxnj.png" alt="Image description" width="278" height="579"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Step 3 &amp;amp; 4
&lt;/h1&gt;

&lt;h6&gt;
  
  
  main.js
&lt;/h6&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, {useEffect, useState} from 'react';
import styles from "./main.module.scss";
import {getCall} from "../../api/getCall";

const TOKEN = process.env.REACT_APP_TOKEN
const Main = () =&amp;gt; {
  const [quote,
    setQuote] = useState("Loading...")
  const [theme,
    setTheme] = useState();
  useEffect(() =&amp;gt; {
    getCall({path: "https://timezoneapi.io/api/ip/?token=" + TOKEN}).then((result) =&amp;gt; {
      var s = new Date().toLocaleString(undefined, {timeZone: result.data.data.timezone.id});
      const hours = s
        .split(", ")[1]
        .split(":")[0];
        if(hours &amp;gt;= 20 &amp;amp;&amp;amp; hours&amp;lt;=5 ){
            setTheme(false)
        }else{
            setTheme(true)
        }

    }).catch((error) =&amp;gt; {
      console.log(error)
    });
    getCall({path: "https://api.quotable.io/random"}).then((item) =&amp;gt; setQuote(item.data.content)).catch((error) =&amp;gt; {
      console.log(error)
    })
  }, [])

  const handleClick = () =&amp;gt; {
    setQuote("Loading...")
    getCall({path: "https://api.quotable.io/random"}).then((item) =&amp;gt; setQuote(item.data.content)).catch((error) =&amp;gt; {
      console.log(error)
    })
  }
  if(!theme){
      return(null)
  }else{
  return (
    &amp;lt;section
      className={[
      styles.main,
      (theme
        ? styles.day_mode
        : styles.night_mode)
    ].join(' ')}&amp;gt;
        &amp;lt;div&amp;gt;
        &amp;lt;h1
        className={[
        styles.main_title,
        (theme
          ? styles.day_mode_title
          : styles.night_mode_title)
      ].join(" ")}&amp;gt;Quote Generator&amp;lt;/h1&amp;gt;
      &amp;lt;span&amp;gt;Theme is decided as per the local time.&amp;lt;br/&amp;gt; Theme is {theme ? "day theme" : "night theme"} supports all country&amp;lt;/span&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;div
        className={[
        styles.quote_generator,
        (theme
          ? styles.night_mode
          : styles.day_mode)
      ].join(" ")}&amp;gt;
        {quote}
      &amp;lt;/div&amp;gt;
      &amp;lt;button
        className={[
        styles.button,
        (theme
          ? styles.night_mode
          : styles.day_mode)
      ].join(' ')}
        onClick={handleClick}&amp;gt;Generate Quote&amp;lt;/button&amp;gt;
    &amp;lt;/section&amp;gt;
  )
}
}

export default Main

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

&lt;/div&gt;



&lt;h6&gt;
  
  
  main.module.scss
&lt;/h6&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.main{
    height: 100vh;
    width: 100vw;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-evenly;
    &amp;amp;_title{
        font-size: 2.5em;
        text-align: center;
    }
    .quote_generator{
        min-height:300px;
        width: 70%;
        margin: 0 auto;
        border-radius: 16px;
        padding: 20px;
        font-size: 2em;
        text-align: center;
        display: flex;
        align-items: center;
        justify-content: center;
        @media screen and (max-width:768px){
            width: 100%;
            padding: 20px;
        }
        @media screen and (max-width:556px){
            padding: 10px;
        }
    }
    span{
        color: red;
        font-style: italic;
        font-weight: 100;
        font-size: 0.8em;
        display: block;
        text-align: center;
    }
    .button{
        height: 50px;
        border: none;
        padding: 10px;
        border-radius: 0.5em;
        font-size: 1em;
        cursor: pointer;
    }
}

.day_mode{
    background-color: rgb(235, 235, 235);
    color: #173f5f;
}

.night_mode{
    color: rgb(235, 235, 235);
    background-color: #173f5f;
}

.day_mode_title{
    color: #173f5f;
}

.night_mode_title{
    color: rgb(235, 235, 235);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h6&gt;
  
  
  getCall.js
&lt;/h6&gt;



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

export const getCall = async({path}) =&amp;gt; {
  return axios
    .get(`${path}`)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Step 5
&lt;/h1&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%2F8mjz9bg5rpbgslr4nnb8.gif" 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%2F8mjz9bg5rpbgslr4nnb8.gif" alt="Image description" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  LIVE DEMO
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://theme-based-quote-generator.netlify.app/"&gt;Live Demo Click here&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Any Questions Please let me know.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>react</category>
      <category>css</category>
    </item>
  </channel>
</rss>
