<?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: Anjan Karmakar</title>
    <description>The latest articles on Forem by Anjan Karmakar (@47anjan).</description>
    <link>https://forem.com/47anjan</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%2F773854%2Ff34379e5-6444-42ea-b76d-e12f926198d9.jpg</url>
      <title>Forem: Anjan Karmakar</title>
      <link>https://forem.com/47anjan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/47anjan"/>
    <language>en</language>
    <item>
      <title>6 Study Habits of Successful Students</title>
      <dc:creator>Anjan Karmakar</dc:creator>
      <pubDate>Wed, 28 Aug 2024 07:23:06 +0000</pubDate>
      <link>https://forem.com/47anjan/6-study-habits-of-successful-students-24d8</link>
      <guid>https://forem.com/47anjan/6-study-habits-of-successful-students-24d8</guid>
      <description>&lt;p&gt;This guide summarizes effective study habits based on research conducted among 700 medical students, focusing on those who excel academically. The following key habits are essential for maximizing learning and achieving academic success.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. &lt;strong&gt;Daily Study Routine&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Time Commitment:&lt;/strong&gt; Successful students study for about 3-4 hours each day, at least 5 days a week.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consistency:&lt;/strong&gt; Maintaining a consistent study schedule helps the brain and body adapt to learning during specific times, making it easier to focus and retain information.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. &lt;strong&gt;Minimizing Distractions&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Set Boundaries:&lt;/strong&gt; During study time, put away your phone, inform friends and family that you are unavailable, and create a distraction-free environment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Focus:&lt;/strong&gt; Understand that focus and attention are limited resources but can be renewed. Prioritize creating an environment conducive to deep concentration.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. &lt;strong&gt;Teaching Others&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Peer Teaching:&lt;/strong&gt; Students who teach their peers perform better. The "Watch One, Do One, Teach One" method is particularly effective:

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Watch One:&lt;/strong&gt; Observe a concept or skill being taught.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Do One:&lt;/strong&gt; Practice and apply the concept independently.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Teach One:&lt;/strong&gt; Teach the concept to others, reinforcing your understanding.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  4. &lt;strong&gt;Studying in Isolation&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Solo Study:&lt;/strong&gt; Dedicate time to studying alone without distractions. This focused time is crucial for deep learning and mastery of the material.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  5. &lt;strong&gt;Sleep and Focus&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Adenosine and Sleep:&lt;/strong&gt; Adenosine builds up in the brain the longer you are awake, leading to decreased focus and alertness. Sleep helps reset adenosine levels, improving your ability to concentrate.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Regular Sleep Schedule:&lt;/strong&gt; Adhering to a consistent sleep schedule will enhance your study effectiveness and overall cognitive function.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  6. &lt;strong&gt;Regular Study Time&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Routine:&lt;/strong&gt; Establish a regular study time each day. It takes about 2-3 days to adjust to a new study routine, after which your brain will be better trained to focus during those times.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Weekend Consistency:&lt;/strong&gt; Try to maintain your study schedule even on weekends to keep your nervous system optimized for learning.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;This guide outlines the practices that top-performing students use to excel in their studies. By incorporating these habits into your routine, you can improve your focus, retention, and overall academic performance.&lt;/p&gt;

&lt;p&gt;Source: &lt;a href="https://youtu.be/ddq8JIMhz7c?si=9mwXvgVwuTENRmLE" rel="noopener noreferrer"&gt;Optimal Protocols for Studying &amp;amp; Learning - Andrew Huberman&lt;/a&gt;&lt;/p&gt;

</description>
      <category>productivity</category>
    </item>
    <item>
      <title>Describe the difference between `&lt;script&gt;`, `&lt;script async&gt;` and `&lt;script defer&gt;` for Optimal Website Performance</title>
      <dc:creator>Anjan Karmakar</dc:creator>
      <pubDate>Tue, 14 May 2024 03:55:18 +0000</pubDate>
      <link>https://forem.com/47anjan/describe-the-difference-between-and-for-optimal-website-performance-1eel</link>
      <guid>https://forem.com/47anjan/describe-the-difference-between-and-for-optimal-website-performance-1eel</guid>
      <description>&lt;p&gt;Ever wondered how to optimize JavaScript loading on your web pages? The answer lies in understanding the different ways to include scripts using the &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; tag. Here's a breakdown:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. &lt;code&gt;&amp;lt;script&amp;gt;&lt;/code&gt; (Default):&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Blocks HTML parsing until the script is downloaded and executed.&lt;/li&gt;
&lt;li&gt;Use this for critical scripts that the page relies on to render initially.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. &lt;code&gt;&amp;lt;script async&amp;gt;&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Downloads the script in parallel with HTML parsing.&lt;/li&gt;
&lt;li&gt;Executes the script as soon as it's available, potentially before HTML parsing finishes.&lt;/li&gt;
&lt;li&gt;Order of execution isn't guaranteed.&lt;/li&gt;
&lt;li&gt;Ideal for non-critical scripts like analytics that don't depend on the DOM being fully built.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. &lt;code&gt;&amp;lt;script defer&amp;gt;&lt;/code&gt;:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Downloads the script in parallel with HTML parsing.&lt;/li&gt;
&lt;li&gt;Waits for the HTML to be fully parsed before executing the script, but before the DOMContentLoaded event fires.&lt;/li&gt;
&lt;li&gt;Scripts execute in the order they appear in the HTML.&lt;/li&gt;
&lt;li&gt;Use this for scripts that rely on the DOM being fully available, like manipulating page elements.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;async&lt;/code&gt; for independent, non-critical scripts.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;defer&lt;/code&gt; for DOM-dependent scripts that preserve order.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Both improve performance by allowing parallel parsing.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Not for critical rendering scripts!&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Bonus Tip:&lt;/strong&gt; Avoid &lt;code&gt;document.write()&lt;/code&gt; with &lt;code&gt;async&lt;/code&gt; or &lt;code&gt;defer&lt;/code&gt; scripts.&lt;/p&gt;

