<?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: Amrita-padhy</title>
    <description>The latest articles on DEV Community by Amrita-padhy (@amritapadhy).</description>
    <link>https://dev.to/amritapadhy</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%2F867601%2F69e62bdd-7fba-478a-a4ab-3005114650c3.jpeg</url>
      <title>DEV Community: Amrita-padhy</title>
      <link>https://dev.to/amritapadhy</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/amritapadhy"/>
    <language>en</language>
    <item>
      <title>[Boost]</title>
      <dc:creator>Amrita-padhy</dc:creator>
      <pubDate>Tue, 12 Aug 2025 09:34:09 +0000</pubDate>
      <link>https://dev.to/amritapadhy/-4nli</link>
      <guid>https://dev.to/amritapadhy/-4nli</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/amritapadhy/my-personal-experience-with-the-changing-from-uncontrolled-input-to-controlled-error-1cp0" class="crayons-story__hidden-navigation-link"&gt;My Personal Experience with the “Changing from Uncontrolled input to Controlled” Error&lt;/a&gt;


  &lt;div class="crayons-story__body crayons-story__body-full_post"&gt;
    &lt;div class="crayons-story__top"&gt;
      &lt;div class="crayons-story__meta"&gt;
        &lt;div class="crayons-story__author-pic"&gt;

          &lt;a href="/amritapadhy" class="crayons-avatar  crayons-avatar--l  "&gt;
            &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F867601%2F69e62bdd-7fba-478a-a4ab-3005114650c3.jpeg" alt="amritapadhy profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/amritapadhy" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Amrita-padhy
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Amrita-padhy
                
              
              &lt;div id="story-author-preview-content-2769494" class="profile-preview-card__content crayons-dropdown branded-7 p-4 pt-0"&gt;
                &lt;div class="gap-4 grid"&gt;
                  &lt;div class="-mt-4"&gt;
                    &lt;a href="/amritapadhy" class="flex"&gt;
                      &lt;span class="crayons-avatar crayons-avatar--xl mr-2 shrink-0"&gt;
                        &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F867601%2F69e62bdd-7fba-478a-a4ab-3005114650c3.jpeg" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Amrita-padhy&lt;/span&gt;
                    &lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="print-hidden"&gt;
                    
                      Follow
                    
                  &lt;/div&gt;
                  &lt;div class="author-preview-metadata-container"&gt;&lt;/div&gt;
                &lt;/div&gt;
              &lt;/div&gt;
            &lt;/div&gt;

          &lt;/div&gt;
          &lt;a href="https://dev.to/amritapadhy/my-personal-experience-with-the-changing-from-uncontrolled-input-to-controlled-error-1cp0" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Aug 12 '25&lt;/time&gt;&lt;span class="time-ago-indicator-initial-placeholder"&gt;&lt;/span&gt;&lt;/a&gt;
        &lt;/div&gt;
      &lt;/div&gt;

    &lt;/div&gt;

    &lt;div class="crayons-story__indention"&gt;
      &lt;h2 class="crayons-story__title crayons-story__title-full_post"&gt;
        &lt;a href="https://dev.to/amritapadhy/my-personal-experience-with-the-changing-from-uncontrolled-input-to-controlled-error-1cp0" id="article-link-2769494"&gt;
          My Personal Experience with the “Changing from Uncontrolled input to Controlled” Error
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/webdev"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;webdev&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/react"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;react&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/beginners"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;beginners&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/programming"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;programming&lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="crayons-story__bottom"&gt;
        &lt;div class="crayons-story__details"&gt;
          &lt;a href="https://dev.to/amritapadhy/my-personal-experience-with-the-changing-from-uncontrolled-input-to-controlled-error-1cp0" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left"&gt;
            &lt;div class="multiple_reactions_aggregate"&gt;
              &lt;span class="multiple_reactions_icons_container"&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/sparkle-heart-5f9bee3767e18deb1bb725290cb151c25234768a0e9a2bd39370c382d02920cf.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
              &lt;/span&gt;
              &lt;span class="aggregate_reactions_counter"&gt;2&lt;span class="hidden s:inline"&gt; reactions&lt;/span&gt;&lt;/span&gt;
            &lt;/div&gt;
          &lt;/a&gt;
            &lt;a href="https://dev.to/amritapadhy/my-personal-experience-with-the-changing-from-uncontrolled-input-to-controlled-error-1cp0#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              Comments


              &lt;span class="hidden s:inline"&gt;Add Comment&lt;/span&gt;
            &lt;/a&gt;
        &lt;/div&gt;
        &lt;div class="crayons-story__save"&gt;
          &lt;small class="crayons-story__tertiary fs-xs mr-2"&gt;
            2 min read
          &lt;/small&gt;
            
              &lt;span class="bm-initial"&gt;
                

              &lt;/span&gt;
              &lt;span class="bm-success"&gt;
                

              &lt;/span&gt;
            
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;/div&gt;


</description>
      <category>webdev</category>
      <category>react</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>My Personal Experience with the “Changing from Uncontrolled input to Controlled” Error</title>
      <dc:creator>Amrita-padhy</dc:creator>
      <pubDate>Tue, 12 Aug 2025 09:32:55 +0000</pubDate>
      <link>https://dev.to/amritapadhy/my-personal-experience-with-the-changing-from-uncontrolled-input-to-controlled-error-1cp0</link>
      <guid>https://dev.to/amritapadhy/my-personal-experience-with-the-changing-from-uncontrolled-input-to-controlled-error-1cp0</guid>
      <description>&lt;p&gt;When I first started building forms in my current project, I ran into this error:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hook.js:608 A component is changing an uncontrolled input to be controlled. This is likely caused by the value changing from undefined to a defined value, which should not happen. Decide between using a controlled or uncontrolled input element for the lifetime of the component.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It appeared in my browser console like an angry red flag every time my form loaded.&lt;/p&gt;

