<?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: Tarun Sharma</title>
    <description>The latest articles on DEV Community by Tarun Sharma (@101beardo).</description>
    <link>https://dev.to/101beardo</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4074008%2F83b63d19-4973-412d-bc59-b836ea597026.jpg</url>
      <title>DEV Community: Tarun Sharma</title>
      <link>https://dev.to/101beardo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/101beardo"/>
    <language>en</language>
    <item>
      <title>useMemo and useCallback: 5 things that actually trip people up</title>
      <dc:creator>Tarun Sharma</dc:creator>
      <pubDate>Tue, 18 Aug 2026 12:47:54 +0000</pubDate>
      <link>https://dev.to/101beardo/usememo-and-usecallback-5-things-that-actually-trip-people-up-4o0l</link>
      <guid>https://dev.to/101beardo/usememo-and-usecallback-5-things-that-actually-trip-people-up-4o0l</guid>
      <description>&lt;p&gt;Both of these get memorized as syntax pretty fast. What doesn't get memorized is what they're actually doing under the hood, and that's where the bugs show up. Here's the stuff that actually trips people up once you go past "wrap it in useMemo I guess."&lt;/p&gt;

&lt;h2&gt;
  
  
  1. They solve different problems, not the same one
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;useMemo&lt;/code&gt; caches a value. &lt;code&gt;useCallback&lt;/code&gt; caches a function reference. People treat them like interchangeable "make it faster" hooks, but &lt;code&gt;useCallback(fn, deps)&lt;/code&gt; is really just &lt;code&gt;useMemo(() =&amp;gt; fn, deps)&lt;/code&gt; under the hood, it just hands you back the function itself instead of calling it for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Neither one makes your code faster by default
&lt;/h2&gt;

&lt;p&gt;Wrapping something in &lt;code&gt;useMemo&lt;/code&gt; has a cost too, it runs the dependency comparison on every render. If the calculation inside is cheap, you're paying more than you save. Reach for these when the calculation is genuinely expensive, or when the value needs to keep the same reference across renders (see #3), not as a reflex on every derived value.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. The real reason you need useCallback: keeping props stable for React.memo
&lt;/h2&gt;

&lt;p&gt;If you pass a normal inline function as a prop to a memoized child, that child re-renders anyway, because the function is a new reference every single render. &lt;code&gt;useCallback&lt;/code&gt; is what actually keeps that reference stable across renders so &lt;code&gt;React.memo&lt;/code&gt;'s shallow comparison has something to bail out on. Without it, memo is comparing a new function to another new function every time and always finding them "different."&lt;/p&gt;

&lt;h2&gt;
  
  
  4. The dependency array lies just as easily here as with useEffect
&lt;/h2&gt;

&lt;p&gt;Same stale closure trap you'd hit with &lt;code&gt;useEffect&lt;/code&gt;. If you memoize a function with &lt;code&gt;useCallback(fn, [])&lt;/code&gt; and &lt;code&gt;fn&lt;/code&gt; reads a prop or state value from outside, you get a function frozen with whatever that value was on the first render. The fix is the same one as always: put it in the deps array, don't fight the linter into silence.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Object and array literals as deps break memoization silently
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;useMemo(() =&amp;gt; doSomething(config), [config])&lt;/code&gt; looks safe until &lt;code&gt;config&lt;/code&gt; is &lt;code&gt;{ foo: bar }&lt;/code&gt; created inline on every render, in which case the dependency is a new reference every time and the memo never actually hits, it recalculates every render while looking like it's working. Move the object outside the render, or memoize it too.&lt;/p&gt;

&lt;p&gt;Curious what the actual useMemo or useCallback bug was that got you. Drop it below, would love to hear it.&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>interview</category>
    </item>
    <item>
      <title>5 React interview questions I'd actually ask (and how I'd answer them)</title>
      <dc:creator>Tarun Sharma</dc:creator>
      <pubDate>Fri, 14 Aug 2026 08:26:33 +0000</pubDate>
      <link>https://dev.to/101beardo/5-react-interview-questions-id-actually-ask-and-how-id-answer-them-3422</link>
      <guid>https://dev.to/101beardo/5-react-interview-questions-id-actually-ask-and-how-id-answer-them-3422</guid>
      <description>&lt;p&gt;Most "React interview questions" lists online are either trivia (define useEffect) or so advanced they're not useful below 3-4 years of experience. Here are 5 I think are actually worth knowing, with the answer I'd give if asked.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. What does this log, and why?
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nx"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&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="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="nx"&gt;i&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;It logs &lt;code&gt;3, 3, 3&lt;/code&gt;. &lt;code&gt;var&lt;/code&gt; gives the whole loop one shared variable, so by the time the callbacks run, the loop has already finished and &lt;code&gt;i&lt;/code&gt; is 3. Swap &lt;code&gt;var&lt;/code&gt; for &lt;code&gt;let&lt;/code&gt; and it logs &lt;code&gt;0, 1, 2&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt; creates a fresh binding for every iteration, so each callback closes over its own copy.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Why doesn't an empty dependency array guarantee no stale-closure bugs?
&lt;/h2&gt;

&lt;p&gt;An effect with &lt;code&gt;[]&lt;/code&gt; only runs once, but any function or state it references from the render it was created in is frozen at that value forever, that's a stale closure. It's the same mechanism as question 1, just applied to a React render instead of a loop iteration.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. What's the actual difference between useMemo and useCallback?
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;useCallback(fn, deps)&lt;/code&gt; is just &lt;code&gt;useMemo(() =&amp;gt; fn, deps)&lt;/code&gt;. One memoizes a value, the other memoizes a function reference. People treat them as separate concepts when one is a special case of the other.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Why can a sibling component re-render even though its own props didn't change?
&lt;/h2&gt;

&lt;p&gt;Because React re-renders every child of a component that re-renders, by default, regardless of whether that specific child's props changed. &lt;code&gt;React.memo&lt;/code&gt; is what actually stops it, re-rendering isn't opt-out at the parent level, it's opt-in per child.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. What does the virtual DOM actually skip?
&lt;/h2&gt;

&lt;p&gt;It skips DOM writes, not DOM reads or re-renders. React still runs your component function and builds a new tree every render; the virtual DOM diff is what decides which actual DOM mutations are necessary, which are usually the expensive part.&lt;/p&gt;

&lt;p&gt;What would you add to this list?&lt;/p&gt;

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