<?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: Vaishnavi Nagendra</title>
    <description>The latest articles on DEV Community by Vaishnavi Nagendra (@vaishnavi_nagendra).</description>
    <link>https://dev.to/vaishnavi_nagendra</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%2F2056136%2F392c4f4d-5521-4ae7-a4ec-a00ea22eed95.png</url>
      <title>DEV Community: Vaishnavi Nagendra</title>
      <link>https://dev.to/vaishnavi_nagendra</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/vaishnavi_nagendra"/>
    <language>en</language>
    <item>
      <title>Just spent way too many hours trying to understand useEffect, useFocusEffect, and useCallback. Finally made sense of it — wrote a beginner-friendly post so you don’t have to suffer like I did 😅 Would love some feedback from fellow devs! 💻 #ReactJS #React</title>
      <dc:creator>Vaishnavi Nagendra</dc:creator>
      <pubDate>Sat, 21 Jun 2025 18:36:51 +0000</pubDate>
      <link>https://dev.to/vaishnavi_nagendra/just-spent-way-too-many-hours-trying-to-understand-useeffect-usefocuseffect-and-usecallback-1c2g</link>
      <guid>https://dev.to/vaishnavi_nagendra/just-spent-way-too-many-hours-trying-to-understand-useeffect-usefocuseffect-and-usecallback-1c2g</guid>
      <description>&lt;div class="ltag__link--embedded"&gt;
  &lt;div class="crayons-story "&gt;
  &lt;a href="https://dev.to/vaishnavi_nagendra/a-beginners-take-on-useeffect-vs-usefocuseffect-and-why-usecallback-matters-21nm" class="crayons-story__hidden-navigation-link"&gt;A Beginner’s Take on useEffect vs useFocusEffect – And Why useCallback Matters&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="/vaishnavi_nagendra" 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%2F2056136%2F392c4f4d-5521-4ae7-a4ec-a00ea22eed95.png" alt="vaishnavi_nagendra profile" class="crayons-avatar__image"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="/vaishnavi_nagendra" class="crayons-story__secondary fw-medium m:hidden"&gt;
              Vaishnavi Nagendra
            &lt;/a&gt;
            &lt;div class="profile-preview-card relative mb-4 s:mb-0 fw-medium hidden m:inline-block"&gt;
              
                Vaishnavi Nagendra
                
              
              &lt;div id="story-author-preview-content-2612997" 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="/vaishnavi_nagendra" 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%2F2056136%2F392c4f4d-5521-4ae7-a4ec-a00ea22eed95.png" class="crayons-avatar__image" alt=""&gt;
                      &lt;/span&gt;
                      &lt;span class="crayons-link crayons-subtitle-2 mt-5"&gt;Vaishnavi Nagendra&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/vaishnavi_nagendra/a-beginners-take-on-useeffect-vs-usefocuseffect-and-why-usecallback-matters-21nm" class="crayons-story__tertiary fs-xs"&gt;&lt;time&gt;Jun 21 '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/vaishnavi_nagendra/a-beginners-take-on-useeffect-vs-usefocuseffect-and-why-usecallback-matters-21nm" id="article-link-2612997"&gt;
          A Beginner’s Take on useEffect vs useFocusEffect – And Why useCallback Matters
        &lt;/a&gt;
      &lt;/h2&gt;
        &lt;div class="crayons-story__tags"&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;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/reactnative"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;reactnative&lt;/a&gt;
            &lt;a class="crayons-tag  crayons-tag--monochrome " href="/t/javascript"&gt;&lt;span class="crayons-tag__prefix"&gt;#&lt;/span&gt;javascript&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/vaishnavi_nagendra/a-beginners-take-on-useeffect-vs-usefocuseffect-and-why-usecallback-matters-21nm" 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/multi-unicorn-b44d6f8c23cdd00964192bedc38af3e82463978aa611b4365bd33a0f1f4f3e97.svg" width="18" height="18"&gt;
                  &lt;/span&gt;
                  &lt;span class="crayons_icon_container"&gt;
                    &lt;img src="https://assets.dev.to/assets/raised-hands-74b2099fd66a39f2d7eed9305ee0f4553df0eb7b4f11b01b6b1b499973048fe5.svg" width="18" height="18"&gt;
                  &lt;/span&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;30&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/vaishnavi_nagendra/a-beginners-take-on-useeffect-vs-usefocuseffect-and-why-usecallback-matters-21nm#comments" class="crayons-btn crayons-btn--s crayons-btn--ghost crayons-btn--icon-left flex items-center"&gt;
              Comments


              6&lt;span class="hidden s:inline"&gt; comments&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;
            3 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>programming</category>
      <category>beginners</category>
      <category>reactnative</category>
      <category>javascript</category>
    </item>
    <item>
      <title>A Beginner’s Take on useEffect vs useFocusEffect – And Why useCallback Matters</title>
      <dc:creator>Vaishnavi Nagendra</dc:creator>
      <pubDate>Sat, 21 Jun 2025 18:31:23 +0000</pubDate>
      <link>https://dev.to/vaishnavi_nagendra/a-beginners-take-on-useeffect-vs-usefocuseffect-and-why-usecallback-matters-21nm</link>
      <guid>https://dev.to/vaishnavi_nagendra/a-beginners-take-on-useeffect-vs-usefocuseffect-and-why-usecallback-matters-21nm</guid>
      <description>&lt;p&gt;As a junior React developer, if there was one of the many things that troubled me in React JS, it was hooks! Although a few of them were quite easy to understand, the rest kind of kept me 'hooked' for quite some time until I kinda 'mastered' them—watching YouTube tutorials, annoying my OG GPT with a million questions… I’ve done it all. So here's my beginner's guide to two of the most important or you can say not so beginner-friendly hooks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📝 Note: useFocusEffect is from React Navigation, not React core, and is used in React Native.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before we dive into these concepts, we need to understand one thing, the structure of both the hooks remains the same&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🎯 A common structure&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;useHookName(() =&amp;gt; { 
    doSomething();
},[[ifThisChanges]]}; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It comprises a JavaScript method asking it to perform some action (doSomething()); based on the dependancy array (ifThisChanges). Now, what if the dependancy array is empty? The action will be triggered once &lt;strong&gt;on mount&lt;/strong&gt;, that is the first time a component is rendered on a screen.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. useEffect()🔥
&lt;/h2&gt;