&lt;p&gt;At first, I didn’t fully understand why React was upset. But after digging in, I realized the issue was this:&lt;/p&gt;

&lt;p&gt;The root cause&lt;br&gt;
An uncontrolled input becomes controlled if its value prop changes from undefined to a defined value after the first render.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example of the problem:&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;&amp;lt;input value={formData.name} onChange={handleChange} /&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;If formData.name is undefined at first (maybe the data is still loading), React treats the input as uncontrolled.&lt;br&gt;
But when the data finally loads and formData.name becomes "User", React sees that as switching from uncontrolled → controlled.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How I fixed it&lt;/strong&gt;&lt;br&gt;
I ensured the value was always defined, even before data loaded:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input
  value={formData.name ?? ""}
  onChange={handleChange}
/&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;Or, when using React Hook Form, I provided defaultValue explicitly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;input {...register("name")} defaultValue="" /&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;For controlled components wrapped with Controller:&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;Controller
  name="username"
  control={control}
  defaultValue="" // important!
  render={({ field }) =&amp;gt; &amp;lt;InputText {...field} /&amp;gt;}
/&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Lesson learned&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Always decide upfront if your input will be controlled or uncontrolled.&lt;/li&gt;
&lt;li&gt;If controlled, initialize value to an empty string (or a sensible default) instead of letting it be undefined.&lt;/li&gt;
&lt;li&gt;If uncontrolled, don’t bind a value prop at all — use defaultValue or refs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This small detail saved me hours of debugging and also made me appreciate why libraries like React Hook Form handle defaults so gracefully.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>react</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Understanding &amp; Fixing FOUC in Next.js App Router (2025 Guide)</title>
      <dc:creator>Amrita-padhy</dc:creator>
      <pubDate>Wed, 09 Apr 2025 13:34:26 +0000</pubDate>
      <link>https://dev.to/amritapadhy/understanding-fixing-fouc-in-nextjs-app-router-2025-guide-ojk</link>
      <guid>https://dev.to/amritapadhy/understanding-fixing-fouc-in-nextjs-app-router-2025-guide-ojk</guid>
      <description>&lt;p&gt;FOUC (Flash of Unstyled Content) is a common but frustrating visual glitch that can happen in modern React apps — especially in Next.js App Router — where your layout appears unstyled briefly during page load or refresh.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is FOUC?
&lt;/h2&gt;

&lt;p&gt;FOUC happens when the browser renders HTML before your CSS or styles are applied — resulting in a flash of unstyled or partially styled elements.&lt;/p&gt;

&lt;p&gt;In SSR frameworks like Next.js, this often happens due to mismatches between the server-rendered HTML and client-rendered UI.&lt;/p&gt;

&lt;h2&gt;
  
  
  Symptoms of FOUC
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;On refresh, your UI shows raw HTML (unstyled) for a moment before styles kick in.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CSS variables like --primary-color aren't applied until the page fully loads.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;-The warning: &lt;code&gt;Warning: A tree hydrated but some attributes of the server rendered HTML didn't match the client properties.&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Common Causes of FOUC in Next.js App Router
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Dynamic Theming (e.g., per-tenant styles via Redux/localStorage)&lt;/strong&gt;
When you load styles after hydration, like setting a theme color based on the current tenant:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;useEffect(() =&amp;gt; {
  document.documentElement.style.setProperty('--primary-color', tenantColor);
}, []);

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

&lt;/div&gt;


&lt;p&gt;This runs only after the page loads, so the browser renders unstyled HTML first → FOUC.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Using Date.now(), Math.random(), or typeof window in shared components&lt;/strong&gt;&lt;br&gt;
These values differ between server and client → causes hydration mismatch, and sometimes FOUC.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;3rd-Party CSS Libraries Not Loaded Early Enough&lt;/strong&gt;&lt;br&gt;
If you're importing styles from UI libraries (e.g., PrimeReact, Tailwind CSS) inside components, they are loaded too late — causing unstyled content to flash on screen momentarily.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Inside a component file (not recommended)
import 'primereact/resources/themes/lara-light-indigo/theme.css';

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

&lt;/div&gt;

&lt;h2&gt;
  
  
  How to Fix FOUC in Next.js App Router
&lt;/h2&gt;

&lt;p&gt;1.&lt;strong&gt;Always Import Global CSS in layout.tsx&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; app/layout.tsx
import "primeflex/primeflex.css";
import "primereact/resources/themes/lara-light-indigo/theme.css";
import "./globals.scss"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This ensures styles are loaded before your app renders.&lt;/p&gt;

