<?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: ATUL KUMAR SINGH</title>
    <description>The latest articles on Forem by ATUL KUMAR SINGH (@atul1995).</description>
    <link>https://forem.com/atul1995</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%2F148612%2Fb791ae3f-383d-459e-9877-47803e4ff8cb.jpeg</url>
      <title>Forem: ATUL KUMAR SINGH</title>
      <link>https://forem.com/atul1995</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/atul1995"/>
    <language>en</language>
    <item>
      <title>Don’t Fall Into the Trap of Too Many Indexes! 🤕</title>
      <dc:creator>ATUL KUMAR SINGH</dc:creator>
      <pubDate>Mon, 21 Oct 2024 13:27:45 +0000</pubDate>
      <link>https://forem.com/atul1995/dont-fall-into-the-trap-of-too-many-indexes-3n51</link>
      <guid>https://forem.com/atul1995/dont-fall-into-the-trap-of-too-many-indexes-3n51</guid>
      <description>&lt;p&gt;Let’s talk about MongoDB indexes and why you shouldn’t create one for every field you query. 🧐&lt;/p&gt;

&lt;p&gt;In MongoDB, indexes are essential tools for enhancing the performance of queries. Just like in a book, where an index helps you quickly find a topic, MongoDB indexes speed up the retrieval of documents in a collection by reducing the number of documents that need to be scanned.&lt;/p&gt;

&lt;p&gt;Imagine you're building an e-commerce platform like Amazon. You create indexes to find orders by userId, sort them by orderDate, and maybe even filter by status. But hold up ✋ —if you keep adding more indexes for every query possibility (like for productId, status, or combinations), you’re setting yourself up for trouble. 😓 &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here’s why:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Slower Writes:&lt;/strong&gt; Every new order has to update all those indexes. Too many? You’ll see performance drop fast, especially on high-traffic days.&lt;br&gt;
&lt;strong&gt;2. Memory Consumption:&lt;/strong&gt; Each index eats up memory. With too many, your server will eventually start reading from disk—performance crash incoming.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution? 🤔 Be selective🕵‍♂️.&lt;/strong&gt; Use compound indexes wisely for queries that frequently involve multiple fields (like userId and orderDate). And always balance between read and write performance based on your app’s needs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;MongoDB indexes are powerful—but only if you don’t overuse them. 🚀&lt;/strong&gt;&lt;br&gt;
Happy Coding 👨‍💻 &lt;/p&gt;

</description>
      <category>mongodb</category>
      <category>node</category>
      <category>fullstackdevelopment</category>
      <category>databaseoptimization</category>
    </item>
    <item>
      <title>🚀 Frontend Tip of the Day: Debouncing Input Handlers for Better Performance 🚀</title>
      <dc:creator>ATUL KUMAR SINGH</dc:creator>
      <pubDate>Mon, 07 Oct 2024 05:09:29 +0000</pubDate>
      <link>https://forem.com/atul1995/-frontend-tip-of-the-day-debouncing-input-handlers-for-better-performance-ii0</link>
      <guid>https://forem.com/atul1995/-frontend-tip-of-the-day-debouncing-input-handlers-for-better-performance-ii0</guid>
      <description>&lt;p&gt;When dealing with real-time user input, like search fields, triggering actions on every keystroke can cause performance issues. &lt;strong&gt;Debouncing&lt;/strong&gt; helps by delaying execution until the user stops typing.&lt;/p&gt;

&lt;p&gt;🛠 &lt;strong&gt;Let's Build a Simple Debounce Function:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useEffect&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;debounce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;timer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;clearTimeout&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;timer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;timer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;(...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;SearchBar&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setQuery&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleSearch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;q&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Searching for:&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;q&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// Perform search action here&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;debouncedSearch&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;debounce&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;handleSearch&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nf"&gt;useEffect&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;debouncedSearch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;input&lt;/span&gt;
      &lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="nx"&gt;placeholder&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Search...&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
      &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="nx"&gt;onChange&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;
    &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;⚡ &lt;strong&gt;How it Works:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The debounce function accepts a fn (function) and a delay (in milliseconds).&lt;/li&gt;
&lt;li&gt;It clears any existing timers and sets a new one to trigger the function after the specified delay.&lt;/li&gt;
&lt;li&gt;In this example, debouncedSearch triggers only after the user stops typing for 500 milliseconds.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;💡 &lt;strong&gt;Why it Matters:&lt;/strong&gt; &lt;br&gt;
It’s a lightweight solution that improves performance, especially in apps with real-time inputs like search fields.&lt;/p&gt;

&lt;p&gt;Happy coding! 🔥&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>node</category>
      <category>webdev</category>
    </item>
    <item>
      <title>🚀 Frontend Tip of the Day: Enhancing Performance with React.memo() 🚀</title>
      <dc:creator>ATUL KUMAR SINGH</dc:creator>
      <pubDate>Sun, 06 Oct 2024 14:46:09 +0000</pubDate>
      <link>https://forem.com/atul1995/frontend-tip-of-the-day-enhancing-performance-with-reactmemo-5e8e</link>
      <guid>https://forem.com/atul1995/frontend-tip-of-the-day-enhancing-performance-with-reactmemo-5e8e</guid>
      <description>&lt;p&gt;&lt;em&gt;Did you know you can boost your React app's performance with just a single line of code? Meet React. memo()&lt;/em&gt;! 🧠&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What It Does:&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;React.memo() is a higher-order component that optimizes your functional components by memoizing them. Essentially, it prevents re-renders when the props haven’t changed. This can make a noticeable difference in apps with many components or complex UI.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to Use It:&lt;/strong&gt;&lt;br&gt;
Wrap your functional component like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MyComponent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;memo&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;props&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Component code will go here&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;💡&lt;strong&gt;When to Use:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;For components that receive the same props frequently.&lt;/li&gt;
&lt;li&gt;When a component re-renders unnecessarily due to parent updates.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;⚠️ &lt;strong&gt;When NOT to Use:&lt;/strong&gt;&lt;br&gt;
Avoid using React.memo() on components that need to update frequently or on components with complex props that change frequently. Overuse can lead to unexpected bugs!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Happy coding!&lt;/strong&gt; 👨‍💻&lt;/p&gt;

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