&lt;p&gt;By understanding these options, you can ensure your website loads faster and delivers a smoother user experience!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>frontend</category>
      <category>performance</category>
      <category>interview</category>
    </item>
    <item>
      <title>Mastering Git: 13 Advanced Techniques and Shortcuts for Efficiency</title>
      <dc:creator>Anjan Karmakar</dc:creator>
      <pubDate>Thu, 09 May 2024 07:02:23 +0000</pubDate>
      <link>https://forem.com/47anjan/mastering-git-13-advanced-techniques-and-shortcuts-for-efficiency-10d1</link>
      <guid>https://forem.com/47anjan/mastering-git-13-advanced-techniques-and-shortcuts-for-efficiency-10d1</guid>
      <description>&lt;p&gt;Ready to elevate your Git game?  Whether you're a seasoned developer with years of experience or just starting out on your coding journey, mastering Git can significantly enhance your development workflow and productivity. This blog post dives into 13 advanced techniques and shortcuts to navigate Git with efficiency and ease.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Combine add &amp;amp; commit:&lt;/strong&gt; Streamline your workflow with &lt;code&gt;git commit -am "&amp;lt;message&amp;gt;"&lt;/code&gt;. This powerful command stages all modified files &lt;strong&gt;(meaning it adds them to the staging area for the next commit)&lt;/strong&gt; and commits them with a provided message in one step. This is a great time-saver for simple changes where you're modifying multiple files and the message is clear.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git commit &lt;span class="nt"&gt;-am&lt;/span&gt; &lt;span class="s2"&gt;"Fixed typo in main function"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Aliases:&lt;/strong&gt; Tired of typing long and repetitive Git commands? Customize them for frequently used actions with aliases in your Git config. This ensures faster execution without compromising accuracy. Here's an example of creating an alias for &lt;code&gt;git status&lt;/code&gt;:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git config &lt;span class="nt"&gt;--global&lt;/span&gt; alias.st status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you can simply type &lt;code&gt;git st&lt;/code&gt; to check the status of your repository.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Amend:&lt;/strong&gt; Corrected a typo in your commit message? No sweat! Use &lt;code&gt;git commit --amend&lt;/code&gt; to effortlessly update the message &lt;strong&gt;without creating unnecessary commits&lt;/strong&gt;. This keeps your commit history clean and organized.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Force Push (Use with Caution):&lt;/strong&gt; Take control of the remote repository with &lt;code&gt;git push --force&lt;/code&gt;. &lt;strong&gt;Important:&lt;/strong&gt; This rewrites remote history irreversibly, so use it cautiously. This should only be used in specific situations, like fixing a mistake you accidentally pushed to the remote repository. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Revert:&lt;/strong&gt; Need to undo changes from a specific commit but want to preserve the overall history? Utilize &lt;code&gt;git revert &amp;lt;commit_hash&amp;gt;&lt;/code&gt;  to create a new commit that effectively undoes the changes introduced by the specified commit.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Codespaces:&lt;/strong&gt; Unleash the power of GitHub and Git operations directly from your web browser with Codespaces. This eliminates the need for local Git installations and enables seamless development and collaboration from anywhere with an internet connection.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Stash:&lt;/strong&gt; Temporarily set aside changes with &lt;code&gt;git stash&lt;/code&gt;. This allows you to switch tasks without cluttering your commit history. Think of it like putting your current work on hold. Retrieve stashed changes with &lt;code&gt;git stash list&lt;/code&gt; to see a list of your stashed changes and apply them selectively using &lt;code&gt;git stash pop&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Main Branch:&lt;/strong&gt;  Embrace modern Git practices by renaming your default branch to &lt;code&gt;main&lt;/code&gt;. This aligns with industry standards adopted post-2020. You can use the command &lt;code&gt;git branch -m master main&lt;/code&gt; to rename your master branch to main.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pretty Logs:&lt;/strong&gt; Tired of scrolling through long lists of commits? Enhance readability of your commit history using &lt;code&gt;git log --graph --oneline --decorate&lt;/code&gt;. This command provides a concise and visually appealing overview of your repository's changes, including branch names and authorship information.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Bisect:&lt;/strong&gt; Debugging a complex issue can be time-consuming. Debug efficiently by isolating problematic commits with &lt;code&gt;git bisect&lt;/code&gt;. This powerful tool allows you to systematically analyze your codebase, narrowing down the commit that introduced the bug.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Autosquash:&lt;/strong&gt; Streamline commit management during feature development with &lt;code&gt;git rebase --interactive&lt;/code&gt;. Utilize &lt;code&gt;fixup&lt;/code&gt; and &lt;code&gt;squash&lt;/code&gt; flags to automate the consolidation of commits. This can be helpful when you have a series of small commits related to a single feature and want to combine them into a single, cleaner commit.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Hooks:&lt;/strong&gt; Extend Git's functionalities by leveraging hooks to execute custom scripts before or after specific Git events. Consider tools like Husky for simplified hook configuration. Hooks can be used for various purposes, such as running automated tests or enforcing code style guidelines before a commit.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Destroy Things (Safely):&lt;/strong&gt;  &lt;strong&gt;Always be cautious when modifying your Git history!&lt;/strong&gt; Here's how to safely revert changes:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;After a &lt;code&gt;git fetch&lt;/code&gt; to update your local repository with remote changes, use &lt;code&gt;git reset --hard HEAD^&lt;/code&gt; to revert your local working directory to the state of the most recent commit on the remote branch (be aware that this discards any uncommitted changes). &lt;/li&gt;
