<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Parsa Frahani</title>
    <description>The latest articles on Forem by Parsa Frahani (@parsafarahani84).</description>
    <link>https://forem.com/parsafarahani84</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%2F1019050%2F3313f51e-a972-42ab-ab4e-cf22d7f466c0.png</url>
      <title>Forem: Parsa Frahani</title>
      <link>https://forem.com/parsafarahani84</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/parsafarahani84"/>
    <language>en</language>
    <item>
      <title>Difference between normal links &amp; tag links in Next.js</title>
      <dc:creator>Parsa Frahani</dc:creator>
      <pubDate>Sun, 30 Jun 2024 06:33:20 +0000</pubDate>
      <link>https://forem.com/parsafarahani84/difference-between-normal-links-tag-links-in-nextjs-8m7</link>
      <guid>https://forem.com/parsafarahani84/difference-between-normal-links-tag-links-in-nextjs-8m7</guid>
      <description>&lt;p&gt;Today in this blog we will talk about the effect of using "a" tag &amp;amp; "Link" tag in Next.js. Are they really different from each other?&lt;br&gt;
Sure they are, let me explain.&lt;/p&gt;
&lt;h2&gt;
  
  
  Normal Links
&lt;/h2&gt;

&lt;p&gt;When you use normal links 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;a href="./users"&amp;gt;Click Here&amp;lt;/a&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;every time that you click the link and navigate to other pages, you call a request to all the files and all of them will download again. That's something we don't want of course. so look at this folder structure that I have to understand better:&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%2Fszqwqsqmmef26utgogzf.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%2Fszqwqsqmmef26utgogzf.png" alt="Image description" width="310" height="171"&gt;&lt;/a&gt;&lt;br&gt;
In this structure, as you can see in my app folder I have a page.tsx file and a folder named "folder" that contains F1.tsx.&lt;br&gt;
In the page file, I have below code that is just a simple 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 React from "react";