&lt;p&gt;Let's start with the internet definition of it 'useEffect is a React Hook that lets you synchronize a component with an external system'.&lt;br&gt;
Didn't get sh**? Same! Basically, useEffect only runs in two situations: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. When the component is mounted 🎗️&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;useEffect(() =&amp;gt; {
  console.log("omg!");
}, []);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Mounted&lt;/strong&gt; meaning when the component is rendered for the first time ever—that’s when this 'omg!' will be logged. With nothing specified in the dependency array, the action is triggered only once on mount.&lt;/p&gt;

&lt;p&gt;But what if we decide to pass no dependency array at all? 💀&lt;br&gt;
Since we’re using React, the component gets rendered—oh lord—a million times!&lt;br&gt;
A tiny change in the useState? Re-renders.&lt;br&gt;
Parent component re-renders and passes new props to a child? THE CHILD ALSO!!! re-renders.&lt;/p&gt;

&lt;p&gt;Yeah, given that we deal with a lot of re-renders... No thanks. Not recommended.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. On mount + when something in the dependancy array changes 📆&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;useEffect(() =&amp;gt; {
  getProfileDetails();
}, [userId]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As seen in the first scenario, once the component is mounted onto the screen the action gets triggered, but what if i explicitly specify when the action needs to be triggered? That's when this dependancy array comes into the picture, you only getProfileDetails() when the userId is changed/updated, if not, it just sits there (chilling) 😎occupying some space in my code.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. useFocusEffect with useCallback 🔎
&lt;/h2&gt;

&lt;p&gt;Alright, Let's just say useFocusEffect is that one, attention-seeking younger sibling of useEffect, Obviously, it does everything that useEffect does 😒 (typical). but with a twist—an important difference is that every time the screen comes into focus the action/function specified in the hook runs. It’s tied to screen focus, not just rendering. So, u leave the screen --&amp;gt; navigate back to it &amp;lt;-- the action is performed.  &lt;/p&gt;

&lt;p&gt;Now, it is only valid to use this hook paired up with useCallback().&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;❎ Without the useCallback:&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;useFocusEffect(() =&amp;gt; {
  // this will re-run every time the screen re-renders
}); 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;"this will re-run every time the screen re-renders". Well, that doesn't sound good, right? Exactly why a useCallback hook is required! It returns a &lt;em&gt;memoized&lt;/em&gt; version—or a remembered version—of the function that only changes when dependencies change. &lt;/p&gt;

&lt;p&gt;Every time the screen gains focus or the parent component re-renders, the function gets re-created, which may cause unnecessary executions or side-effects. Who would want that now?! That would negate the whole point of using useFocusEffect.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;✅ With the useCallback(recommended):&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;useFocusEffect(
  useCallback(() =&amp;gt; {
    fetchDataOrDoSomething(); // runs every time the screen comes into focus
  }, [dependency])
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🥇Runs every time the screen gains focus (like navigating to that screen).&lt;/p&gt;

&lt;p&gt;🥈Memoizing(Caching) the function using useCallback prevents unnecessary re-runs when the screen is already focused and the parent component just re-renders. &lt;/p&gt;

&lt;p&gt;In conclusion, it prevents the usual behaviour of react where if the child component to which the props are passed also re-renders when the parent component re-renders.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;👀 PS: Memoizing(not a fan of this term) so &lt;del&gt;memoizing&lt;/del&gt; caching, &lt;br&gt;
saving, remembering 👍🏻.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Breakdown: useEffect vs useFocusEffect
&lt;/h2&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%2F95rtcm78kf0gyew6vrgo.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%2F95rtcm78kf0gyew6vrgo.png" alt="Image description" width="800" height="168"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;This was my understanding of the two most (can-be-confusing) hooks of react, I did not jump into the more advance parts of it—although that’s very important too (like the &lt;strong&gt;cleanup function&lt;/strong&gt;). Will try writing another post just diving deeper into a single hook!&lt;/p&gt;

&lt;p&gt;If you're still figuring it out or have a different way of remembering these hooks, drop a comment! I’d love to hear how you made sense of them — we’re all just learning out loud here anyway. 🙌&lt;/p&gt;

&lt;p&gt;Hope it helps some fellow rookies just getting started with React!&lt;br&gt;
&lt;strong&gt;Happy learning :)&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>programming</category>
      <category>beginners</category>
      <category>reactnative</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