&lt;li&gt;Utilize &lt;code&gt;git clean -f&lt;/code&gt; to remove untracked files (files that haven't been added to the Git repository) and restore repository cleanliness. &lt;strong&gt;Remember:&lt;/strong&gt; Use these commands with caution, as they can lead to data loss if not used properly.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Bonus Tip: Checkout to Last:&lt;/strong&gt; Quickly switch back to your previous branch with &lt;code&gt;git checkout -&lt;/code&gt;. This eliminates the need to manually recall branch names and is&lt;/p&gt;

</description>
      <category>git</category>
      <category>github</category>
      <category>opensource</category>
      <category>programming</category>
    </item>
    <item>
      <title>The Magic of keyof and typeof in Typescript</title>
      <dc:creator>Anjan Karmakar</dc:creator>
      <pubDate>Thu, 02 May 2024 16:14:15 +0000</pubDate>
      <link>https://forem.com/47anjan/magic-of-keyof-and-typeof-in-typescript-43ma</link>
      <guid>https://forem.com/47anjan/magic-of-keyof-and-typeof-in-typescript-43ma</guid>
      <description>&lt;p&gt;Ever get stuck writing out long unions for component props based on an object? There's a cleaner way! &lt;/p&gt;

&lt;p&gt;This post explores using &lt;code&gt;keyof&lt;/code&gt; and &lt;code&gt;typeof&lt;/code&gt; to automatically generate type unions from object keys for your React components. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Problem:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's say you have a button component with different variants based on classNames:&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;classNamesMap&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;primary&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bg-blue-500 text-white&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;secondary&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bg-gray-200 text-black&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;success&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bg-green-500 text-white&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// This approach is tedious and error-prone&lt;/span&gt;
&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;ButtonProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;variant&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;primary&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;secondary&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;success&lt;/span&gt;&lt;span class="dl"&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;The Solution: Leverage &lt;code&gt;keyof&lt;/code&gt; and &lt;code&gt;typeof&lt;/code&gt;!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Here's how to achieve the same functionality with cleaner code:&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="c1"&gt;// Get the type of classNamesMap&lt;/span&gt;
&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;ClassNamesMapType&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;classNamesMap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Use keyof to create a union type from the object's keys&lt;/span&gt;
&lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;ButtonProps&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;variant&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;keyof&lt;/span&gt; &lt;span class="nx"&gt;ClassNamesMapType&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// variant: "primary" | "secondary" | "success"&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With typeof you will be able to get the type of your object, and with keyof you will be able to create union types based on the keys of your object.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Reduced Code:&lt;/strong&gt; No more manually typing out unions!&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Improved Type Safety:&lt;/strong&gt; TypeScript automatically enforces valid variants.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Maintainability:&lt;/strong&gt; Changes to &lt;code&gt;classNamesMap&lt;/code&gt; are reflected in &lt;code&gt;ButtonProps&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Use this approach for any component prop based on an object of key-value pairs.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Spread the Knowledge!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Share this post with your fellow developers and elevate your React component typing game! &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>typescript</category>
      <category>programming</category>
      <category>react</category>
    </item>
    <item>
      <title>Why React Re-Renders?</title>
      <dc:creator>Anjan Karmakar</dc:creator>
      <pubDate>Sun, 21 Jan 2024 13:07:24 +0000</pubDate>
      <link>https://forem.com/47anjan/why-react-re-renders-4bao</link>
      <guid>https://forem.com/47anjan/why-react-re-renders-4bao</guid>
      <description>&lt;h4&gt;
  
  
  &lt;strong&gt;Why React Re-Renders?&lt;/strong&gt;
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Start with a fundamental every re-render in React starts with a state change.&lt;/li&gt;
&lt;li&gt;Re-renders only affect the component that owns the state + its descendants (if any).&lt;/li&gt;
&lt;li&gt;Some developers believe that a component will re-render because its props change, although that is a valid reason, it is not quite true when a component renders it all descends also re-renders, regardless of whether the descends components have props or not (pure components). The descends components can be exported with React.memo to prevent unnecessary re-rendering. If any pure components have props as a static value (object or function) you can use useMemo or useCallback hook to prevent re-rendering.&lt;/li&gt;
&lt;li&gt;Now What about context? Though some components have no props, if it uses a value form useContext If that state variable changes, a re-render will occur.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are the fundamentals of React and why it re-renders. &lt;/p&gt;

&lt;p&gt;If any of the points are incorrect, please feel free to correct me, as I am also learning, and I have learned this through reading many blogs and articles.&lt;/p&gt;

&lt;p&gt;Thank you for your attention 🙂&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title>Understanding Event Delegation</title>
      <dc:creator>Anjan Karmakar</dc:creator>
      <pubDate>Fri, 01 Dec 2023 12:00:29 +0000</pubDate>
      <link>https://forem.com/47anjan/understanding-event-delegation-13kf</link>
      <guid>https://forem.com/47anjan/understanding-event-delegation-13kf</guid>
      <description>&lt;p&gt;Event delegation is a technique involving adding event listeners to a parent element instead of adding them to the descendant elements. The listener will fire whenever the event is triggered on the descendant elements due to event bubbling up the DOM. The benefits of this technique are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Memory footprint goes down because only one single handler is needed on the parent element, rather than having to attach event handlers on each descendant.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There is no need to unbind the handler from elements that are removed and to bind the event for new elements.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://davidwalsh.name/event-delegate" rel="noopener noreferrer"&gt;References&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>frontend</category>
      <category>interview</category>
    </item>
    <item>
      <title>Mastering JavaScript Promises🔥| all, allSettled, race, any</title>
      <dc:creator>Anjan Karmakar</dc:creator>
      <pubDate>Fri, 20 Oct 2023 03:47:28 +0000</pubDate>
      <link>https://forem.com/47anjan/mastering-javascript-promises-all-allsettled-race-any-2b1d</link>
      <guid>https://forem.com/47anjan/mastering-javascript-promises-all-allsettled-race-any-2b1d</guid>
      <description>&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%2Fdy9m3jpsefpkzkwse0lb.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdy9m3jpsefpkzkwse0lb.jpg" alt="Image description" width="800" height="341"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;JavaScript Promise APIs revolutionize how we manage asynchronous operations in JavaScript, offering a structured and efficient approach. In this article, we will delve into four crucial Promise APIs: Promise.all, Promise.allSettled, Promise.race, and Promise.any.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Promise.all: Managing Concurrent Operations&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Promise.all is your go-to choice when you need to perform multiple parallel API calls simultaneously, such as fetching data for 10 different users using 10 unique IDs. This method takes an array of promises as input and initiates multiple API calls concurrently.&lt;/p&gt;

&lt;p&gt;If you provide it with promises P1, P2, and P3, it will make these three parallel API calls and collect the results in an array. It waits for all three to complete, taking, for example, 3 seconds, and then returns the results.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Handling Failures with Promise.all&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Should any of the promises in the array get rejected, Promise.all responds by throwing an error, matching the error type and message of the first rejected promise. Even if the others are pending, it quickly reports the error, illustrating how it operates.&lt;/p&gt;

&lt;p&gt;Remember that promises are immutable; they will either resolve or reject but cannot be canceled. The promise chain does not wait for all promises to succeed; if any fail, the entire collection fails. So, all promises will either succeed or fail, with an error thrown after 1 second in case of failure.&lt;/p&gt;

&lt;p&gt;If two seconds promises are rejected, the first rejection takes precedence, and the second one immediately returns the error. If you only need results from successful promises, Promise.all is the way to go.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Promise.allSettled: Comprehensive Promise Handling&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When all promises fulfill, the output remains the same as when all promises succeed. However, if any promise gets rejected, the output changes. For instance, if there are three promises, one for success, one for error, and one for success again, any failure results in an immediate response. But if all three fail, it waits for all three and responds accordingly.&lt;/p&gt;

&lt;p&gt;If you need the results from all API calls to display a webpage, choose Promise.all. If you want to process results even if some promises fail, go for Promise.allSettled.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Promise.race: Optimized Execution&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Promise.race, the third API, returns a value as soon as the first promise resolves, allowing for optimized execution. If the first promise succeeds, it immediately returns the value. If the second promise fails, it returns the error of the first settled promise after 1 second. If P3 fails after 2 seconds, it throws an error without waiting for the others to finish.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Managing Promise Resolution with Promise.any&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Promise.any, the last API, waits for the first successful promise before returning its result. If the first promise gets rejected, it doesn't respond until 1 second has passed. If one of the promises succeeds, it returns that result. If all API calls fail, it aggregates all the errors into an array. However, if all fail, it returns an aggregate error after 1 second.&lt;/p&gt;

&lt;p&gt;Now that you understand these cases, let's move on to the code. I'll show you how to write and use these promises effectively.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Summary of Promise APIs&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To recap:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Promise.all takes an array of promises and returns an array of results if they all succeed, failing fast if any of them fail.&lt;/li&gt;
&lt;li&gt;Promise.race returns a result as soon as the first promise settles.&lt;/li&gt;
&lt;li&gt;Promise.any waits for the first successful promise to return its result, ignoring failures unless all promises fail.&lt;/li&gt;
&lt;li&gt;Promise.allSettled handles a mix of fulfilled and rejected promises gracefully.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Interview Questions + Clarifying Terminology: Settle, Resolve, Reject, Fulfilled&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In interviews, remember that the first settled promise, whether successful or not, wins the race. Understanding the nuances of terminology, like resolved or rejected and fulfilled or rejected, is essential.&lt;/p&gt;

&lt;p&gt;Recognize that settling can be either a failure or a success, and a promise is generally said to be fulfilled or rejected. By grasping these nuances, you'll be better prepared for interviews and deepen your understanding of JavaScript Promise APIs.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>frontend</category>
      <category>programming</category>
    </item>
    <item>
      <title>Mastering Event Debouncing in JavaScript: A Guide with Practical Example</title>
      <dc:creator>Anjan Karmakar</dc:creator>
      <pubDate>Thu, 31 Aug 2023 02:29:31 +0000</pubDate>
      <link>https://forem.com/47anjan/mastering-event-debouncing-in-javascript-a-guide-with-practical-example-19oe</link>
      <guid>https://forem.com/47anjan/mastering-event-debouncing-in-javascript-a-guide-with-practical-example-19oe</guid>
      <description>&lt;p&gt;Debouncing is a technique used to control how often a particular function is executed in response to frequent events. It ensures that the function is called only after a certain amount of time has passed since the last event. In this blog, we'll explore the concept of debouncing and demonstrate its implementation using a practical example in JavaScript.&lt;/p&gt;

&lt;p&gt;Understanding Debouncing&lt;/p&gt;

&lt;p&gt;Imagine a search bar on a webpage that fetches search results as the user types. Without debouncing, every keystroke triggers a new search request, potentially overwhelming the server and causing unnecessary network traffic. Debouncing addresses this problem by delaying the execution of the function until the user has finished typing.&lt;/p&gt;

&lt;p&gt;Debouncing involves setting a timer that delays the function execution. If another event occurs before the timer expires, the timer is reset. This ensures that the function only fires after a certain quiet period.&lt;/p&gt;

&lt;p&gt;Practical Example: Implementing Debounce in JavaScript&lt;/p&gt;

&lt;p&gt;Let's dive into a practical example to demonstrate how to implement debouncing using JavaScript. We'll use the provided code as a starting point and explain each component.&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;searchInput&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&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="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&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="s2"&gt;Fetching data.... &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&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;debounceFun&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;getData&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;time&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="kd"&gt;let&lt;/span&gt; &lt;span class="nb"&gt;self&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&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;time&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;time&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;time&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="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;getData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&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="p"&gt;},&lt;/span&gt; &lt;span class="nx"&gt;delay&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&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;optimizeFun&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;debounceFun&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;getData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;searchInput&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;keyup&lt;/span&gt;&lt;span class="dl"&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;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="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;optimizeFun&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="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we have a search input element and a &lt;code&gt;getData&lt;/code&gt; function that simulates fetching data based on the search query.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The &lt;code&gt;debounceFun&lt;/code&gt; function takes two arguments: the function to be debounced (&lt;code&gt;getData&lt;/code&gt;) and a delay in seconds (&lt;code&gt;delay&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Inside the &lt;code&gt;debounceFun&lt;/code&gt;, a closure is returned. This closure maintains a reference to the &lt;code&gt;time&lt;/code&gt; variable, which stores the timer ID.&lt;/li&gt;
&lt;li&gt;When an event occurs (in this case, a &lt;code&gt;keyup&lt;/code&gt; event on the search input), the &lt;code&gt;optimizeFun&lt;/code&gt; (debounced version of &lt;code&gt;getData&lt;/code&gt;) is called with the search value.&lt;/li&gt;
&lt;li&gt;Inside the &lt;code&gt;optimizeFun&lt;/code&gt;, the existing timer is cleared using &lt;code&gt;clearTimeout&lt;/code&gt; if it exists. Then, a new timer is set using &lt;code&gt;setTimeout&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The timer delays the execution of the &lt;code&gt;getData&lt;/code&gt; function until the specified &lt;code&gt;delay&lt;/code&gt; has passed since the last event.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Benefits of Debouncing:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Reduced Function Calls:&lt;/strong&gt; Debouncing ensures that a function is called only after a pause in events, preventing excessive function calls and improving performance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optimized Network Requests:&lt;/strong&gt; For actions like search suggestions or fetching data, debouncing can help minimize the number of requests sent to the server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Enhanced User Experience:&lt;/strong&gt; By avoiding rapid and unnecessary updates, debouncing creates a smoother user experience.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>interview</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Infinite Scrolling in React: A Comprehensive Guide</title>
      <dc:creator>Anjan Karmakar</dc:creator>
      <pubDate>Wed, 30 Aug 2023 15:53:13 +0000</pubDate>
      <link>https://forem.com/47anjan/infinite-scrolling-in-react-a-comprehensive-guide-2o05</link>
      <guid>https://forem.com/47anjan/infinite-scrolling-in-react-a-comprehensive-guide-2o05</guid>
      <description>&lt;p&gt;&lt;strong&gt;Implementing Infinite Scrolling in React&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Infinite scrolling is a powerful technique used to enhance user experience when dealing with long lists of content. Rather than displaying all the data at once and overwhelming the user, infinite scrolling loads more content as the user scrolls down the page. In this article, we'll explore how to implement infinite scrolling in a React application, using a combination of state management, event listeners, and conditional rendering.&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;To implement infinite scrolling, we'll start by creating a component that displays a list of items. We'll name this component &lt;code&gt;InfiniteScrollList&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  State Management
&lt;/h3&gt;

&lt;p&gt;First, set up the necessary state to track the current page or offset. This is crucial for determining which set of items to load next. We'll use React's &lt;code&gt;useState&lt;/code&gt; and &lt;code&gt;useEffect&lt;/code&gt; hooks for this.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&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;InfiniteScrollList&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="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setItems&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="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setPage&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="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Load items whenever the page changes&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="nf"&gt;loadItems&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;page&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

  &lt;span class="c1"&gt;// Function to load more items&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;loadItems&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="c1"&gt;// Implement your logic to fetch more items (e.g., from an API)&lt;/span&gt;
    &lt;span class="c1"&gt;// Append the new items to the existing ones&lt;/span&gt;
    &lt;span class="c1"&gt;// Update the state using setItems&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;

  &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Scroll Event Listener
&lt;/h3&gt;

&lt;p&gt;Next, add a scroll event listener to the &lt;code&gt;window&lt;/code&gt; object to detect when the user reaches the bottom of the page. This is the trigger for loading more items.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;handleScroll&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="c1"&gt;// Calculate how close the user is to the bottom&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;scrollPosition&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHeight&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;scrollY&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;scrollMax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;offsetHeight&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;scrollPosition&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nx"&gt;scrollMax&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// User has reached the bottom, load more items&lt;/span&gt;
      &lt;span class="nf"&gt;setPage&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&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="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;scroll&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handleScroll&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// Clean up the event listener when the component unmounts&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;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;scroll&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handleScroll&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;page&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Rendering Items
&lt;/h3&gt;

&lt;p&gt;Now, in the &lt;code&gt;render&lt;/code&gt; function of your component, map over the &lt;code&gt;items&lt;/code&gt; array and render each item.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;index&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/* Render your item here */&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Conditional Rendering
&lt;/h3&gt;

&lt;p&gt;To provide a smooth user experience, consider showing a loading indicator while new items are being fetched.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;index&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt; &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="cm"&gt;/* Render your item here */&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;loading&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Loading...&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;Implementing infinite scrolling in a React application can significantly improve the way users interact with long lists of content. By progressively loading more items as the user scrolls down, you create a seamless and engaging browsing experience. Keep in mind that while the steps provided here offer a simplified overview, you'll need to tailor the implementation to your specific data fetching logic, error handling, and design requirements.&lt;/p&gt;

&lt;p&gt;By following the techniques outlined in this guide, you can effortlessly create a dynamic and user-friendly application that keeps users engaged without overwhelming them with excessive content all at once.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
      <category>interview</category>
    </item>
    <item>
      <title>Embracing the Future: Progressive Web Apps (PWAs) Unveiled</title>
      <dc:creator>Anjan Karmakar</dc:creator>
      <pubDate>Mon, 28 Aug 2023 14:07:28 +0000</pubDate>
      <link>https://forem.com/47anjan/embracing-the-future-progressive-web-apps-pwas-unveiled-58lb</link>
      <guid>https://forem.com/47anjan/embracing-the-future-progressive-web-apps-pwas-unveiled-58lb</guid>
      <description>&lt;p&gt;In an age where digital experiences are seamlessly intertwined with our lives, the emergence of Progressive Web Apps (PWAs) marks a significant milestone in the evolution of web applications. PWAs bring together the best of both web and mobile apps, offering an immersive and dynamic user experience that transcends traditional boundaries. Let's delve into the world of PWAs and uncover how they're reshaping our digital interactions.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Fusion of Web and Apps
&lt;/h2&gt;

&lt;p&gt;Progressive Web Apps, often referred to as PWAs, represent a groundbreaking convergence of web and native app technologies. These applications are designed to embody the qualities we value most in both platforms. Here's what sets PWAs apart:&lt;/p&gt;

&lt;h3&gt;
  
  
  Progressive Enhancement
&lt;/h3&gt;

&lt;p&gt;PWAs ensure universal access, catering to every user regardless of their device or browser. The principle of progressive enhancement is at the core of their design, ensuring inclusivity.&lt;/p&gt;

&lt;h3&gt;
  
  
  Responsive Design
&lt;/h3&gt;

&lt;p&gt;Adaptability is key. PWAs seamlessly adjust to diverse screen sizes, offering a consistent and enjoyable experience on smartphones, tablets, and desktops alike.&lt;/p&gt;

&lt;h3&gt;
  
  
  App-Like Features
&lt;/h3&gt;

&lt;p&gt;PWAs blur the lines between websites and native apps by delivering features such as offline access, push notifications, and installability on users' devices.&lt;/p&gt;

&lt;h3&gt;
  
  
  Always Up-to-Date
&lt;/h3&gt;

&lt;p&gt;Unlike traditional apps that necessitate time-consuming updates, PWAs can be effortlessly deployed, guaranteeing users have access to the latest features.&lt;/p&gt;

&lt;h3&gt;
  
  
  Speed and Performance
&lt;/h3&gt;

&lt;p&gt;Leveraging cutting-edge web technologies, PWAs load swiftly and perform seamlessly, elevating user satisfaction.&lt;/p&gt;

&lt;h3&gt;
  
  
  Engaging Interactions
&lt;/h3&gt;

&lt;p&gt;Features like push notifications and app shortcuts keep users engaged, fostering a deeper connection with the application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Shareable and Secure
&lt;/h3&gt;

&lt;p&gt;PWAs can be conveniently shared via URLs, ensuring accessibility. Moreover, they're served over HTTPS, prioritizing security.&lt;/p&gt;

&lt;h2&gt;
  
  
  Under the Hood: Technologies Powering PWAs
&lt;/h2&gt;

&lt;p&gt;The brilliance of PWAs is underpinned by a trio of powerful technologies:&lt;/p&gt;

&lt;h3&gt;
  
  
  Web App Manifest
&lt;/h3&gt;

&lt;p&gt;A JSON file defines the app's characteristics, enabling users to install PWAs on their home screens, akin to native apps.&lt;/p&gt;

&lt;h3&gt;
  
  
  Service Workers
&lt;/h3&gt;

&lt;p&gt;These background scripts empower PWAs to deliver advanced functionalities like push notifications, offline support, and background synchronization.&lt;/p&gt;

&lt;h3&gt;
  
  
  Caching APIs
&lt;/h3&gt;

&lt;p&gt;Utilizing APIs like Cache Storage and Cache API, PWAs can cache resources, enabling offline access and enhancing performance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Unveiling the Benefits of PWAs
&lt;/h2&gt;

&lt;p&gt;PWAs offer a multitude of advantages that cater to the modern digital landscape:&lt;/p&gt;

&lt;h3&gt;
  
  
  Unified Experience
&lt;/h3&gt;

&lt;p&gt;Blending the finest attributes of both web and native apps, PWAs provide a unified, engaging, and fluid user experience.&lt;/p&gt;

&lt;h3&gt;
  
  
  Streamlined Development
&lt;/h3&gt;

&lt;p&gt;Developing and deploying PWAs often requires less complexity compared to traditional native app development.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cross-Platform Accessibility
&lt;/h3&gt;

&lt;p&gt;With PWAs, the need for separate apps for various operating systems diminishes, reaching a wider audience.&lt;/p&gt;

&lt;h3&gt;
  
  
  App Store Bypass
&lt;/h3&gt;

&lt;p&gt;Say goodbye to intricate app store approvals. PWAs allow you to release updates swiftly and efficiently.&lt;/p&gt;

&lt;h3&gt;
  
  
  Instant Updates
&lt;/h3&gt;

&lt;p&gt;Users instantly access the latest features, as PWAs seamlessly update in the background.&lt;/p&gt;

&lt;h2&gt;
  
  
  Real-World PWA Champions
&lt;/h2&gt;

&lt;p&gt;Leading brands have embraced PWAs to elevate their user experiences. Notable examples include Google Maps, Pinterest, Twitter Lite, and Instagram.&lt;/p&gt;

&lt;h2&gt;
  
  
  Joining the PWA Revolution
&lt;/h2&gt;

&lt;p&gt;As we venture further into an era where connectivity and user engagement define success, embracing PWAs holds the key to staying ahead of the curve. The realms of web and apps have converged, and PWAs are at the forefront of this transformation.&lt;/p&gt;

&lt;p&gt;This article is your gateway to understanding and exploring the dynamic world of PWAs. Feel free to dive in, contribute, and become a part of the PWA revolution. The future of digital interactions has arrived, and it's exhilarating.&lt;/p&gt;

</description>
      <category>pwa</category>
      <category>frontend</category>
      <category>webdev</category>
      <category>mobile</category>
    </item>
    <item>
      <title>Standing Out as a Front-End Developer: Mastering the Art of Web Innovation</title>
      <dc:creator>Anjan Karmakar</dc:creator>
      <pubDate>Mon, 28 Aug 2023 03:36:22 +0000</pubDate>
      <link>https://forem.com/47anjan/standing-out-as-a-front-end-developer-mastering-the-art-of-web-innovation-38jd</link>
      <guid>https://forem.com/47anjan/standing-out-as-a-front-end-developer-mastering-the-art-of-web-innovation-38jd</guid>
      <description>&lt;p&gt;In the fast-paced world of web development, being a proficient front-end developer is just the starting point. To truly excel and seize remarkable opportunities, it's crucial to stand out from the crowd. This README offers insights and strategies to help you shine as a front-end developer and make your mark in the industry.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Solidify Your Fundamentals&lt;/li&gt;
&lt;li&gt;Meticulous Attention to Design&lt;/li&gt;
&lt;li&gt;Responsive and Mobile-First Approach&lt;/li&gt;
&lt;li&gt;Embrace JavaScript Frameworks&lt;/li&gt;
&lt;li&gt;Continuous Learning and Upgrading&lt;/li&gt;
&lt;li&gt;Version Control and Collaboration&lt;/li&gt;
&lt;li&gt;Performance Optimization&lt;/li&gt;
&lt;li&gt;Soft Skills and Effective Communication&lt;/li&gt;
&lt;li&gt;Build an Impressive Portfolio&lt;/li&gt;
&lt;li&gt;Create Valuable Content&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Solidify Your Fundamentals
&lt;/h2&gt;

&lt;p&gt;Master the core technologies – HTML, CSS, and JavaScript. Stay updated with the latest specifications and advanced techniques. A strong grasp of the fundamentals ensures you create efficient, accessible, and visually appealing web applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Meticulous Attention to Design
&lt;/h2&gt;

&lt;p&gt;Understanding UX and UI design principles bridges the gap between designers and developers. Craft pixel-perfect interfaces, maintain design patterns, and deliver superior end products by merging development and design perspectives.&lt;/p&gt;

&lt;h2&gt;
  
  
  Responsive and Mobile-First Approach
&lt;/h2&gt;

&lt;p&gt;Prioritize mobile design and create responsive layouts that adapt to various screen sizes and devices. Embrace the mobile-first approach to provide seamless user experiences across the digital landscape.&lt;/p&gt;

&lt;h2&gt;
  
  
  Embrace JavaScript Frameworks
&lt;/h2&gt;

&lt;p&gt;Master popular frameworks like React, Angular, or Vue.js to build dynamic and interactive web applications. Component-based architecture, state management, and routing are your allies in creating robust projects.&lt;/p&gt;

&lt;h2&gt;
  
  
  Continuous Learning and Upgrading
&lt;/h2&gt;

&lt;p&gt;Stay updated with the latest trends, tools, and best practices. Engage with communities, follow influential blogs, and participate in events. Embrace change and new technologies to keep your skills relevant.&lt;/p&gt;

&lt;h2&gt;
  
  
  Version Control and Collaboration
&lt;/h2&gt;

&lt;p&gt;Proficiency in version control systems like Git is essential. Collaborate effectively by using platforms like GitHub to manage codebase changes and work seamlessly with teams.&lt;/p&gt;

&lt;h2&gt;
  
  
  Performance Optimization
&lt;/h2&gt;

&lt;p&gt;Prioritize website speed and performance by implementing techniques like code splitting and lazy loading. Optimizing assets showcases your commitment to delivering fast-loading and efficient web applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Soft Skills and Effective Communication
&lt;/h2&gt;

&lt;p&gt;Develop strong soft skills such as communication, teamwork, and problem-solving. Effective collaboration with cross-functional teams and the ability to translate technical concepts into understandable terms are key differentiators.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build an Impressive Portfolio
&lt;/h2&gt;

&lt;p&gt;Curate a diverse portfolio showcasing your skills, creativity, and problem-solving abilities. Personal and passion projects demonstrate your capabilities beyond standard assignments.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create Valuable Content
&lt;/h2&gt;

&lt;p&gt;Share your expertise through blogging, tutorials, or videos on platforms like Hashnode, Medium, or YouTube. By creating valuable content, you establish yourself as an authority in the field and contribute to the developer community.&lt;/p&gt;

&lt;p&gt;In conclusion, becoming an exceptional front-end developer goes beyond technical mastery. By embracing design principles, continuous learning, collaboration, and effective communication, you can carve a niche for yourself in the dynamic world of front-end development. Create memorable user experiences, showcase your skills, and stand out as a true innovator in the industry.&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>softwareengineering</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
    <item>
      <title>Building a Custom Hook to Track User's Online/Offline Status in React</title>
      <dc:creator>Anjan Karmakar</dc:creator>
      <pubDate>Sat, 26 Aug 2023 13:53:24 +0000</pubDate>
      <link>https://forem.com/47anjan/building-a-custom-hook-to-track-users-onlineoffline-status-in-react-12h6</link>
      <guid>https://forem.com/47anjan/building-a-custom-hook-to-track-users-onlineoffline-status-in-react-12h6</guid>
      <description>&lt;p&gt;In today's digitally connected world, understanding the user's online or offline status within a web application is becoming increasingly important. Whether you need to deliver real-time updates, enhance user experience, or manage data synchronization, having insights into the user's connectivity can be pivotal. In this guide, we will walk you through the process of creating a custom React hook that effortlessly tracks a user's online or offline status.&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Introduction&lt;/li&gt;
&lt;li&gt;Understanding the Code&lt;/li&gt;
&lt;li&gt;Using the Custom Hook&lt;/li&gt;
&lt;li&gt;Conclusion&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;With the internet being an integral part of modern life, web applications often need to adapt to users' varying connectivity. Imagine a chat application where you need to show when a user is online or offline, or an online document editor that needs to synchronize changes in real time. These scenarios illustrate the significance of knowing whether a user is currently online or offline. This guide will walk you through creating a custom React hook, &lt;code&gt;useOnline&lt;/code&gt;, that addresses this need effectively.&lt;/p&gt;

&lt;h2&gt;
  
  
  Understanding the Code
&lt;/h2&gt;

&lt;p&gt;Let's delve into the code you've provided and break it down step by step:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&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="s2"&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;const&lt;/span&gt; &lt;span class="nx"&gt;useOnline&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;isOnline&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setOnline&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="kc"&gt;false&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;handleOnline&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="nf"&gt;setOnline&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&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;handleOffline&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="nf"&gt;setOnline&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;false&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="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;online&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handleOnline&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;offline&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handleOffline&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;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;online&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handleOnline&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
      &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;removeEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;offline&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;handleOffline&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="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;isOnline&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;useOnline&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Importing Dependencies&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The code begins by importing essential dependencies from the React library: &lt;code&gt;useState&lt;/code&gt; and &lt;code&gt;useEffect&lt;/code&gt;. These hooks are fundamental for managing state and side effects within functional components.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Defining the Custom Hook&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The custom hook, &lt;code&gt;useOnline&lt;/code&gt;, is crafted using the concise arrow function syntax. This hook serves to determine whether the user is presently online or offline.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Initializing State&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Within the hook, a state variable &lt;code&gt;isOnline&lt;/code&gt; is initialized using the &lt;code&gt;useState&lt;/code&gt; hook. Its default value is &lt;code&gt;false&lt;/code&gt;, assuming the user starts in an offline state.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Defining Event Handlers&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Two event handler functions, &lt;code&gt;handleOnline&lt;/code&gt; and &lt;code&gt;handleOffline&lt;/code&gt;, are defined. These functions update the &lt;code&gt;isOnline&lt;/code&gt; state based on the online and offline events, respectively.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Setting Up Event Listeners&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;code&gt;useEffect&lt;/code&gt; hook is employed to attach event listeners to the &lt;code&gt;online&lt;/code&gt; and &lt;code&gt;offline&lt;/code&gt; events on the &lt;code&gt;document&lt;/code&gt; object. These listeners respond to changes in the user's connectivity status.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Cleaning Up Event Listeners&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To prevent memory leaks, the &lt;code&gt;useEffect&lt;/code&gt; hook returns a cleanup function. This function removes the event listeners when the component using the hook is unmounted.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Return Statement&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The hook's return statement provides the &lt;code&gt;isOnline&lt;/code&gt; state variable. This allows components using the hook to access the current online status of the user.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Using the Custom Hook
&lt;/h2&gt;

&lt;p&gt;Now that we've dissected the code, let's demonstrate how to integrate this custom hook into your components:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&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="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;useOnline&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./useOnline&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Adjust the import path as needed&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;OnlineStatus&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="nx"&gt;isOnline&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useOnline&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;You are currently &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;isOnline&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;online&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;offline&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;OnlineStatus&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, a new component named &lt;code&gt;OnlineStatus&lt;/code&gt; is created. Within this component, the &lt;code&gt;useOnline&lt;/code&gt; hook is harnessed to ascertain the user's current online status. Based on the value of &lt;code&gt;isOnline&lt;/code&gt;, an appropriate message is displayed.&lt;/p&gt;

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

&lt;p&gt;Developing custom hooks in React can significantly enhance code reusability and organization. The &lt;code&gt;useOnline&lt;/code&gt; hook we've constructed empowers you to seamlessly track user online or offline status, offering valuable insights to optimize your application's behavior. Whether you're building a dynamic chat platform, a collaborative document editor, or any innovative application, this custom hook can serve as a valuable asset in your development toolkit. Embrace the power of custom hooks to create more efficient and effective React applications.&lt;/p&gt;

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