<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sajid M on Medium]]></title>
        <description><![CDATA[Stories by Sajid M on Medium]]></description>
        <link>https://medium.com/@sajidprimero?source=rss-92a26bb8b469------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*M3kWET4Tsl38D09_.</url>
            <title>Stories by Sajid M on Medium</title>
            <link>https://medium.com/@sajidprimero?source=rss-92a26bb8b469------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 08:42:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sajidprimero/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ 5 Tricky React Interview Questions (That Reveal Real Understanding)- Part 1]]></title>
            <link>https://medium.com/@sajidprimero/5-tricky-react-interview-questions-that-reveal-real-understanding-part-1-cb9dc85bc61d?source=rss-92a26bb8b469------2</link>
            <guid isPermaLink="false">https://medium.com/p/cb9dc85bc61d</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript-interview]]></category>
            <category><![CDATA[react-interview]]></category>
            <category><![CDATA[react-js-tutorials]]></category>
            <category><![CDATA[react-interview-question]]></category>
            <dc:creator><![CDATA[Sajid M]]></dc:creator>
            <pubDate>Sun, 29 Mar 2026 18:54:56 GMT</pubDate>
            <atom:updated>2026-03-29T18:54:56.623Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vUXeJ1lO1NBSlwcuklP1OQ.png" /></figure><p>If you’re preparing for a React interview, you’ve probably practiced a lot of questions.</p><p>But here’s the truth:</p><blockquote><em>Most interviews don’t test what you </em>know<em> — they test how you </em>think<em>.</em></blockquote><p>In this post, I’ll walk you through 5 tricky React questions that I personally encountered across multiple interviews. These are the kind of questions that can easily catch you off guard if you’re not prepared. This is Part 1 — more such questions are on the way.</p><p>👉 Try to answer each one <strong>before</strong> reading the explanation.</p><h3>1️⃣ Why does this log the old value?</h3><pre>const [count, setCount] = useState(0);</pre><pre>const handleClick = () =&gt; {<br>  setCount(count + 1);<br>  console.log(count);<br>};</pre><h3>🤔 What do you expect?</h3><p>Will it log the updated value?</p><h3>✅ Answer:</h3><p>It logs the <strong>old value</strong>.</p><h3>💡 Explanation:</h3><p>State updates in React are <strong>asynchronous</strong>. When setCount is called, React schedules the update, but it doesn’t happen immediately.</p><p>So console.log(count) still sees the previous value.</p><h3>✅ Fix (if needed):</h3><pre>useEffect(() =&gt; {<br>  console.log(count);<br>}, [count]);</pre><h3>2️⃣ Find the infinite loop</h3><pre>useEffect(() =&gt; {<br>  setCount(count + 1);<br>}, [count]);</pre><h3>🤔 What happens here?</h3><h3>❌ Problem:</h3><p>This creates an <strong>infinite loop</strong>.</p><h3>💡 Why?</h3><ul><li>count changes → useEffect runs</li><li>useEffect updates count again</li><li>Repeat forever</li></ul><h3>✅ Fix:</h3><pre>useEffect(() =&gt; {<br>  setCount(prev =&gt; prev + 1);<br>}, []);</pre><h3>🧠 Lesson:</h3><p>Be careful with dependencies in useEffect. They control when your effect runs.</p><h3>3️⃣ Why is this causing unnecessary re-renders?</h3><pre>&lt;MyComponent onClick={() =&gt; console.log(&quot;clicked&quot;)} /&gt;</pre><h3>🤔 Looks harmless, right?</h3><h3>❌ Problem:</h3><p>A <strong>new function</strong> is created on every render.</p><p>If MyComponent is optimized (e.g., using React.memo), it will still re-render because the prop reference changes.</p><h3>✅ Fix:</h3><pre>const handleClick = useCallback(() =&gt; {<br>  console.log(&quot;clicked&quot;);<br>}, []);</pre><pre>&lt;MyComponent onClick={handleClick} /&gt;</pre><h3>🧠 Lesson:</h3><p>Function identity matters in React.</p><h3>4️⃣ What’s wrong with this list?</h3><pre>items.map((item, index) =&gt; (<br>  &lt;div key={index}&gt;{item.name}&lt;/div&gt;<br>));</pre><h3>❌ Problem:</h3><p>Using index as a key can cause <strong>UI bugs</strong>.</p><h3>💡 Why?</h3><p>When the list changes (add/remove/reorder), React can’t properly track items.</p><h3>✅ Fix:</h3><pre>items.map(item =&gt; (<br>  &lt;div key={item.id}&gt;{item.name}&lt;/div&gt;<br>));</pre><h3>🧠 Lesson:</h3><p>Keys must be <strong>stable and unique</strong>.</p><h3>5️⃣ Why doesn’t this update work correctly?</h3><pre>const [user, setUser] = useState({ name: &quot;John&quot; });</pre><pre>const updateName = () =&gt; {<br>  user.name = &quot;Mike&quot;;<br>  setUser(user);<br>};</pre><h3>❌ Problem:</h3><p>You’re <strong>mutating state directly</strong>.</p><p>React compares references, not deep values. Since the object reference didn’t change, React may skip re-rendering.</p><h3>✅ Fix:</h3><pre>setUser({ ...user, name: &quot;Mike&quot; });</pre><h3>🧠 Lesson:</h3><p>Always treat state as <strong>immutable</strong>.</p><h3>⚡ Quick Recap</h3><ul><li>State updates are <strong>not immediate</strong></li><li>useEffect dependencies control execution</li><li>Functions can trigger re-renders</li><li>Keys must be stable</li><li>Never mutate state directly</li></ul><h3>🎯 Final Thought</h3><p>These questions aren’t just for interviews.</p><p>They reflect <strong>real-world bugs</strong> that even experienced developers run into.</p><p>Master these, and you’ll not only crack interviews — you’ll write <strong>better React code every day</strong>.</p><h3>✍️ If this helped you…</h3><p>Follow for more practical React insights 🚀<br> More deep-but-simple posts coming soon!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cb9dc85bc61d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ useEffect Explained in the Simplest Way Possible]]></title>
            <link>https://medium.com/@sajidprimero/useeffect-explained-in-the-simplest-way-possible-8dec89fff825?source=rss-92a26bb8b469------2</link>
            <guid isPermaLink="false">https://medium.com/p/8dec89fff825</guid>
            <category><![CDATA[react-hook-useeffect]]></category>
            <category><![CDATA[useeffect-hook]]></category>
            <category><![CDATA[useeffect]]></category>
            <category><![CDATA[react-useeffect]]></category>
            <category><![CDATA[useeffect-hook-in-react]]></category>
            <dc:creator><![CDATA[Sajid M]]></dc:creator>
            <pubDate>Sun, 29 Mar 2026 18:45:39 GMT</pubDate>
            <atom:updated>2026-03-29T18:45:39.549Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PTnfzbCeEs4gGWS0dBmtiQ.png" /></figure><p>If you’re learning React, you’ve probably seen useEffect and thought:</p><blockquote><em>“Why is this so confusing?”</em></blockquote><p>You’re not alone.</p><p>In this post, I’ll break down useEffect into <strong>3 simple use cases</strong>:</p><ul><li>Run once</li><li>Run when something changes</li><li>Cleanup</li></ul><p>No complex jargon. Just clarity.</p><h3>🧠 What is useEffect?</h3><p>useEffect lets you run code <strong>after your component renders</strong>.</p><p>Think of it like:<br> 👉 “Run this after the UI is updated.”</p><h3>1️⃣ Run Once (Like componentDidMount)</h3><p>If you want something to run <strong>only once when the component loads</strong>, use an empty dependency array.</p><pre>import { useEffect } from &quot;react&quot;;</pre><pre>useEffect(() =&gt; {<br>  console.log(&quot;Component mounted&quot;);<br>}, []);</pre><h3>✅ When to use:</h3><ul><li>API calls</li><li>Initial setup</li><li>Fetching data</li></ul><p>👉 The empty [] means:<br> <strong>“Run this only once”</strong></p><h3>2️⃣ Run When Something Changes</h3><p>You can tell useEffect to run when a specific value changes.</p><pre>import { useEffect, useState } from &quot;react&quot;;</pre><pre>const [count, setCount] = useState(0);</pre><pre>useEffect(() =&gt; {<br>  console.log(&quot;Count changed:&quot;, count);<br>}, [count]);</pre><h3>✅ When to use:</h3><ul><li>Watching state changes</li><li>Triggering side effects based on user actions</li></ul><p>👉 [count] means:<br> <strong>“Run this whenever the count changes.”</strong></p><h3>3️⃣ Cleanup (Very Important ⚠️)</h3><p>Sometimes you need to <strong>clean up</strong> things like:</p><ul><li>Timers</li><li>Event listeners</li><li>Subscriptions</li></ul><pre>useEffect(() =&gt; {<br>  const interval = setInterval(() =&gt; {<br>    console.log(&quot;Running...&quot;);<br>  }, 1000);</pre><pre>  return () =&gt; {<br>    clearInterval(interval);<br>    console.log(&quot;Cleaned up&quot;);<br>  };<br>}, []);</pre><h3>✅ When to use:</h3><ul><li>Prevent memory leaks</li><li>Stop background processes</li></ul><p>👉 The return function runs:<br> <strong>“Before the component is removed or re-run.”</strong></p><h3>⚡ Quick Summary</h3><p>Use CaseCode PatternRun onceuseEffect(fn, [])On changeuseEffect(fn, [value])Cleanupreturn () =&gt; {}</p><h3>🚫 Common Mistake</h3><p>Forgetting dependencies:</p><pre>useEffect(() =&gt; {<br>  console.log(count);<br>}, []); // ❌ Wrong if count is used</pre><p>👉 This can cause bugs because React won’t track changes.</p><h3>🎯 Final Thought</h3><p>useEffect is not complicated.</p><p>Just remember:</p><ul><li><strong>No array → runs every time</strong></li><li><strong>Empty array → runs once</strong></li><li><strong>With values → runs on change</strong></li><li><strong>Return function → cleanup</strong></li></ul><p>That’s it.</p><h3>✍️ If this helped you…</h3><p>Follow me for more simple React tips 🚀<br> More practical posts coming soon!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8dec89fff825" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[3 React Tips I Wish I Knew Earlier]]></title>
            <link>https://medium.com/@sajidprimero/3-react-tips-i-wish-i-knew-earlier-dab249524a90?source=rss-92a26bb8b469------2</link>
            <guid isPermaLink="false">https://medium.com/p/dab249524a90</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[react-beginner-guide]]></category>
            <category><![CDATA[react-tips]]></category>
            <dc:creator><![CDATA[Sajid M]]></dc:creator>
            <pubDate>Mon, 23 Mar 2026 06:36:47 GMT</pubDate>
            <atom:updated>2026-03-23T06:36:47.254Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TSkLhAq_oj-onk1dzF_mjw.jpeg" /></figure><p>When I started learning React, I focused a lot on making things <em>work</em>.<br>But over time, I realized that writing <strong>clean and simple code</strong> is just as important. If you’re new to React, these small tips can make a big difference.</p><p>Here are 3 small React tips I wish I knew earlier — they made my code much easier to read and maintain.</p><h3>1. Use Early Return Instead of Nested Conditions</h3><p>In the beginning, I used a lot of if-else blocks inside my components.</p><p><strong>Before:</strong></p><pre>function App({ user }) {<br>  if (user) {<br>    return &lt;Dashboard /&gt;;<br>  } else {<br>    return &lt;Login /&gt;;<br>  }<br>}</pre><p><strong>After:</strong></p><pre>function App({ user }) {<br>  if (!user) return &lt;Login /&gt;;<br>  return &lt;Dashboard /&gt;;<br>}</pre><p>👉 This reduces nesting and makes your component easier to scan.</p><h3>2. Destructure Props for Cleaner Code</h3><p>Accessing props using props.name everywhere can get repetitive.</p><p><strong>Before:</strong></p><pre>function Welcome(props) {<br>  return &lt;h1&gt;Hello {props.name}&lt;/h1&gt;;<br>}</pre><p><strong>After:</strong></p><pre>function Welcome({ name }) {<br>  return &lt;h1&gt;Hello {name}&lt;/h1&gt;;<br>}</pre><p>👉 Destructuring keeps your code shorter and more readable.</p><h3>3. Use Optional Chaining to Avoid Errors</h3><p>Sometimes your data might not be available immediately (like from an API), and accessing nested properties can crash your app.</p><p><strong>Before:</strong></p><pre>user.profile.avatar</pre><p>❌ This can throw an error if user or profile is undefined.</p><p><strong>After:</strong></p><pre>user?.profile?.avatar</pre><p>👉 Optional chaining prevents runtime errors and keeps your app safe.</p><h3>Final Thoughts</h3><p>These are small changes, but they make a big difference in how your React code looks and feels.</p><p>If you’re just starting with React, try using these tips in your next project — you’ll notice the improvement immediately.</p><p><em>Which tip did you find most useful?</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dab249524a90" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>