&lt;p&gt;2.&lt;strong&gt;Provide Fallback Theme Styles in globals.scss&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;:root {
  --primary-color: #ff8c00; // fallback before tenant-specific color is applied
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This avoids flashing unstyled buttons or layouts before tenant styles load.&lt;/p&gt;

&lt;p&gt;3.&lt;strong&gt;Wrap Client-Side Logic in a Hydration Guard&lt;/strong&gt;&lt;br&gt;
Use this in a client component (e.g., HydrationWrapper.tsx):&lt;br&gt;
&lt;/p&gt;

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

export default function HydrationWrapper({ children }) {
  const [mounted, setMounted] = useState(false);

  useEffect(() =&amp;gt; {
    setMounted(true);
  }, []);

  if (!mounted) return null;

  return &amp;lt;&amp;gt;{children}&amp;lt;/&amp;gt;;
}

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

&lt;/div&gt;



&lt;p&gt;Then use it in layout.tsx:&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;body&amp;gt;
  &amp;lt;HydrationWrapper&amp;gt;
    {children}
  &amp;lt;/HydrationWrapper&amp;gt;
&amp;lt;/body&amp;gt;

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

&lt;/div&gt;



&lt;p&gt;This delays rendering until the client takes control — preventing mismatches.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bonus: Avoid These Anti-Patterns&lt;/strong&gt;&lt;br&gt;
❌ Avoid dynamic CSS imports.&lt;br&gt;
❌ Don’t use Date.now() or Math.random() directly in render.&lt;br&gt;
❌ Don’t read from localStorage or window in server components.&lt;br&gt;
❌ Don’t conditionally render &lt;code&gt;&amp;lt;html&amp;gt; or &amp;lt;head&amp;gt;&lt;/code&gt;in client components.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FOUC is annoying — but totally fixable in Next.js App Router. By carefully separating your server logic from client-specific theming or rendering, you can eliminate style flashes, avoid hydration warnings, and ensure a polished user experience.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>nextjs</category>
      <category>beginners</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Understanding onClick in React: onClick={handleClick}, onClick={handleClick()}, and onClick={() =&gt; handleClick()}</title>
      <dc:creator>Amrita-padhy</dc:creator>
      <pubDate>Sat, 21 Dec 2024 05:50:35 +0000</pubDate>
      <link>https://dev.to/amritapadhy/understanding-onclick-in-react-onclickhandleclick-onclickhandleclick-and-onclick--4k71</link>
      <guid>https://dev.to/amritapadhy/understanding-onclick-in-react-onclickhandleclick-onclickhandleclick-and-onclick--4k71</guid>
      <description>&lt;p&gt;When working with event handlers in React, the onClick attribute is one of the most commonly used props. It allows us to define what happens when a user clicks on a button or another interactive element. However, there are multiple ways to define the event handler, and the differences between them can sometimes be confusing.&lt;/p&gt;

&lt;p&gt;In this blog, we will break down three common patterns:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;onClick={handleClick}&lt;/li&gt;
&lt;li&gt;onClick={handleClick()}&lt;/li&gt;
&lt;li&gt;onClick={() =&amp;gt; handleClick()}&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;1. onClick={handleClick}&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is the simplest and most common way to assign an event handler in React. Here, you are directly passing a reference to the handleClick function.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How It Works:&lt;/strong&gt;&lt;br&gt;
React saves the function reference and invokes it when the event occurs.&lt;/p&gt;

&lt;p&gt;The function is not immediately called during render; it is executed only when the user interacts with the element.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&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;function handleClick() {
  console.log('Button clicked');
}

&amp;lt;button onClick={handleClick}&amp;gt;Click Me&amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Use this pattern when you do not need to pass any arguments or add additional logic to the event handler.&lt;/p&gt;

&lt;p&gt;This is the most efficient and straightforward way to handle events.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Points:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No function is created during every render, making it better for performance.&lt;/p&gt;

&lt;p&gt;The code is cleaner and easier to read.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. onClick={handleClick()}&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At first glance, this may look similar to the previous example, but it behaves very differently. Here, you are immediately invoking the handleClick function during render and passing its return value to the onClick prop.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How It Works:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When the component renders, handleClick() is executed immediately.&lt;/p&gt;

&lt;p&gt;The return value of handleClick() is then assigned to the onClick attribute. If the return value is not a function, this will cause an error.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&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;function handleClick() {
  console.log('This runs immediately!');
}

&amp;lt;button onClick={handleClick()}&amp;gt;Click Me&amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What Happens:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As soon as the component renders, "This runs immediately!" is logged to the console.&lt;/p&gt;

&lt;p&gt;The onClick handler will not work as intended because the function has already been executed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is rarely useful in React and is often the result of a mistake.&lt;/p&gt;

&lt;p&gt;Avoid using this pattern unless you explicitly need the function to run during render (which is uncommon).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Points:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This does not bind the function to the event; instead, it executes it during render.&lt;/p&gt;

&lt;p&gt;Misusing this pattern can lead to unintended side effects and bugs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. onClick={() =&amp;gt; handleClick()}&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This pattern uses an arrow function to wrap the handleClick function call. When the user clicks the button, the arrow function is executed, and it then calls handleClick.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How It Works:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A new function (the arrow function) is created on every render.&lt;/p&gt;

&lt;p&gt;When the button is clicked, the arrow function is executed, and it calls handleClick.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example:&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;function handleClick() {
  console.log('Button clicked');
}

&amp;lt;button onClick={() =&amp;gt; handleClick()}&amp;gt;Click Me&amp;lt;/button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Use Case:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Use this pattern when you need to pass arguments to the handleClick function or when additional logic is required.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example with Arguments:&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;function handleClick(message) {
  console.log(message);
}

&amp;lt;button onClick={() =&amp;gt; handleClick('Hello, World!')}&amp;gt;Click
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Key Points:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This creates a new function on every render, which may impact performance in large or frequently updated components.&lt;/p&gt;

&lt;p&gt;Use it only when you need additional functionality, such as passing arguments or chaining multiple actions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Best Practices&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Use onClick={handleClick} whenever possible:&lt;/p&gt;

&lt;p&gt;.It is the cleanest and most efficient way to handle events.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use onClick={() =&amp;gt; handleClick()} sparingly:&lt;/p&gt;

&lt;p&gt;.Only use this pattern when passing arguments or additional logic is necessary.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Avoid onClick={handleClick()} unless explicitly required:&lt;br&gt;&lt;br&gt;
.This pattern is generally a mistake and can lead to unexpected behavior.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;Understanding the differences between these three patterns can help you write cleaner, more efficient React code. Always prefer onClick={handleClick} for simple use cases, and reach for onClick={() =&amp;gt; handleClick()} only when absolutely necessary. By avoiding common pitfalls like onClick={handleClick()}, you can ensure your event handlers work as intended and avoid unnecessary bugs.&lt;/p&gt;

</description>
      <category>react</category>
      <category>beginners</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Enhancing React Apps: Server Image Preview Component</title>
      <dc:creator>Amrita-padhy</dc:creator>
      <pubDate>Sat, 22 Jun 2024 11:32:32 +0000</pubDate>
      <link>https://dev.to/amritapadhy/enhancing-react-apps-server-image-preview-component-1pn0</link>
      <guid>https://dev.to/amritapadhy/enhancing-react-apps-server-image-preview-component-1pn0</guid>
      <description>&lt;p&gt;In this blog post, we'll walk through the process of creating a custom file preview component using React. We won't rely on any third-party libraries, ensuring you gain a deeper understanding of how to handle files directly in JavaScript. By the end of this tutorial, you'll be able to preview images, text files, xlxs files, pdf files in your React application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const PdfViewer = ({ url }) =&amp;gt; {
  const iframeRef = useRef(null);
  const interval = useRef();

  const pdfUrl = createGdocsUrl(url);

  const [loaded, setLoaded] = useState(false);

  const clearCheckingInterval = () =&amp;gt; {
    clearInterval(interval.current);
  };

  const onIframeLoaded = () =&amp;gt; {
    clearCheckingInterval();
    setLoaded(true);
  };

  useEffect(() =&amp;gt; {
    interval.current = setInterval(() =&amp;gt; {
      try {
        // google docs page is blank (204), hence we need to reload the iframe.
        if (iframeRef.current.contentWindow.document.body.innerHTML === '') {
          iframeRef.current.src = pdfUrl;
        }
      } catch (e) {
        // google docs page is being loaded, but will throw CORS error.
        // it mean that the page won't be blank and we can remove the checking interval.
        onIframeLoaded();
      }
    }, 4000); // 4000ms is reasonable time to load 2MB document

    return clearCheckingInterval;
  }, []);

  return (
    &amp;lt;div className={css['pdf-iframe__wrapper']}&amp;gt;
      &amp;lt;iframe
        ref={iframeRef}
        className={css['pdf-iframe__inside']}
        frameBorder="no"
        onLoad={onIframeLoaded}
        src={pdfUrl}
        title="PDF Viewer"
      /&amp;gt;

      {!loaded &amp;amp;&amp;amp; (
        &amp;lt;div className={css['pdf-iframe__skeleton']}&amp;gt;
          &amp;lt;Skeleton height="100%" rectRadius={{ rx: 0, ry: 0 }} width="100%" /&amp;gt;
        &amp;lt;/div&amp;gt;
      )}
    &amp;lt;/div&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this blog post, we created a custom file preview component using React without relying on any third-party libraries. We learned how to   read file contents, and display previews .&lt;/p&gt;

&lt;p&gt;Potential enhancements include adding support for more file types, improving the styling, and handling errors more gracefully. Happy coding!&lt;/p&gt;

&lt;p&gt;Feel free to reach out in the comments if you have any questions or suggestions!&lt;/p&gt;

</description>
      <category>react</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Exploring HTTP Protocol: Can You Send a GET Call with a POST Method ? and Vice Versa</title>
      <dc:creator>Amrita-padhy</dc:creator>
      <pubDate>Tue, 09 Apr 2024 05:53:42 +0000</pubDate>
      <link>https://dev.to/amritapadhy/exploring-http-protocol-can-you-send-a-get-call-with-a-post-method-and-vice-versa-5g0i</link>
      <guid>https://dev.to/amritapadhy/exploring-http-protocol-can-you-send-a-get-call-with-a-post-method-and-vice-versa-5g0i</guid>
      <description>&lt;p&gt;In a recent web development job interview, I faced an unexpected question that led me to dive deep into HTTP methods. The interviewer asked: "Can you use the POST method to send a GET call, and vice versa?" This question caught me off guard, but it made me realize how crucial understanding HTTP methods is in web development.&lt;/p&gt;

&lt;p&gt;In this blog post, I'll share my journey of exploring this question, from initial surprise to valuable insights gained through research and reflection. By understanding the nuances of HTTP methods, we can better grasp the basics of web development and API design.&lt;/p&gt;

&lt;h2&gt;
  
  
  GET Request with POST Method:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A GET request is typically used for fetching data from a server. It's meant to be idempotent, meaning making the same request multiple times should have the same effect as making it once.&lt;/li&gt;
&lt;li&gt;POST requests, on the other hand, are intended for submitting data to the server to be processed. They may have side effects, such as updating a database or creating a new resource.&lt;/li&gt;
&lt;li&gt;Sending a GET request with a POST method (by including parameters in the request body instead of the URL) violates the HTTP specification and can lead to confusion and unexpected behavior. It's not a recommended practice.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  POST Request with GET Method:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Similarly, while you can technically send a POST request with a GET method (by including parameters in the URL instead of the request body), it's also not recommended.&lt;/li&gt;
&lt;li&gt;GET requests are meant for retrieving data and should not have side effects on the server.&lt;/li&gt;
&lt;li&gt;POST requests, on the other hand, are intended for actions that may change the state of the server or create new resources.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In both cases, using the wrong method for the intended purpose can lead to issues with interoperability, confusion, and unexpected behavior.&lt;/p&gt;

&lt;p&gt;Therefore, it's essential to use the appropriate HTTP method based on the semantics of the request:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use GET for retrieving data from the server.&lt;/li&gt;
&lt;li&gt;Use POST for submitting data to the server to be processed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While it's interesting to understand that HTTP methods are flexible in this way, it's crucial to adhere to best practices for clarity, consistency, and maintaining the integrity of  web applications.&lt;/p&gt;

&lt;p&gt;You can technically send a GET request with a POST method and vice versa, but it's generally not recommended or considered good practice&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>http</category>
      <category>beginners</category>
    </item>
    <item>
      <title>TypeScript Journey: A Beginner's Journey into Typed JavaScript</title>
      <dc:creator>Amrita-padhy</dc:creator>
      <pubDate>Mon, 18 Mar 2024 16:12:41 +0000</pubDate>
      <link>https://dev.to/amritapadhy/typescript-journey-a-beginners-journey-into-typed-javascript-37l7</link>
      <guid>https://dev.to/amritapadhy/typescript-journey-a-beginners-journey-into-typed-javascript-37l7</guid>
      <description>&lt;p&gt;&lt;strong&gt;TypeScript: An Overview&lt;/strong&gt;&lt;br&gt;
TypeScript is a programming language built on top of JavaScript. Every JavaScript file is a valid TypeScript file, but TypeScript adds some powerful features that enhance the robustness and maintainability of applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is TypeScript?&lt;/strong&gt;&lt;br&gt;
TypeScript addresses the shortcomings of JavaScript by introducing features like static typing. In static typing, variables can be declared with a specific type, such as a number or string. Unlike dynamic typing found in languages like JavaScript, TypeScript provides type checking at compile time.&lt;/p&gt;

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

&lt;p&gt;&lt;strong&gt;Benefits of TypeScript&lt;/strong&gt;&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Static Typing: Enables catching type-related errors early in the development process.&lt;/li&gt;
&lt;li&gt;Code Compilation: TypeScript code is compiled into JavaScript, making it compatible with all browsers.&lt;/li&gt;
&lt;li&gt;Refactoring: Easier code refactoring due to the availability of type information.&lt;/li&gt;
&lt;li&gt;Short-hand Notation: Provides concise syntax for common patterns, improving code readability and maintainability.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Drawbacks of TypeScript&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Compilation Step: Requires a compilation step before running the code, adding an extra layer of complexity to the development process.&lt;/li&gt;
&lt;li&gt;Discipline in Coding: Developers need to adhere to TypeScript's typing rules and guidelines, which may require additional effort and discipline.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Compilation Process&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To use TypeScript in a web application, the TypeScript code must be transpiled into JavaScript using a TypeScript compiler. This transpilation process ensures that the resulting JavaScript code is compatible with all browsers.&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Switch Vs. If else</title>
      <dc:creator>Amrita-padhy</dc:creator>
      <pubDate>Tue, 12 Mar 2024 05:00:57 +0000</pubDate>
      <link>https://dev.to/amritapadhy/switch-vs-if-else-1aig</link>
      <guid>https://dev.to/amritapadhy/switch-vs-if-else-1aig</guid>
      <description>&lt;p&gt;As I learned JavaScript, I often found myself stuck between using switch or if-else statements. It's a common dilemma for beginners. Let's dive into these two choices together, exploring what they offer and when to use each one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Readability&lt;/strong&gt;: For simple cases where you're testing the value of a single variable against multiple conditions, switch statements can often be more readable and maintainable. They provide a clear structure for handling multiple cases.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;switch (day) {&lt;br&gt;
  case 'Monday':&lt;br&gt;
  case 'Tuesday':&lt;br&gt;
  case 'Wednesday':&lt;br&gt;
  case 'Thursday':&lt;br&gt;
  case 'Friday':&lt;br&gt;
    console.log('Weekday');&lt;br&gt;
    break;&lt;br&gt;
  case 'Saturday':&lt;br&gt;
  case 'Sunday':&lt;br&gt;
    console.log('Weekend');&lt;br&gt;
    break;&lt;br&gt;
  default:&lt;br&gt;
    console.log('Invalid day');&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Performance&lt;/strong&gt;: In JavaScript, the performance difference between switch and if-else statements is generally negligible. Modern JavaScript engines are quite efficient in optimizing both constructs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Flexibility&lt;/strong&gt;: if-else statements provide more flexibility for complex conditional logic. You can use logical operators and test multiple conditions within a single if or else if block, which can sometimes be more concise and expressive.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;if (score &amp;gt;= 90) {&lt;br&gt;
  console.log('A');&lt;br&gt;
} else if (score &amp;gt;= 80) {&lt;br&gt;
  console.log('B');&lt;br&gt;
} else if (score &amp;gt;= 70) {&lt;br&gt;
  console.log('C');&lt;br&gt;
} else {&lt;br&gt;
  console.log('D');&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Handling Different Types of Conditions&lt;/strong&gt;: if-else statements are more versatile when dealing with conditions beyond simple value comparisons, such as ranges or boolean expressions.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;if (age &amp;lt; 18) {&lt;br&gt;
  console.log('Minor');&lt;br&gt;
} else if (age &amp;gt;= 18 &amp;amp;&amp;amp; age &amp;lt; 65) {&lt;br&gt;
  console.log('Adult');&lt;br&gt;
} else {&lt;br&gt;
  console.log('Senior');&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here’s the general layout of an if-else statement verses the switch case:&lt;/strong&gt;&lt;br&gt;
This is the general syntax of an if-else statement:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (condition1) { //Body of if }

else if (condition2) { //Body of if }

else if (condition3) { //Body of if }

else { //default if all conditions return false }

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

&lt;/div&gt;



&lt;p&gt;And this is the general syntax for switch:&lt;/p&gt;

&lt;p&gt;switch ( variable )&lt;br&gt;
&lt;/p&gt;

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

case &amp;lt;variable value1&amp;gt;: //Do Something

break;

case &amp;lt;variable value2&amp;gt;://Do Something

break;

default: //Default will perform if all case’s fail

break;

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

&lt;/div&gt;



&lt;p&gt;The if-else ladder is of type strict condition check, while switch is of type jump value catching.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Some key advantages of switch over if-else ladder:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A switch statement works much faster than an equivalent  if-else ladder. It’s because the compiler generates a jump table for a switch during compilation. As a result, during execution, instead of checking which case is satisfied, it only decides which case has to be executed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;It’s more readable compared to if-else statements.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the end, the choice is yours and I hope this blog helps lead you in the right path to making the most informed decision when to use an if-else statement verses a switch case!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>react</category>
      <category>reactjsdevelopment</category>
    </item>
    <item>
      <title>JavaScript Array Hacks: Deleting Elements Like a Pro</title>
      <dc:creator>Amrita-padhy</dc:creator>
      <pubDate>Mon, 25 Dec 2023 11:15:44 +0000</pubDate>
      <link>https://dev.to/amritapadhy/javascript-array-hacks-deleting-elements-like-a-pro-458h</link>
      <guid>https://dev.to/amritapadhy/javascript-array-hacks-deleting-elements-like-a-pro-458h</guid>
      <description>&lt;p&gt;&lt;strong&gt;JavaScript&lt;/strong&gt; array is a single variable that is used to store the elements or a group of values.&lt;/p&gt;

&lt;p&gt;You can add or remove elements from the array in any position. &lt;/p&gt;

&lt;p&gt;Here, we will discuss different ways to remove elements from the array. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Methods to Remove Elements from JavaScript Array:&lt;/strong&gt;&lt;br&gt;
There are many methods that are used to remove elements from JavaScript array which are discussed below&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using the pop() method&lt;/li&gt;
&lt;li&gt;Using the shift() method&lt;/li&gt;
&lt;li&gt;Using the splice() method&lt;/li&gt;
&lt;li&gt;Using the filter() method&lt;/li&gt;
&lt;li&gt;Using Delete Operator&lt;/li&gt;
&lt;li&gt;Using a simple for() loop and a new array&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  1: using the &lt;strong&gt;pop()&lt;/strong&gt; method:
&lt;/h2&gt;

&lt;p&gt;This method is used to remove the last element of the array and returns the removed element. This function decreases the length of the array by 1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const array = ["apple", "mango", "banana", "orange"];
  const popedArray = array.pop();
  console.log(popedArray);
  console.log(array);
  // output =  orange
  // output =  ['apple', 'mango', 'banana']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2: using the &lt;strong&gt;shift()&lt;/strong&gt; method:
&lt;/h2&gt;

&lt;p&gt;This method is used to remove the first element of the array and reduce the size of the original array by 1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; const array = ["apple", "mango", "banana", "orange"];
  const shiftedArray = array.shift();
  console.log(shiftedArray);
  console.log(array);
  // output =  apple
  // output =   ['mango', 'banana', 'orange']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3: using the &lt;strong&gt;splice()&lt;/strong&gt; method:
&lt;/h2&gt;

&lt;p&gt;This method is used to modify the contents of an array by removing the existing elements and/or adding new elements. To remove elements by the splice() method you can specify the elements in different ways.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  const array = ["apple", "mango", "banana", "orange"];
  const splicedArray = array.splice(2, 1);
  console.log(splicedArray);   // output =  ['banana']
  console.log(array); // output =   ['apple', 'mango', 'orange']
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;here in this example array.splice(2, 1) , 2 is index of deleting element and 1 is number of elements you want to delete .&lt;/p&gt;

&lt;h2&gt;
  
  
  4: using the &lt;strong&gt;filter()&lt;/strong&gt; method:
&lt;/h2&gt;

&lt;p&gt;This method is used to create a new array from a given array consisting of only those elements from the given array which satisfy a condition set by the argument function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; function isPositive(value) {
    return value &amp;gt; 0;
  }
  const array = [1, 3, 45, 124, -1, 0, 125];
  const filtereddArray = array.filter(isPositive);
  console.log(filtereddArray); // output =  [1, 3, 45, 124, 125]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5: using the &lt;strong&gt;Delete Operator&lt;/strong&gt;:
&lt;/h2&gt;

&lt;p&gt;Use the delete operator to remove elements from a JavaScript array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const array = [1, 3, 45, 20];
  const deleted = delete array[2];
  console.log(deleted); // output =  true
  console.log(array); // output =  [1, 3, empty, 20]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6: using the &lt;strong&gt;for loop&lt;/strong&gt;:
&lt;/h2&gt;

&lt;p&gt;Here a simple for() will be run over the array and the except for the removed element, the remaining elements will be pushed into the new array which will be declared inside the function or a method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  let removeElement = (array, n) =&amp;gt; {
    let newArray = [];

    for (let i = 0; i &amp;lt; array.length; i++) {
      if (array[i] !== n) {
        newArray.push(array[i]);
      }
    }
    return newArray;
  };

  let passed_in_array = [1, 2, 3, 4, 5];
  let element_to_be_removed = 2;
  let result = removeElement(passed_in_array, element_to_be_removed);
  console.log(result); // output  [1, 3, 4, 5]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;While I find &lt;strong&gt;filter()&lt;/strong&gt; and &lt;strong&gt;splice()&lt;/strong&gt; convenient for deleting elements from a JavaScript array in certain scenarios due to their readability and simplicity, I also recognize the importance of understanding fundamental techniques the classic &lt;strong&gt;for loop&lt;/strong&gt; remains a cornerstone in array manipulation.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>beginners</category>
      <category>javascript</category>
    </item>
    <item>
      <title>React CRUD Operations Made Easy with Array Methods</title>
      <dc:creator>Amrita-padhy</dc:creator>
      <pubDate>Tue, 12 Dec 2023 09:33:54 +0000</pubDate>
      <link>https://dev.to/amritapadhy/react-crud-operations-made-easy-with-array-methods-3pn5</link>
      <guid>https://dev.to/amritapadhy/react-crud-operations-made-easy-with-array-methods-3pn5</guid>
      <description>&lt;h2&gt;
  
  
  What is CRUD ?
&lt;/h2&gt;

&lt;p&gt;CRUD operation in React stands for Create, Read, Update, and Delete. CRUD is an important concept for organizing and managing data across the web application. We will perform CRUD operation in the React application with local storage in the form of JavaScript Objects instead of using JSON servers or Axios in React. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Create:&lt;/strong&gt; Creating a post or adding the table row, adding data to the webpage, or creating content.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Read:&lt;/strong&gt; Reading or retrieving data from a web page&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Update:&lt;/strong&gt; Updating or editing existing content on the webpage&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Delete:&lt;/strong&gt; Deleting and removing the entry or content/post from the webpage&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Here's a guide on which array methods you can use for each CRUD operation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Create (C):&lt;/strong&gt;&lt;br&gt;
To add a new element to the array, you can use the concat() method or the spread operator (...).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Using concat
const newArray = oldArray.concat(newElement);

// Using spread operator
const newArray = [...oldArray, newElement];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2-Read (R):&lt;/strong&gt;&lt;br&gt;
Reading or retrieving data from an array can be done using methods like map(), filter(), or accessing elements by index.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Using map
const mappedArray = oldArray.map(item =&amp;gt; /* transform item if needed */);

// Using filter
const filteredArray = oldArray.filter(item =&amp;gt; /* condition */);

// Accessing by index
const elementAtIndex = oldArray[index];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3-Update (U):&lt;/strong&gt;&lt;br&gt;
Updating data in an array can be done using methods like map() or splice().&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Using map to update a specific item
const updatedArray = oldArray.map(item =&amp;gt; item.id === itemId ? updatedItem : item);

// Using splice to replace an item at a specific index
const updatedArray = [...oldArray];
updatedArray.splice(index, 1, updatedItem);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4-Delete (D):&lt;/strong&gt;&lt;br&gt;
Deleting an element from an array can be achieved with methods like filter() or splice().&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Using filter to remove a specific item
const newArray = oldArray.filter(item =&amp;gt; item.id !== itemId);

// Using splice to remove an item at a specific index
const newArray = [...oldArray];
newArray.splice(index, 1);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;CRUD operations are fundamental for building applications that interact with databases or any form of data storage.&lt;br&gt;
uses of appropriate method based on your specific use case. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>codenewbie</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Choosing the Right Path: Ternary Operator vs. Logical AND for Conditional Rendering in React</title>
      <dc:creator>Amrita-padhy</dc:creator>
      <pubDate>Tue, 28 Nov 2023 04:38:26 +0000</pubDate>
      <link>https://dev.to/amritapadhy/choosing-the-right-path-ternary-operator-vs-logical-and-for-conditional-rendering-in-react-3dnk</link>
      <guid>https://dev.to/amritapadhy/choosing-the-right-path-ternary-operator-vs-logical-and-for-conditional-rendering-in-react-3dnk</guid>
      <description>&lt;p&gt;&lt;strong&gt;what is conditional rendaring&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Conditional rendering in React refers to the ability to render different components or content based on certain conditions. This allows developers to dynamically display different parts of the user interface depending on the state of the application or the data being received.&lt;/p&gt;

&lt;p&gt;In JavaScript and React, conditional rendering is often accomplished using conditional statements or operators. Two common methods for conditional rendering in React are:&lt;br&gt;
1-Ternary Operator (? :):&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foli3g1xn0ehzcd8p3ied.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foli3g1xn0ehzcd8p3ied.png" alt=" " width="225" height="225"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{condition ? &amp;lt;TrueComponent /&amp;gt; : &amp;lt;FalseComponent /&amp;gt;}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;2-Logical AND (&amp;amp;&amp;amp;) Operator:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{condition &amp;amp;&amp;amp; &amp;lt;TrueComponent /&amp;gt;}

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

&lt;/div&gt;



&lt;p&gt;In the examples above, if the condition is true,  will be rendered; otherwise,  (in the case of the ternary operator) or nothing at all (in the case of the logical AND operator) will be rendered.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;which way is better and why?&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Both the ternary operator (? :) and the &amp;amp;&amp;amp; operator are valid approaches for conditional rendering in React, and each has its use cases.&lt;br&gt;
The choice between them often comes down to personal or team preference, readability, and the specific requirements of the code.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;1. Ternary Operator (? :):&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{condition ? &amp;lt;TrueComponent /&amp;gt; : &amp;lt;FalseComponent /&amp;gt;}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;&lt;strong&gt;Pros:&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1. Explicitly shows the true and false cases.&lt;/li&gt;
&lt;li&gt;2. Easy to read and understand, especially for complex conditions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;Cons:&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Slightly longer syntax compared to the &amp;amp;&amp;amp; operator.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;2. Logical AND (&amp;amp;&amp;amp;) Operator:&lt;/u&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{condition &amp;amp;&amp;amp; &amp;lt;TrueComponent /&amp;gt;}

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

&lt;/div&gt;



&lt;p&gt;&lt;u&gt;&lt;strong&gt;Pros:&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Concise and often preferred for simple conditions.&lt;/li&gt;
&lt;li&gt;Can be more readable for shorter expressions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;u&gt;&lt;strong&gt;Cons:&lt;/strong&gt;&lt;/u&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;May be less explicit, especially for more complex conditions.&lt;/li&gt;
&lt;li&gt;Only works well when you want to render the component when the condition is true.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;&lt;u&gt;Readability:&lt;/u&gt; Choose the approach that makes your code more readable, especially considering the complexity of your conditions.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Consistency:&lt;/u&gt; It's often beneficial to maintain consistency within a codebase. If your team has a preference, it's good to stick with it for consistency.&lt;/p&gt;

&lt;p&gt;&lt;u&gt;Use Case:&lt;/u&gt; For simple conditions where you want to render a component based on a single boolean expression, the &amp;amp;&amp;amp; operator might be more concise. For more complex conditions or when rendering different components based on multiple conditions, the ternary operator might be clearer.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>react</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>All about router guards in react js</title>
      <dc:creator>Amrita-padhy</dc:creator>
      <pubDate>Mon, 27 Nov 2023 14:00:12 +0000</pubDate>
      <link>https://dev.to/amritapadhy/all-about-router-guards-in-react-js-50b6</link>
      <guid>https://dev.to/amritapadhy/all-about-router-guards-in-react-js-50b6</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is router guard&lt;/strong&gt;&lt;br&gt;
In React applications, a router guard is a mechanism for controlling navigation based on certain conditions or requirements. The goal is to prevent or allow navigation to specific routes based on certain criteria. This is often used to implement features such as &lt;br&gt;
1-authentication checks, &lt;br&gt;
2-form submission confirmation,&lt;br&gt;
3-preventing users from navigating away with unsaved changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to implement&lt;/strong&gt;&lt;br&gt;
 react-router-dom library is commonly used for handling routing. The Route component from react-router-dom allows you to render different components based on the current URL. A router guard can be implemented by using the  useNavigate hook.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use case&lt;/strong&gt;&lt;br&gt;
Here is a small usecase example for implementing router guards . whenever user is filling a form , and user did not submit it and click cancel then user can not redirect directly to previous route.&lt;br&gt;
IN this case a conformation modal will show and ask the user wheather you want to leave the page or continue&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Guard.js
import React, { useState } from "react";
import { useNavigate } from "react-router-dom";
import { Dialog } from "primereact/dialog";
import { Button } from "primereact/button";

const Guard = ({ showModal, setShowModal }) =&amp;gt; {
  const [confirmNavigation, setConfirmNavigation] = useState(false);
  const navigate = useNavigate();

  const onOkClick = () =&amp;gt; {
    if (confirmNavigation) {
      setShowModal(false);
      navigate("/");
    }
  };

  const onDialogCancel = () =&amp;gt; {
    setShowModal(false);
    setConfirmNavigation(false);
  };

  const onDialogProceed = () =&amp;gt; {
    setConfirmNavigation(true);
    onOkClick();
  };

  return (
    &amp;lt;div&amp;gt;
      &amp;lt;Dialog
        header="Confirmation"
        visible={showModal}
        onHide={onDialogCancel}
        style={{ padding: "15px", width: "600px" }}
        footer={
          &amp;lt;div&amp;gt;
            &amp;lt;Button
              label="No"
              icon="pi pi-times"
              onClick={onDialogCancel}
              className="p-button-text"
              style={{ padding: "5px" }}
            /&amp;gt;
            &amp;lt;Button
              label="Yes"
              text
              icon="pi pi-check"
              onClick={onDialogProceed}
              style={{ padding: "5px" }}
            /&amp;gt;
          &amp;lt;/div&amp;gt;
        }
      &amp;gt;
        &amp;lt;p style={{ padding: "15px" }}&amp;gt;Do you want to leave the page?&amp;lt;/p&amp;gt;
      &amp;lt;/Dialog&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default Guard;

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

&lt;/div&gt;



&lt;p&gt;On cancel button click this Guard component will show. and it will prevent the user to directly go back to previous route .&lt;/p&gt;

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