async function page() {
  return (
    &amp;lt;div className="p-[1rem]"&amp;gt;
      &amp;lt;h1&amp;gt;Hello World&amp;lt;/h1&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default page;

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

&lt;/div&gt;



&lt;p&gt;And in the F1 file, I have this code that as you see it's just a simple button with "a" tag in it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Link from "next/link";
import React from "react";

function F1() {
  return (
    &amp;lt;button className="py-[0.5rem] px-[2.5rem] bg-gray-800 rounded-[0.75rem]"&amp;gt;
      &amp;lt;a href="/users" className="text-white"&amp;gt;
        click
      &amp;lt;/a&amp;gt;
    &amp;lt;/button&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;When you click that "a" tag you will navigate to the user's file page and everything should work fine. But let's open the Network tab real quick.&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%2Fob598vbg6wcizzvhtolu.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%2Fob598vbg6wcizzvhtolu.png" alt="Image description" width="800" height="347"&gt;&lt;/a&gt;&lt;br&gt;
It's normal, right? we have all the necessary files in here.&lt;br&gt;
OK now clear the Network log and click the button to navigate to the user page:&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%2Fq3w1gcrjdrx9nm16umcy.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%2Fq3w1gcrjdrx9nm16umcy.png" alt="Image description" width="800" height="608"&gt;&lt;/a&gt;&lt;br&gt;
By clicking the button we go to "&lt;a href="http://localhost:3000/users"&gt;http://localhost:3000/users&lt;/a&gt;" &amp;amp; this is our Network log:&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%2F7s5x8rrvtiqw63nzyv66.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%2F7s5x8rrvtiqw63nzyv66.png" alt="Image description" width="800" height="332"&gt;&lt;/a&gt;&lt;br&gt;
As I told you we redownloaded all the unnecessary files again. and we don't want that. So what is the solution?&lt;/p&gt;
&lt;h2&gt;
  
  
  Tag Links
&lt;/h2&gt;

&lt;p&gt;Simple, we are just going to use "Link" instead of "a" tag. 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;import Link from "next/link";
import React from "react";

function F1() {
  return (
    &amp;lt;button className="py-[0.5rem] px-[2.5rem] bg-gray-800 rounded-[0.75rem]"&amp;gt;
      &amp;lt;Link href="/users" className="text-white"&amp;gt;
        click
      &amp;lt;/Link&amp;gt;
    &amp;lt;/button&amp;gt;
  );
}

export default F1;

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

&lt;/div&gt;



&lt;p&gt;Now again open the Network tab, we have our files downloaded once. Click clear log like before and navigate to the F1 file using the button. Now if you see the log we just downloaded our necessary files and not all of the files again.&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%2Fvhopx4kyye5na7n83mnc.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%2Fvhopx4kyye5na7n83mnc.png" alt="Image description" width="800" height="603"&gt;&lt;/a&gt;&lt;br&gt;
So to wrap up by using the "a" tag we download all the files again &amp;amp; again but with the "Link" tag we just download all the files once and on every page we just download what we need.&lt;/p&gt;

&lt;p&gt;This small change may not seem handy but in the big projects, it will help you build a website or app with better performance and of course a faster one!&lt;br&gt;
If this blog helped you please like and also feel free to share ANY opinion in the comments section. Thanks for reading🙏.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
      <category>programming</category>
    </item>
    <item>
      <title>3D Car Image Just With One API!</title>
      <dc:creator>Parsa Frahani</dc:creator>
      <pubDate>Sat, 27 Apr 2024 08:07:33 +0000</pubDate>
      <link>https://forem.com/parsafarahani84/3d-car-image-just-with-one-api-40ak</link>
      <guid>https://forem.com/parsafarahani84/3d-car-image-just-with-one-api-40ak</guid>
      <description>&lt;p&gt;Let me introduce an API that you just gave the car name and then you can have a 3D image of it in any color, angle, model, and so on, and that's &lt;a href="https://www.imaginstudio.com" rel="noopener noreferrer"&gt;imaging studio&lt;/a&gt;. &lt;br&gt;
In this blog, I'll teach you how to use this API and how to customize the car in the way that you want. so let's go to VScode and learn while we are coding.&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%2Fzd1upxq45od2dsnozwub.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%2Fzd1upxq45od2dsnozwub.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1- Where Can You Get The API?
&lt;/h2&gt;

&lt;p&gt;Well, you can find the API on the RapidAPI website &lt;a href="https://rapidapi.com/apininjas/api/cars-by-api-ninjas?utm_source=youtube.com%2FJavaScriptMastery&amp;amp;utm_medium=referral&amp;amp;utm_campaign=DevRel" rel="noopener noreferrer"&gt;here&lt;/a&gt;. As you can see you have the code for calling the API that you can copy and paste but if you want to see what will you receive after fetching this API simply click the Test Endpoint button and it will show you the JSON format of the data.&lt;br&gt;
By clicking the button you can see we have tons of options like fuel_type, drive, class, and a lot more. Keep in mind that this API is free and you don't have to pay any money to use it.&lt;/p&gt;

&lt;h2&gt;
  
  
  2- Get The Data
&lt;/h2&gt;

&lt;p&gt;So here, I have a small project that I want to simply call the API and get the Supra image with a kind of green color. so let's make an index.ts file and copy these codes for calling the API.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export async function fetchCars() {
  try {
    const response = (
      await fetch(
        "https://cars-by-api-ninjas.p.rapidapi.com/v1/cars?model=supra",
        {
          headers: {
            "X-RapidAPI-Key":
              "fa5d9302b5msh316f633dd1fb958p111bedjsnb5ccf339adf5",
            "X-RapidAPI-Host": "cars-by-api-ninjas.p.rapidapi.com",
          },
        }
      )
    ).json();
    return response;
  } catch (error) {
    console.error(error);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the above code, I just fetched the API in an async function, and in the headers option, I gave it the same headers in the Rapid API (Just copy and paste the code). But did you notice something in the API? &lt;br&gt;
After cars, I gave it the name of the car that I wanted like: &lt;strong&gt;[the API]?model=supra&lt;/strong&gt;.&lt;br&gt;
Or you can just give the params and then the car model that you want. 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%2Fdufvppi54575tjlohq7k.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%2Fdufvppi54575tjlohq7k.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
So now how can we see it?&lt;br&gt;
Let's go to our Hero.tsx file that we want to use this API to render our car image there. This is how Hero.tsx looks like:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { BackgroundBeams } from "@/components/Aceternety-ui/HeroBeams";
import React from "react";
import styles from "./Hero.module.css";
import { fetchCars } from "@/utils";

async function Hero() {
  const allCars = await fetchCars();
  console.log(allCars);

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;BackgroundBeams /&amp;gt;
      &amp;lt;div className={styles.component}&amp;gt;


        &amp;lt;div className={styles.carImageComponent}&amp;gt;
             {/* HERE WE RENDER THE IMAGE */}
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default Hero;

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

&lt;/div&gt;

&lt;p&gt;Here we have BackgroundBeams it is a component from aceternity UI (it's okay if you don't use this one), then our styles, and finally imported the fetchCars from Index.ts in the utils folder.&lt;br&gt;
So basically this file right here:&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%2F2fezw71mzbhjpdy40xxc.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%2F2fezw71mzbhjpdy40xxc.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Then I await this fetchCars function and store it in a const name allCars. Now if you log this allCars maybe your log in your browser will throw an error but when you open your terminal in VScode you can see all of the data there:&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%2Ftgjkyb107n0bs277ll3u.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%2Ftgjkyb107n0bs277ll3u.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Now that you have all of the data for the Supra car you can simply loop through the allCars array and use all of these parameters, but what about the image? there is no image in our data, right?&lt;br&gt;
No worries, for getting the image we need to call another API provided by the imagin studio. So let's back to our index.tsx to call this API.&lt;/p&gt;

&lt;h2&gt;
  
  
  3- Get the Image
&lt;/h2&gt;

&lt;p&gt;As I told you we need to fetch another API to get the images. Basically, these 2 APIs are for one company, one for getting data and the other one for getting the image.&lt;/p&gt;

&lt;p&gt;So let's begin:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const createCarImage = (car: any, angle?: string) =&amp;gt; {
  const url = new URL("https://cdn.imagin.studio/getimage");

  const { make, year, model } = car;

  url.searchParams.append("customer", "hrjavascript-mastery");
  url.searchParams.append("zoomType", "fullscreen");
  url.searchParams.append("paintdescription", "radiant-green");
  url.searchParams.append("modelFamily", model.split(" ")[0]);
  url.searchParams.append("make", make);
  url.searchParams.append("modelYear", `${year}`);
  url.searchParams.append("angle", `${angle}`);

  return `${url}`;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In this code, I gave our createCarImage function two parameters one is the &lt;strong&gt;car&lt;/strong&gt; which is an array of our data and the second one is the car &lt;strong&gt;angle&lt;/strong&gt; which if it exists we use it otherwise, we don't need it. Then I created a new URL and gave it the API which you can see in the code above. After that, I take out the model, year, and make out of the car parameter so we don't need to write car.model or car.year every time. In the end, I set all the other parameters for our API like zoomType or modelYear, and finally returned the URL. &lt;br&gt;
But to get the image you need to have a customer key. You may not be a company to email them for sending it to you, and it is totally okay cause as you can see I found a free customer key name as &lt;strong&gt;hrjavascript-mastery&lt;/strong&gt; for you under one of the projects of &lt;a href="https://www.youtube.com/@javascriptmastery" rel="noopener noreferrer"&gt;js mastery channel&lt;/a&gt; on YouTube that you can use for your projects completely free!&lt;/p&gt;

&lt;p&gt;Here we used our key that you can see in the above code too:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  url.searchParams.append("customer", "hrjavascript-mastery");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In the Hero file, we need to import this createCarImage function to use it in our JSX, like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { fetchCars , createCarImage } from "@/utils";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now to get the image we need to pass this function to its src and give it the allCars (our data that we had) at the position of 0 because I want the first car model in the array of our data. If you like to render all of the cars that you have in the allCars array you can simply loop over it and then use the data for it. So the code will look like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function Hero() {
  const allCars = await fetchCars();
  console.log(allCars);

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;BackgroundBeams /&amp;gt;
      &amp;lt;div className={styles.component}&amp;gt;
        &amp;lt;h1&amp;gt;SUPRA!!!&amp;lt;/h1&amp;gt;

        &amp;lt;div className={styles.carImageComponent}&amp;gt;
          &amp;lt;img className={styles.carImg} src={createCarImage(allCars[0], "")} /&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;As you can see I'm giving allcars at position 0 to my createCarImage function to look for the image of that car and also I gave it no angle (If you like to try another angle go for 29 or 13 for example). now you should see 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%2Fol1xsb5chil53ze2x95b.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%2Fol1xsb5chil53ze2x95b.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At the angle of 29:&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%2F60zogzoldz2ntwlvhizq.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%2F60zogzoldz2ntwlvhizq.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At the angle of 13:&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%2Fuoxe5tsi1d0yqq2h0ppy.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%2Fuoxe5tsi1d0yqq2h0ppy.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  4- Need docs?
&lt;/h2&gt;

&lt;p&gt;If you need help with this API you can always read their docs &lt;a href="https://docs.imagin.studio/" rel="noopener noreferrer"&gt;here&lt;/a&gt;. You can find docs about subjects like changing colors or zooming and a lot more.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔴Was This Blog Helpful?
&lt;/h2&gt;

&lt;p&gt;If this blog was helpful to you like and follow🙏.&lt;br&gt;
Also if you have any opinion or question feel free to comment it out.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>api</category>
      <category>javascript</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Smarter Code With AbortController!</title>
      <dc:creator>Parsa Frahani</dc:creator>
      <pubDate>Wed, 17 Apr 2024 10:06:47 +0000</pubDate>
      <link>https://forem.com/parsafarahani84/smarter-code-with-abortcontroller-14g1</link>
      <guid>https://forem.com/parsafarahani84/smarter-code-with-abortcontroller-14g1</guid>
      <description>&lt;p&gt;For example, think that you fetched an API but for any reason, you want to cancel it. what will you do? or maybe you have an event on some button and you want that event don't work if something happens. what will do here? call another event?&lt;br&gt;
All of these ideas that you have may work, but they are not &lt;strong&gt;smart&lt;/strong&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%2Fu09rg5ez18fka61xbs3t.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%2Fu09rg5ez18fka61xbs3t.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With the help of ES6 now you can cancel your request or event at any time with better &amp;amp; also with smarter code. so without wasting any time let's get into it.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is AbortController?
&lt;/h2&gt;

&lt;p&gt;So basically as I said, AbortController is used for canceling events or requests easily. We have two parts to work with it, one is the usual AbortController and the other one is AbortSignal. With the use of AbortSignal we can have access to the API's signal and call our AbortController, then set some conditions that if X happens cancel fetching data. but to understand better and deeper let's see it in the code.&lt;/p&gt;
&lt;h2&gt;
  
  
  Using AbortController In JavaScript:
&lt;/h2&gt;

&lt;p&gt;Take a quick look at the code below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const controller = new AbortController();

const functionFetch = async () =&amp;gt; {
  try {
    const url = await fetch("https://catfact.ninja/fact", {
      signal: controller.signal,
    });
    const todo = await url.json();
    console.log(todo);
  } catch (error) {
    if (error.name === "AbortError") {
      console.log("this is an abort error ==&amp;gt;", error);
    }
  }
};
functionFetch();
controller.abort();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's okay not to get it all, but let me break it down.&lt;/p&gt;

&lt;p&gt;So first to start it we need to make a new AbortController as we did so. Then I fetched an API and got access to its signal like an object and gave it the property of &lt;code&gt;controller.signal&lt;/code&gt;, but what does this signal do?&lt;/p&gt;

&lt;p&gt;So basically we use this property to communicate with the outer abort (as we are setting it for our API).&lt;/p&gt;

&lt;p&gt;After that, I made a Constance value and named it &lt;strong&gt;todo&lt;/strong&gt; that simply holds the JSON version of our data. In the catch part, I checked if the error name is AbortError which means our API got canceled because of our abort I'll log and string with a text. &lt;/p&gt;

&lt;p&gt;In the end, I called the function to make it work and also called the controller.abort to cancel the API. So if we wanted to cancel the API call we simply call the controller.abort anywhere we wanted. If you check the console we should have this text there:&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%2Fbcg0jyeyz2w1c3z5z72s.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%2Fbcg0jyeyz2w1c3z5z72s.png" alt="Image description" width="721" height="100"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And by the way, you can name the &lt;strong&gt;controller&lt;/strong&gt; anything that you want as it's obvious or you can specify some conditions like if/else statements. and that's how you use AbortController in your Project. easy huh?&lt;/p&gt;

&lt;h2&gt;
  
  
  How To Use It In The Events?
&lt;/h2&gt;

&lt;p&gt;Most programmers think that AbortController is just for API and they don't know they can use it to stop events too. before I explain how you should use it to stop events take a quick look at the code below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const controller = new AbortController();
const { signal } = controller;

const log = function () {
  console.log("mouse moved");
};

const remove = function () {
  console.log("Event stoped");
  controller.abort();
};

window.addEventListener("mousemove", log, { signal });
window.addEventListener("mouseup", remove, { signal });


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

&lt;/div&gt;



&lt;p&gt;Understanding the code above got to be easy but I'll explain it as well.&lt;/p&gt;

&lt;p&gt;So this is the code that we had before but now we are canceling the log event by clicking. But notice something in the events, I gave them a third property and that signal. By doing that I', telling them that on this event call our AbortController.&lt;/p&gt;

&lt;p&gt;If you move the mouse it will log the string in the log function and if you click the AbortController will stop the log function and it's not going to work anymore (before stopping the log function we will see Event stopped as you can see).&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%2Fe2aqt3ypp6hx7fqw4qb2.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%2Fe2aqt3ypp6hx7fqw4qb2.png" alt="Image description" width="709" height="139"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you click multiple times it will stop the event several times as you know (so the AbortController will be called several times).&lt;/p&gt;

&lt;p&gt;But did you know that we have an event named &lt;strong&gt;abort&lt;/strong&gt;?&lt;/p&gt;

&lt;h2&gt;
  
  
  Abort Event In JS:
&lt;/h2&gt;

&lt;p&gt;Honestly, That was so interesting for me. so we have an event named abort that whenever we call AbrotController this event will call too. look here to understand better:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const controller = new AbortController();
const { signal } = controller;


const log = function () {
    console.log("mouse moved");
  };

  const remove = function () {
    console.log("Event stoped");
    controller.abort();
  };

  window.addEventListener("mousemove", log, { signal });
  window.addEventListener("mouseup", remove, { signal });

  // I ADDED THIS👇
  signal.addEventListener("abort", () =&amp;gt; {
    console.log("this is abort event");
  });

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

&lt;/div&gt;



&lt;p&gt;This is the last part code but with a new event as you can see. So simply we call our event on the signal and we tell it whenever something aborted log this string. The output should be like this:&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%2Fqu30pm1u9l0kibd6sjx1.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%2Fqu30pm1u9l0kibd6sjx1.png" alt="Image description" width="718" height="153"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;Now that you are at the end of this blog keep in mind that AbortControllers can be more complicated when you use libraries like Axios. I hope this blog helped you understand the basics of abort controllers and how to use them in real projects.&lt;/p&gt;

&lt;p&gt;If you have any opinion feel free to share it in the comments🙏.&lt;br&gt;
Thanks for your support.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
      <category>programming</category>
    </item>
    <item>
      <title>Explanation of CSS Gradients</title>
      <dc:creator>Parsa Frahani</dc:creator>
      <pubDate>Tue, 02 Apr 2024 11:32:29 +0000</pubDate>
      <link>https://forem.com/parsafarahani84/explanation-of-css-gradients-58h0</link>
      <guid>https://forem.com/parsafarahani84/explanation-of-css-gradients-58h0</guid>
      <description>&lt;p&gt;You may ask yourself what is the difference between linear-gradient, radial-gradient &amp;amp; conic-gradient as they sound so confusing, but not after reading this blog!&lt;br&gt;
In this blog, I'm going to explain the differences between these three gradients and how you can use them like a pro-CSS writer. so let's dive in.&lt;/p&gt;
&lt;h2&gt;
  
  
  1- Set Up Our Project
&lt;/h2&gt;

&lt;p&gt;Before anything let's make our project and then work on it. so here I have an HTML &amp;amp; CSS file as you can see:&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%2Fmhmivrstr8y3va5w492w.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%2Fmhmivrstr8y3va5w492w.png" alt="Image description" width="406" height="394"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;this is my simple HTML:&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;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8" /&amp;gt;
    &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&amp;gt;
    &amp;lt;link href="./style.css" rel="stylesheet" /&amp;gt;
    &amp;lt;title&amp;gt;Gradients&amp;lt;/title&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;div class="container"&amp;gt;
      &amp;lt;h1&amp;gt;Hello World&amp;lt;/h1&amp;gt;
      &amp;lt;div class="tester"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@import url("https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&amp;amp;display=swap");

body {
  background-color: #333;
  overflow-x: hidden;
  font-family: "Poppins", sans-serif;
}

.container {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  height: 90vh;
  width: 100vw;
}

.container h1 {
  color: white;
  font-weight: 400;
}

.tester {
  width: 10rem;
  height: 10rem;
  background-color: rgb(0, 208, 255);
  border-radius: 1rem;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our goal is to style the taster div and try different gradients on it.&lt;br&gt;
Well done, now we set up our project let me explain the first gradient.&lt;/p&gt;
&lt;h2&gt;
  
  
  2- Linear Gradient
&lt;/h2&gt;

&lt;p&gt;As you may know for giving all the gradients you have to use background-image like here:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  background-image: linear-gradient(red, blue);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we are giving linear gradient to our taster div. linear-gradient will get two colors minimum and you can specify where the color should start or even how many degrees should it be. now our taster div looks like this:&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%2Fk50onx4nrie60cz4noko.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%2Fk50onx4nrie60cz4noko.png" alt="Image description" width="800" height="350"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now I use &lt;strong&gt;to right&lt;/strong&gt;, &lt;strong&gt;to left&lt;/strong&gt;, &lt;strong&gt;to bottom&lt;/strong&gt;, &lt;strong&gt;to top&lt;/strong&gt; to specify where should the color start as I said.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  background-image: linear-gradient(to right, red, blue);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now our div looks like this:&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%2Fqr7b04xqha9ryy4b1z57.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%2Fqr7b04xqha9ryy4b1z57.png" alt="Image description" width="800" height="352"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can also add multiple colors:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  background-image: linear-gradient(to right, red, blue, green, yellow);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can even give it a Percentage after the colors to say it should cover X% of the div.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  background-image: linear-gradient(to right, red 10%, blue 20%);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we are saying that from 0% to 10% should be red &amp;amp; after that from 20% to the end of the div (100%) should be blue. like this:&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%2Fnjm47ssw72wwx6iwdnoc.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%2Fnjm47ssw72wwx6iwdnoc.png" alt="Image description" width="800" height="349"&gt;&lt;/a&gt; &lt;br&gt;
Or specify the start &amp;amp; the end percentage 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;  background-image: linear-gradient(to right, red 0% 10%, blue 50% 100%);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here the red color will start from 0% to 20% &amp;amp; blue will start from 50% &amp;amp; end in 100%. this gap between red &amp;amp; blue will fill with the transition that they have:&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%2Fib7flmnyktvhm96pf7n6.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%2Fib7flmnyktvhm96pf7n6.png" alt="Image description" width="800" height="345"&gt;&lt;/a&gt;&lt;br&gt;
It's obvious that if you give the colors no space for transition they will just stick together. like this example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  background-image: linear-gradient(
    to right,
    red 0% 10%,
    blue 10% 50%,
    green 50% 100%
  );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code has no gap between the colors so it will be like this:&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%2Fufuc9dk1h44zpwwzjsoq.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%2Fufuc9dk1h44zpwwzjsoq.png" alt="Image description" width="800" height="350"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3- Radial Gradient
&lt;/h2&gt;

&lt;p&gt;In radial-gradient the colors will start from the center of the page in the form of a circle &amp;amp; you can add colors to it. let's try it out:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  background-image: radial-gradient(red, blue);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we have this:&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%2Fhlg6mm1sb9ss1n5slrf2.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%2Fhlg6mm1sb9ss1n5slrf2.png" alt="Image description" width="800" height="344"&gt;&lt;/a&gt;&lt;br&gt;
Exactly like linear that we had t*&lt;em&gt;o bottom&lt;/em&gt;&lt;em&gt;, **to top&lt;/em&gt;&lt;em&gt;, ... in here we have **circle&lt;/em&gt;&lt;em&gt;, **circle at bottom&lt;/em&gt;* or even** circle at bottom left**. It will give our colors a better circle shape:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  background-image: radial-gradient(circle, red, blue);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And this is what we have:&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%2Fcfmolp5h05qnxdf6649h.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%2Fcfmolp5h05qnxdf6649h.png" alt="Image description" width="800" height="347"&gt;&lt;/a&gt;&lt;br&gt;
And you can give them percentages as well exactly like before:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  background-image: radial-gradient(
    circle at bottom left,
    red 0% 20%,
    blue 50% 100%
  );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it for radial gradients. let's move on to the next one.&lt;/p&gt;

&lt;h2&gt;
  
  
  4- Conic Gradient
&lt;/h2&gt;

&lt;p&gt;In the conic gradient the colors rotate around a center on the page. for example with this line of code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  background-image: conic-gradient(red, blue);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will have this:&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%2Fikh36834lhs8tgmmfmn3.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%2Fikh36834lhs8tgmmfmn3.png" alt="Image description" width="800" height="343"&gt;&lt;/a&gt;&lt;br&gt;
You can add more colors and it will add them clockwise or you can give them degrees like before.&lt;/p&gt;
&lt;h2&gt;
  
  
  Repeating Gradient's
&lt;/h2&gt;

&lt;p&gt;As the name says it will repeat the linear, radial or conic gradient. here is an example of it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  background-image: repeating-linear-gradient(
    red 50px,
    blue 50px 100px,
    red 100px 150px
  );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this code we have this repeating blue &amp;amp; red gradient:&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%2Fzk4w584l0qntrylzcc8d.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%2Fzk4w584l0qntrylzcc8d.png" alt="Image description" width="800" height="348"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;Great job! You've learned all about gradients and now you can use them like a CSS expert. With these skills, you can make your websites more colorful and attractive. you can read more in &lt;a href="https://developer.mozilla.org/"&gt;MDN&lt;/a&gt; website.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you found this blog helpful let me know in the comments🙏.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>css</category>
      <category>javascript</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>For...of Loops Over Map in API Handling</title>
      <dc:creator>Parsa Frahani</dc:creator>
      <pubDate>Sun, 07 Jan 2024 06:37:27 +0000</pubDate>
      <link>https://forem.com/parsafarahani84/forof-loops-over-map-in-api-handling-5dn1</link>
      <guid>https://forem.com/parsafarahani84/forof-loops-over-map-in-api-handling-5dn1</guid>
      <description>&lt;h2&gt;
  
  
  Introduction:
&lt;/h2&gt;

&lt;p&gt;In the dynamic field of web development, interacting with APIs is a routine task for developers. When it comes to iterating through arrays, two commonly used methods are the traditional for...of loop and the higher-order function map(). While both methods have their merits, there are situations where using a for...of loop can be more advantageous, particularly in the context of API interactions. In this article, we'll delve into the reasons why developers often choose for...of loops over map() when working with APIs.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Clarity in Asynchronous Code:
&lt;/h2&gt;

&lt;p&gt;API calls often involve asynchronous operations, and when dealing with promises, the clarity of code becomes crucial. The for...of loop provides a more straightforward syntax, making it easier to read and understand asynchronous code. It allows developers to express the logic of fetching and handling data in a sequential manner, enhancing code readability and maintainability.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Using for...of loop
const fetchData = async () =&amp;gt; {
  for (const item of data) {
    const response = await fetch(`https://api.example.com/${item}`);
    const result = await response.json();
    // Handle result
  }
};

// Using map
const fetchDataWithMap = async () =&amp;gt; {
  await Promise.all(data.map(async (item) =&amp;gt; {
    const response = await fetch(`https://api.example.com/${item}`);
    const result = await response.json();
    // Handle result
  }));
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Fine-grained Control:
&lt;/h2&gt;

&lt;p&gt;The for...of loop provides finer control over the iteration process. Developers can insert logic between iterations or implement custom error handling for each API call. This level of control is often more challenging to achieve with the concise and declarative nature of map().&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Using for...of loop
const fetchDataWithControl = async () =&amp;gt; {
  for (const item of data) {
    try {
      const response = await fetch(`https://api.example.com/${item}`);
      const result = await response.json();
      // Handle result
    } catch (error) {
      // Handle error for this specific API call
    }
  }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Sequential Requests:
&lt;/h2&gt;

&lt;p&gt;In certain scenarios, API requests must be executed sequentially, with the result of one request influencing the next. The for...of loop naturally enforces this sequential behavior, ensuring that each API call is made one after the other. This can be vital when dealing with APIs that have rate limits or dependencies between requests.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Using for...of loop
const sequentialRequests = async () =&amp;gt; {
  for (const endpoint of endpoints) {
    const response = await fetch(`https://api.example.com/${endpoint}`);
    const result = await response.json();
    // Process result and decide whether to proceed to the next request
  }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Reduced Complexity:
&lt;/h2&gt;

&lt;p&gt;For simple iterations, using a for...of loop is often more concise and reduces the overall complexity of the code. The simplicity of the loop is especially beneficial when dealing with straightforward API interactions that don't require extensive transformation or mapping of data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Using for...of loop
const simpleApiInteraction = async () =&amp;gt; {
  for (const id of userIds) {
    const response = await fetch(`https://api.example.com/users/${id}`);
    const user = await response.json();
    // Handle user data
  }
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;----------------------------------SECTION2----------------------------------&lt;br&gt;
If you're experiencing a situation where data from your API is continuously logged in an infinite loop, there are several potential reasons for this behavior. Here are some common causes and solutions:&lt;/p&gt;
&lt;h2&gt;
  
  
  1- Incorrect Use of Hooks or State:
&lt;/h2&gt;

&lt;p&gt;If you are using React or another framework that utilizes state management, ensure that you are updating the state correctly. Continuous logging might occur if the state is being updated in a way that triggers re-renders in an infinite loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Incorrect state update causing infinite loop
useEffect(() =&amp;gt; {
  fetchData();  // Assuming fetchData triggers a state update
}, [data]);  // data is part of the dependency array triggering useEffect on state change
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ensure that you are updating state appropriately and that your dependencies in useEffect are set up correctly.&lt;/p&gt;

&lt;h2&gt;
  
  
  2- Infinite Fetch Requests:
&lt;/h2&gt;

&lt;p&gt;Check your code for any unintentional recursive function calls or loops that repeatedly trigger API requests. Make sure that your API fetching logic is not creating an infinite loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Example of unintentional infinite loop in fetching logic
const fetchData = () =&amp;gt; {
  fetch('https://api.example.com/data')
    .then(response =&amp;gt; response.json())
    .then(data =&amp;gt; {
      console.log(data);
      fetchData();  // This creates an infinite loop
    });
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ensure that API fetching is performed only when necessary and that you are not triggering the same request repeatedly.&lt;/p&gt;

&lt;h2&gt;
  
  
  3- Incorrect Dependencies in useEffect:
&lt;/h2&gt;

&lt;p&gt;If you are using useEffect in a React component, check the dependencies array to ensure that you are not inadvertently causing the effect to run infinitely.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Incorrect dependencies leading to an infinite loop
useEffect(() =&amp;gt; {
  fetchData();
}, []);  // Empty dependency array causing the effect to run on every render
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure to include only the necessary dependencies to prevent unnecessary re-execution.&lt;/p&gt;

&lt;h2&gt;
  
  
  4- Console.log Inside a Render:
&lt;/h2&gt;

&lt;p&gt;If you have console.log statements inside your render method or JSX, they will be executed every time the component re-renders, potentially causing a large number of logs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Example causing continuous logging on each render
const MyComponent = () =&amp;gt; {
  console.log('Rendering component...');
  return &amp;lt;div&amp;gt;Component content&amp;lt;/div&amp;gt;;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Move console.log statements outside the render method or use them judiciously to avoid excessive logging.&lt;br&gt;
By investigating these potential causes, you should be able to identify and resolve the issue of continuous logging of data from your API.&lt;/p&gt;

&lt;p&gt;While the for...of loop has its strengths, it's essential to recognize that different looping constructs and higher-order functions, such as map(), forEach(), and others, also play crucial roles in JavaScript development. The key is to choose the looping mechanism that best fits the specific requirements of your task, promotes readability, and aligns with your team's coding style and preferences.&lt;/p&gt;

&lt;h2&gt;
  
  
  conclusion
&lt;/h2&gt;

&lt;p&gt;In conclusion, while the map() function is a powerful tool for array transformations, the for...of loop offers distinct advantages when handling asynchronous API calls. Its clarity, fine-grained control, ability to execute sequential requests, and reduced complexity make it a preferred choice for developers aiming to write clean, readable, and maintainable code in the context of API interactions. The decision between for...of and map() ultimately depends on the specific requirements of the task at hand and the level of control and readability desired in the codebase.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>webdev</category>
    </item>
    <item>
      <title>All about RSS (Real Simple Syndication)</title>
      <dc:creator>Parsa Frahani</dc:creator>
      <pubDate>Wed, 27 Dec 2023 21:08:48 +0000</pubDate>
      <link>https://forem.com/parsafarahani84/all-about-rss-real-simple-syndication-i6n</link>
      <guid>https://forem.com/parsafarahani84/all-about-rss-real-simple-syndication-i6n</guid>
      <description>&lt;p&gt;In the ever-evolving landscape of the internet, staying updated with the latest information can be overwhelming. Whether you're an avid reader, content creator, or developer, managing a multitude of websites for updates can be time-consuming. This is where Really Simple Syndication (RSS) steps in as a game-changer. In this blog post, we'll dive into the world of RSS, exploring its significance &amp;amp; functionalities.&lt;/p&gt;

&lt;h2&gt;
  
  
  How I found RSS?
&lt;/h2&gt;

&lt;p&gt;So from last month I was working on my own website &amp;amp; I was making a section that when you click on every platform the page will update &amp;amp; show all of my blog in DEV, Medium &amp;amp; LinkedIn. &lt;br&gt;
I talked to my teammate which is a backend developer, &amp;amp; he told me that he can build an API that can get all of the data &lt;strong&gt;BUT&lt;/strong&gt; it was illegal!&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%2Fcb94uhvzj3rgfd1y1jyn.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%2Fcb94uhvzj3rgfd1y1jyn.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So I went through lots of blogs &amp;amp; YouTube videos till one of the Senior developers told me that I should search for something name &lt;strong&gt;RSS Feed&lt;/strong&gt;. I got so excited when I worked with the API's that this platform provided for me to catch the feeds. &amp;amp; now I want to talk about this cool thing that I found! let's go.&lt;/p&gt;
&lt;h2&gt;
  
  
  Understanding RSS:
&lt;/h2&gt;

&lt;p&gt;RSS, which stands for "Really Simple Syndication" or "Rich Site Summary," is a web feed that allows users to access updates to online content in a standardized, machine-readable format. The fundamental idea behind RSS is to simplify the process of distributing and consuming information on the internet. Instead of manually visiting multiple websites to check for updates, users can subscribe to RSS feeds and receive consolidated updates in one place.&lt;/p&gt;
&lt;h2&gt;
  
  
  How RSS Works:
&lt;/h2&gt;

&lt;p&gt;RSS operates on a publish-subscribe model. Content publishers create an RSS feed containing a summary of their content, and users subscribe to these feeds using RSS readers. When new content is published on a website, the RSS feed is updated automatically. Subscribers receive these updates in their chosen RSS reader, providing a centralized hub for all the latest information.&lt;/p&gt;
&lt;h2&gt;
  
  
  Advantages of RSS:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Time Efficiency:&lt;br&gt;
RSS streamlines the process of content consumption, saving time by presenting updates in a centralized location.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Customization:&lt;br&gt;
Users have the flexibility to subscribe to specific feeds based on their interests, creating a personalized and tailored content experience.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reduced Information Overload:&lt;br&gt;
By aggregating content in one place, RSS helps users avoid information overload and focus on what matters most to them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Consistent Format:&lt;br&gt;
RSS feeds follow a standardized format, making it easier for developers to integrate and manipulate the data programmatically.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Does RSS Feeding have different functionality from Scripting a website?
&lt;/h2&gt;

&lt;p&gt;Yes, RSS feeding is a specific mechanism designed for content distribution and consumption with a focus on updates and subscriptions. Website scraping, on the other hand, is a broader term that encompasses various methods for extracting data from websites, and it's not necessarily focused on real-time updates or a standardized format.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Main goal of RSS Feeding:&lt;/strong&gt;&lt;br&gt;
The primary goal of RSS feeding is to streamline content distribution and consumption, making it easier for users to stay informed without visiting each website individually.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Main goal of Scraping a website:&lt;/strong&gt;&lt;br&gt;
Website scraping is more flexible and can be used for various purposes, such as gathering pricing information, monitoring changes on a website, or extracting data for research and analysis.&lt;/p&gt;
&lt;h2&gt;
  
  
  Let's see it in real project
&lt;/h2&gt;

&lt;p&gt;So we work with Medium API for getting feeds that you can access to all their RSS API's from &lt;strong&gt;&lt;a href="https://help.medium.com/hc/en-us/articles/214874118-Using-RSS-feeds-of-profiles-publications-and-topics" rel="noopener noreferrer"&gt;this &lt;/a&gt;&lt;/strong&gt; link.&lt;br&gt;
First look at the code below &amp;amp; then I'll explain what is going on.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [feedData, setFeedData] = useState([]);

  useEffect(() =&amp;gt; {
    const fetchData = async () =&amp;gt; {
      try {
        const response = await axios.get(
          "https://api.rss2json.com/v1/api.json",
          {
            params: {
              rss_url: "https://medium.com/feed/@parsafarahani",
            },
          }
        );

        // Assuming the data structure from the Medium RSS feed is stored in response.data.items
        setFeedData(response.data.items);
      } catch (error) {
        console.error("Error fetching Medium feed:", error);
      }
    };

    fetchData();
  }, []);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;First of all I made a state here to save &amp;amp; update my data so the site &amp;amp; data will always be update. as you can see I used UseEffect to update the data only one time when the browser loads. in our effect I called the current API that I get using chatGPT by Axios &amp;amp; give the feed API as params to it. then I update my state with the data I want &amp;amp; finally call the function.&lt;br&gt;
now I can all of my data from my Medium profile and use it in my components.&lt;/p&gt;

&lt;p&gt;You may ask me what exactly this "&lt;a href="https://api.rss2json.com/v1/api.json" rel="noopener noreferrer"&gt;https://api.rss2json.com/v1/api.json&lt;/a&gt;" API will do?&lt;br&gt;
Well this is an API endpoint provided by rss2json.com, and it converts RSS feeds into JSON format so with that we don't need to convert our data to JSON in our code.&lt;/p&gt;

&lt;h2&gt;
  
  
  At the end
&lt;/h2&gt;

&lt;p&gt;In conclusion, RSS helps you to get any data from others or your profile and use it as you want. but keep in mind that that website should support RSS feature so that you can use it.&lt;br&gt;
I hope this blog helped you to make more creative stuff! &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Any opinion? let me know in the comments🙏.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>react</category>
    </item>
    <item>
      <title>Clean Code Is Not Quick Code!💻</title>
      <dc:creator>Parsa Frahani</dc:creator>
      <pubDate>Wed, 13 Dec 2023 18:05:49 +0000</pubDate>
      <link>https://forem.com/parsafarahani84/clean-code-is-not-quick-code-5alm</link>
      <guid>https://forem.com/parsafarahani84/clean-code-is-not-quick-code-5alm</guid>
      <description>&lt;p&gt;Good code Manners!&lt;br&gt;
Most of us when we come back to our code after a 15m break, we can barely understand what is going on. or maybe if you change just one line the projects will stop working &amp;amp; you even don't know where you should fix. as Uncle Bob say's clean code is not quick code, it's smart code. so let me explain what I mean by &lt;strong&gt;smart&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%2F0fm6mpt4yvclyizi9ovf.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%2F0fm6mpt4yvclyizi9ovf.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What Is Smart Code
&lt;/h2&gt;

&lt;p&gt;Have you ever rushed into writing code &amp;amp; feel lost when you come back to it later? It happens to the best of us. Deciphering your own quick code can be like solving a puzzle. But what if there were seven simple things you could do to make your code easy to understand at a glance?&lt;/p&gt;

&lt;p&gt;Imagine looking at your code for just a moment and being able to continue where you left off. Picture your team feeling at ease while working on what you've created. In this blog, we'll explore these seven practices for smart &amp;amp; cleaner coding tips. Let's jump into the details:&lt;/p&gt;
&lt;h2&gt;
  
  
  1- Variable Naming:
&lt;/h2&gt;

&lt;p&gt;Consider the importance of naming variables, especially in larger projects. Let's dive into an example. Imagine you have a variable that you want to pass as a parameter to a function and then log it. Here's the initial code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const bb = "this is text";

const hrb = function (bbr) {
  console.log(bbr);
};

hrb(bb);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this snippet, the variable names (like bb and hrb) lack clear meaning. Now, picture having tons of code like this – it becomes a puzzle to figure out which function does what and which variable it's working with. now let's make this code better:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const text = "this is text";

const textHandler = function (data) {
  console.log(data);
};

textHandler(text);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;See? now we'll understand what is our function doing.&lt;/p&gt;

&lt;h2&gt;
  
  
  2- Small Refactors Are Way Better
&lt;/h2&gt;

&lt;p&gt;So you are just coding without think about what the h*ll am I coding or will my team or even myself understand that last week what I worked on. new features will add to the project &amp;amp; it is getting bigger &amp;amp; bigger. then you realize what a mess! I can't figure out what is this code doing &amp;amp; it also got so much complicated. so now you do even a worse mistake. you plane to refactor all the project.&lt;br&gt;
Think about it just for few seconds. wasn't it better to do small refactors as you go on with new features? you do a little coding then a little refactor and so on. so instead of ignoring your messy code, clean it as you go on!&lt;/p&gt;
&lt;h2&gt;
  
  
  3- Do Commenting Not Documenting
&lt;/h2&gt;

&lt;p&gt;They are so different from each other &amp;amp; still some people mix these two things up.&lt;br&gt;
You have to comment a little explonation about maybe a complicated functionality for your team or even yourself. not to explain the whole code! for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const text = "this is text";

// log what ever it gets
const textHandler = function (data) {
  console.log(data);
};

textHandler(text);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is commenting. now look at this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const text = "this is text";

// This function will get the data that we pass to it and log it in the console.
const textHandler = function (data) {
  console.log(data);
};

textHandler(text);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You are just overexplaining when you can simply just explain it with several words. this documenting will waste your team members &amp;amp; your time! try to explain the functionality a little bit &amp;amp; only do this if you think it will be confusing in the future.&lt;/p&gt;

&lt;h2&gt;
  
  
  4- Make Smart Functionalities For Your Project
&lt;/h2&gt;

&lt;p&gt;Ever seen code with too many functions doing single tasks, making it unnecessarily complicated? That's what we call "beginner mode" coding – doubling the code length without a good reason. I'm not saying we shouldn't break down code (we'll talk about that in a bit), but let's avoid making things needlessly complex.&lt;br&gt;
Imagine we're fetching data from an API, and for different button clicks, we want to show different things. Initially, our code looks 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;import React, { useState } from "react";

function ShowActivity() {
   const [data, setData] = useState("");
  const [key, setKey] = useState();

  async function ShowActivity() {
    const response = await fetch("https://www.boredapi.com/api/activity");
    const activity = await response.json();
    console.log(activity);
    setData(activity);
  }

  const ShowKey = function () {
    setKey(data.key);
  };

  return (
    &amp;lt;div className="parent"&amp;gt;
      &amp;lt;h1&amp;gt;{data.activity}&amp;lt;/h1&amp;gt;
      &amp;lt;h1&amp;gt;{key}&amp;lt;/h1&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; ShowActivity()}&amp;gt;Show Activity&amp;lt;/button&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; ShowKey()}&amp;gt;Show Status&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;in this React example we get a random activity and show it when we click the Show Activity button. this also will happen when we click the Key button too. it will show the activity key. It works, but we've created two separate functions for each button click, which is a bit repetitive. Now, let's make it simpler using one function:&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, { useState } from "react";

function ShowActivity() {
  const [data, setData] = useState("");
  const [key, setKey] = useState();

  async function Checker(type) {
    const response = await fetch("https://www.boredapi.com/api/activity");
    const jsonData = await response.json();
    console.log(jsonData);

    if (type === "Activity") {
      return setData(jsonData.activity);
    } else if (type === "Key") {
      return setKey(jsonData.key);
    }
  }

  return (
    &amp;lt;div className="parent"&amp;gt;
      &amp;lt;h1&amp;gt;{data}&amp;lt;/h1&amp;gt;
      &amp;lt;h1&amp;gt;{key}&amp;lt;/h1&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; Checker("Activity")}&amp;gt;Show Activity&amp;lt;/button&amp;gt;
      &amp;lt;button onClick={() =&amp;gt; Checker("Key")}&amp;gt;Show Key&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;As I said that not always put all the functionalities in one function is good! sometimes it can be so difficult to understand what is going on, so you have to devide the code to different functions &amp;amp; components. you might also don't see a lot of change in these two codes but the second code can be a way better &amp;amp; cleaner style than the first one, because I use a single function except two different functions for each event &amp;amp; if you want to use another parameter from API you just have to give it a type and check if the type is true rather than writing another function for just that one parameter.&lt;/p&gt;

&lt;h2&gt;
  
  
  5- Devide Responsibilities
&lt;/h2&gt;

&lt;p&gt;As I said sometimes you have to devide your code to smaller pieces. this division can help your team &amp;amp; also yourself to understand each function is doing what &amp;amp; you can edit or add new features to your project way easier. but you have to name your functions in a way that by reading it's name, you understand what this function is doing. for example look at this code:&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, { useState } from "react";

function App() {
  const [value, setValue] = useState("");
  const [data, setData] = useState([
    {
      activity: "Take a shower",
      description: "6AM in the morning",
      id: Math.random(),
      done: false,
      editable: false,
    },
  ]);

  const DoneHandler = function (todoId) {
    console.log(todoId);
  };

  const formHandler = function (e) {
    e.preventDefault();
    console.log(value);
    setData([
      {
        activity: value,
        description: "6AM in the morning",
        id: Math.random(),
        done: false,
        editable: false,
      },
      ...data,
    ]);

    setValue("");
  };

  return (
    &amp;lt;div className="main-container"&amp;gt;
      &amp;lt;form className="conatiner" onSubmit={formHandler}&amp;gt;
        &amp;lt;input
          type="text"
          value={value}
          onChange={(e) =&amp;gt; setValue(e.target.value)}
          className="container-input"
        /&amp;gt;
        &amp;lt;button&amp;gt;Add&amp;lt;/button&amp;gt;
      &amp;lt;/form&amp;gt;
      &amp;lt;div&amp;gt;
        {data.map((i) =&amp;gt; (
          &amp;lt;div className="todo" key={i.id} onClick={() =&amp;gt; DoneHandler(i.id)}&amp;gt;
            &amp;lt;h1&amp;gt;{i.activity}&amp;lt;/h1&amp;gt;
            &amp;lt;p&amp;gt;{i.description}&amp;lt;/p&amp;gt;
            &amp;lt;label&amp;gt;{i.key}&amp;lt;/label&amp;gt;
          &amp;lt;/div&amp;gt;
        ))}
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;It's so hard to figure out what exactly this code is doing. but  as soon as I start to folder my code &amp;amp; components right (that I talk about in next one), reading the code get so much simpler. 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%2F2jxep67ggj4hdnwtln2i.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%2F2jxep67ggj4hdnwtln2i.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
and devide code to small piece's. I do the functionalities here:&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 { useState } from "react";

function TMain(props) {
  const [value, setValue] = useState("");
  const [data, setData] = useState([
    {
      activity: "Take a shower",
      id: Math.random(),
      done: false,
      editable: false,
    },
  ]);

  const formHandler = function (e) {
    e.preventDefault();
    setData([
      {
        activity: value,
        description: "6AM in the morning",
        id: Math.random(),
        done: false,
        editable: false,
      },
      ...data,
    ]);

    setValue("");
  };

  return (
    &amp;lt;div className="main-container"&amp;gt;
      &amp;lt;form className="conatiner" onSubmit={formHandler}&amp;gt;
        &amp;lt;input
          type="text"
          value={value}
          onChange={(e) =&amp;gt; setValue(e.target.value)}
          className="container-input"
        /&amp;gt;
        &amp;lt;button&amp;gt;Add&amp;lt;/button&amp;gt;
      &amp;lt;/form&amp;gt;
      &amp;lt;div&amp;gt;
        {data.map((i) =&amp;gt; (
          &amp;lt;div
            className="todo"
            key={i.id}
            onClick={() =&amp;gt; props.DoneHandler(i.id)}
          &amp;gt;
            &amp;lt;h1&amp;gt;{i.activity}&amp;lt;/h1&amp;gt;
            &amp;lt;label&amp;gt;{i.key}&amp;lt;/label&amp;gt;
          &amp;lt;/div&amp;gt;
        ))}
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default TMain;

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

&lt;/div&gt;



&lt;p&gt;Then if anything click I log that It has been done here:&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, { useState } from "react";
import TMain from "../Todo-Main/TMain";

function TFunc() {
  const DoneHandler = function (todoId) {
    console.log(`${todoId} Has been done`);
  };

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;TMain DoneHandler={DoneHandler} /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

export default TFunc;

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

&lt;/div&gt;



&lt;p&gt;&amp;amp; finally I use it in my App.jsx:&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 TFunc from "./Components/Todo-Functionality/TFunc";

function App() {
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;TFunc /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;p&gt;In the store.js you can save your data in browser cache using Redux or Jotai or any library that you like.&lt;br&gt;
This is an small example but in bigger projects it can really life saver!&lt;/p&gt;

&lt;h2&gt;
  
  
  6- Be Better At Foldering Your Components
&lt;/h2&gt;

&lt;p&gt;Foldering is so important to find your code. for example think I foldered my components 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%2Fgtsfqqpk7gzhhxsr80qy.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%2Fgtsfqqpk7gzhhxsr80qy.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
I really don't know each component is responsible for what task so I have to put a lot of time to read the code in each file &amp;amp; see if that is what I'm looking for. but I can manage it in a better way:&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%2Fw0gz94fc5i6ij3vpuzje.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%2Fw0gz94fc5i6ij3vpuzje.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Now by just reading the folder's name I'll understand what each file is doing.&lt;/p&gt;

&lt;h2&gt;
  
  
  7- Do You Know How To Handle Errors?
&lt;/h2&gt;

&lt;p&gt;So lot's of beginners just code without thinking about handling errors. but a pro coder think about this one too. &lt;br&gt;
If our app runs to an error, the whole project will stops &amp;amp; you will see a blank page. this is so awful for user experience. you have to manage error somehow that the user still use the website. you can use try/catch functionality or error boundaries or use the react error boundaries package or any way that you are comfortable with.&lt;/p&gt;

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

&lt;p&gt;What I tried to talk in this blog was all about experiences that most of programmers as well as me had all the time, also the most popular way that all of the programmers do to keep they code creative &amp;amp; clean is SOLID Principles. so it have 5 stages that help you write better code. if you are interested you can read about it &lt;a href="https://medium.com/backticks-tildes/the-s-o-l-i-d-principles-in-pictures-b34ce2f1e898" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;br&gt;
**&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Was this blog helpful?&lt;br&gt;
Or can it be better?&lt;br&gt;
Let me know in the comments🙏.&lt;br&gt;
**&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>react</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
