<?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 Sai Amanaganti on Medium]]></title>
        <description><![CDATA[Stories by Sai Amanaganti on Medium]]></description>
        <link>https://medium.com/@saiamanaganti12?source=rss-d4a81cb46fd4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*dmCoubueDH4KwM5D</url>
            <title>Stories by Sai Amanaganti on Medium</title>
            <link>https://medium.com/@saiamanaganti12?source=rss-d4a81cb46fd4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 16:48:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@saiamanaganti12/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[React, Explained From Zero — Part 11: useEffect and the React Lifecycle]]></title>
            <link>https://medium.com/@saiamanaganti12/react-explained-from-zero-part-11-useeffect-and-the-react-lifecycle-3c6e91596b6a?source=rss-d4a81cb46fd4------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c6e91596b6a</guid>
            <category><![CDATA[react-lifecycle]]></category>
            <category><![CDATA[useeffect]]></category>
            <category><![CDATA[lifecycle]]></category>
            <dc:creator><![CDATA[Sai Amanaganti]]></dc:creator>
            <pubDate>Sat, 28 Mar 2026 10:09:20 GMT</pubDate>
            <atom:updated>2026-03-28T10:09:20.403Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sgn-Iw1asaPCg63fmnwdEg.png" /></figure><p>In the previous part of this series, you learned how to:</p><ul><li>Share data with useContext</li><li>Manage complex state with useReducer</li><li>Reuse logic with custom hooks</li></ul><p>Now we finally arrive at one of the most important — and most misunderstood — parts of React:</p><p><strong>useEffect</strong></p><p>This is where everything about <em>hooks, timing, and lifecycle</em> comes together.</p><h3>Goal of This Part</h3><p>By the end of this article, you will:</p><ul><li>Understand what useEffect actually does</li><li>Understand the <strong>React lifecycle in functional components</strong></li><li>Know when and why useEffect runs</li><li>Stop guessing and start predicting behavior</li></ul><h3>First: What Problem Does useEffect Solve?</h3><p>So far, your components run like this:</p><pre>function App() {<br>  return &lt;h1&gt;Hello&lt;/h1&gt;;<br>}</pre><p>What happens?</p><ul><li>The function runs</li><li>JSX is returned</li><li>The UI updates</li></ul><p>That’s it.</p><p>But real apps need more.</p><p>What if you want to:</p><ul><li>Log something when the component loads?</li><li>Fetch data from an API?</li><li>Run code when state changes?</li><li>Set up a timer?</li><li>Clean something up?</li></ul><h3>Why Not Just Put That Code in the Component?</h3><p>You <em>can</em> technically write code inside the component body.</p><p>But you <strong>shouldn’t</strong> for side effects.</p><p>Why?</p><p>Because the component function runs on <strong>every render</strong></p><p>So your code would:</p><ul><li>Run again and again</li><li>Cause bugs</li><li>Create performance issues</li></ul><h3>The Big Rule</h3><blockquote><strong><em>The component body is for rendering UI — not side effects.</em></strong></blockquote><h3>What Are Side Effects?</h3><p>Side effects are anything that interacts with the outside world:</p><ul><li>Fetching data</li><li>Logging</li><li>Timers (setInterval, setTimeout)</li><li>Subscriptions</li><li>Manual DOM interaction</li></ul><p>useEffect exists to handle <strong>side effects safely</strong>. It is used when your component needs to stay in sync with something outside React (like APIs, timers, or the browser).</p><h3>What Is useEffect?</h3><p>In simple terms:</p><blockquote><strong><em>useEffect lets you run code at specific moments in a component’s life.</em></strong></blockquote><p>It answers questions like:</p><ul><li>“Run this when the component first appears”</li><li>“Run this when a value changes”</li><li>“Clean this up when the component disappears”</li></ul><h3>The Core Idea</h3><p>React always does this:</p><ol><li>Render the UI</li><li>Update the screen</li><li>Then run effects</li></ol><blockquote><em>Effects happen </em><strong><em>after rendering</em></strong><em>, never during.</em></blockquote><p>This is critical.</p><h3>Think of useEffect Like This</h3><ul><li>Render → <em>What should the UI look like?</em></li><li>Effect → <em>Now that it’s rendered, what else should happen?</em></li></ul><h3>Your First useEffect (Runs Once)</h3><pre>import { useEffect } from &quot;react&quot;;<br><br>function App() {<br>  useEffect(() =&gt; {<br>    console.log(&quot;Component mounted&quot;);<br>  }, []);<br>  return &lt;h1&gt;Hello&lt;/h1&gt;;<br>}</pre><p>What happens here?</p><ul><li>Component renders</li><li>React updates the screen</li><li>Then the effect runs</li><li>Message logs once</li></ul><h3>Why the Empty Array []?</h3><p>This part confuses everyone at first — so let’s keep it simple.</p><pre>useEffect(() =&gt; {<br>  // effect<br>}, []);</pre><p>The empty array means:</p><blockquote><strong><em>“This effect does not depend on anything.”</em></strong></blockquote><p>So React runs it:</p><ul><li>Once, when the component appears</li><li>Never again</li></ul><p>This is similar to “component did mount” — without classes.</p><h3>The React Lifecycle (Simple Version)</h3><p>You do <strong>not</strong> need complex lifecycle charts.</p><p>Just remember this:</p><pre>Component appears → mount<br>Component updates → update<br>Component disappears → unmount</pre><p>useEffect lets you run code at each of these moments.</p><h3>Running an Effect When State Changes</h3><p>Now let’s react to state changes.</p><pre>import { useState, useEffect } from &quot;react&quot;;<br><br>function App() {<br>  const [name, setName] = useState(&quot;&quot;);<br>  useEffect(() =&gt; {<br>    console.log(&quot;Name changed:&quot;, name);<br>  }, [name]);<br>   <br>  return (<br>    &lt;input<br>      value={name}<br>      onChange={(e) =&gt; setName(e.target.value)}<br>    /&gt;<br>  );<br>}</pre><p>What’s happening?</p><ul><li>User types</li><li>State updates</li><li>Component re-renders</li><li>Effect runs because name changed</li></ul><h3>The Dependency Array</h3><p>This part is critical.</p><pre>useEffect(() =&gt; {<br>  // code<br>}, [name]);</pre><p>Means:</p><blockquote><em>“Run this effect whenever name changes.”</em></blockquote><p>Rules:</p><ul><li>No array → runs after every render</li><li>Empty array → runs once</li><li>Values inside → runs when those values change</li></ul><p>That’s it.</p><h3>How React Decides</h3><p>React compares values between renders.</p><p>If any dependency changes → effect runs again.</p><h3>Common Beginner Mistake #1: Missing Dependencies</h3><p>This runs too often:</p><pre>useEffect(() =&gt; {<br>  console.log(&quot;Runs every render&quot;);<br>});</pre><h3>Why is this problematic?</h3><p>Without the dependency array, <strong>the effect will run after every render</strong> (not just once or when a specific value changes).</p><p>This could result in</p><ul><li>unnecessary API calls</li><li>performance issues</li><li>unpredictable behaviour.</li></ul><p><strong>Solution</strong>: Always ask: <strong>“When should this run?”</strong><br>Then reflect that in the dependency array.</p><h3>Cleaning Up Effects</h3><p>Some effects need cleanup. For example, if you’re setting up a <strong>timer</strong> or subscribing to an event, you should clean it up when the component disappears (unmounts).</p><p>Example: timers.</p><pre>useEffect(() =&gt; {<br>  const timer = setInterval(() =&gt; {<br>    console.log(&quot;Tick&quot;);<br>  }, 1000);<br><br>  return () =&gt; {<br>    clearInterval(timer);<br>  };<br>}, []);</pre><h3>What’s happening?</h3><ol><li>The effect runs when the component mounts (the timer starts).</li><li>The cleanup function (return () =&gt; clearInterval(timer)) runs when the component unmounts, clearing the timer.</li></ol><p>This prevents <strong>memory leaks</strong> and unnecessary resource consumption.</p><h3>Cleanup Mental Model</h3><p>If your effect sets something up (like a timer or subscription), it should clean it up when the component unmounts.</p><p>Examples:</p><ul><li>Timers → clear them</li><li>Subscriptions → unsubscribe</li><li>Event listeners → remove them</li></ul><h3>Why Cleanup Matters</h3><p>Without cleanup:</p><ul><li>Memory leaks</li><li>Duplicate listeners</li><li>Strange bugs</li></ul><h3>What useEffect Is NOT</h3><p>useEffect is <strong>not</strong>:</p><ul><li>A replacement for state</li><li>A place for rendering logic</li><li>Something you use everywhere</li></ul><p>Use it when:</p><ul><li>You need to <strong>sync with the outside world</strong> (e.g., API calls, subscriptions)</li><li>You need to <strong>react to changes</strong> in data (e.g., logging, updating the document title)</li></ul><h3>Common Beginner Mistake #2: Infinite Loops</h3><pre>useEffect(() =&gt; {<br>  setCount(count + 1); // this will trigger a re-render and the effect will run again<br>}, [count]);</pre><h3>What Happens?</h3><p>This creates a loop:</p><ul><li>Effect runs</li><li>State updates</li><li>Component re-renders</li><li>Effect runs again</li><li>Repeat forever</li></ul><p>Always think: <strong>“What triggers this effect?”</strong></p><h3>Strict Mode Confusion</h3><p>You might notice:</p><p>“Why is my effect running twice?”</p><p>In development, React intentionally runs effects twice to detect bugs.</p><p>This <strong>does not happen in production</strong>.</p><h3>Thinking the React Way</h3><p>Don’t think:</p><p>“When this happens, do this, then this…”</p><p>Think:</p><p>“When this value changes, this effect should run.”</p><p>React is <strong>declarative</strong>, not procedural.</p><h3>Mini Exercises</h3><h4>Exercise 1: Log on Mount</h4><p>Use useEffect to log:</p><blockquote><em>“App loaded”</em></blockquote><p>Only once.</p><h4>Exercise 2: React to Input</h4><p>Create an input.<br> Log the value <strong>only when it changes</strong>.</p><h4>Exercise 3: Cleanup Practice</h4><p>Create a timer that logs every second.<br> Clean it up properly.</p><h3>What You Should Understand Now</h3><p>At this point, you should understand:</p><ul><li>What useEffect is</li><li>When it runs</li><li>How the dependency array works</li><li>What the React lifecycle really means</li><li>Why effects need cleanup</li></ul><p>This is one of the hardest React concepts, so if it mostly makes sense to you, you’re doing great!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c6e91596b6a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React, Explained From Zero — Part 10: useContext, useReducer & custom hooks]]></title>
            <link>https://medium.com/@saiamanaganti12/react-explained-from-zero-part-10-usecontext-usereducer-custom-hooks-df977fc15483?source=rss-d4a81cb46fd4------2</link>
            <guid isPermaLink="false">https://medium.com/p/df977fc15483</guid>
            <category><![CDATA[react-usecontext]]></category>
            <category><![CDATA[react-hook-usereducer]]></category>
            <category><![CDATA[custom-hooks-in-react]]></category>
            <dc:creator><![CDATA[Sai Amanaganti]]></dc:creator>
            <pubDate>Sat, 28 Mar 2026 04:30:40 GMT</pubDate>
            <atom:updated>2026-03-28T04:30:40.831Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dVyR6lvJjAre5-DtreU04g.png" /></figure><p>In Part 9, you learned <em>why hooks exist</em> — they give function components memory and timing.</p><p>Now we take the next step.</p><p>So far, your apps can:</p><ul><li>Store state (useState)</li><li>React to changes (useEffect, conceptually)</li><li>Handle user input</li></ul><p>But as your app grows, new problems appear:</p><ul><li>“How do I share data across many components?”</li><li>“Why is my state logic getting messy?”</li><li>“How do I reuse logic without copying code?”</li></ul><p>That’s exactly what this part solves.</p><h3>Goal of This Part</h3><p>By the end of this article, you will:</p><ul><li>Understand <strong>why useContext exists</strong></li><li>Understand <strong>when to use useReducer instead of useState</strong></li><li>Understand <strong>what custom hooks are</strong></li><li>See how React scales from small apps → real apps</li></ul><h3>The New Problems You’ll Face</h3><p>Let’s imagine your app grows.</p><p>You now have:</p><ul><li>A Navbar</li><li>A Sidebar</li><li>A Profile</li><li>A Dashboard</li></ul><p>And all of them need the same data:<br>user info (name, login status, theme, etc.)</p><h3>Problem 1: Prop Drilling</h3><p>You might do this:</p><pre>&lt;App&gt;<br>  &lt;Layout&gt;<br>    &lt;Navbar user={user} /&gt;<br>    &lt;Sidebar user={user} /&gt;<br>    &lt;Dashboard user={user} /&gt;<br>  &lt;/Layout&gt;<br>&lt;/App&gt;</pre><p>But wait… Layout doesn’t even need user.</p><p>You’re just passing it through.</p><p>This is called <strong>prop drilling</strong>.</p><p>It becomes:</p><ul><li>annoying</li><li>repetitive</li><li>hard to maintain</li></ul><h3>Solution 1: useContext</h3><h3>What useContext Does</h3><p>useContext lets you <strong>share data globally</strong> without passing props manually.</p><p>Think of it like:</p><blockquote><em>“Make this data available everywhere.”</em></blockquote><h3>Mental Model</h3><p>Instead of passing props:</p><pre>App → Layout → Navbar</pre><p>You create a <strong>shared data layer</strong>:</p><pre>        Context (global)<br>        /     |      \<br>   Navbar  Sidebar  Dashboard</pre><h3>When to Use useContext</h3><p>Use it when data is:</p><ul><li>Needed in many places</li><li>Not specific to one component</li><li>Painful to pass via props</li></ul><p>Examples:</p><ul><li>User authentication</li><li>Theme (dark/light)</li><li>Language settings</li></ul><h3>What Problem It Solves</h3><p>Without context:</p><ul><li>Too many props</li><li>Tight coupling between components</li></ul><p>With context:</p><ul><li>Clean structure</li><li>Direct access to shared data</li></ul><h3>Problem 2: State Logic Getting Messy</h3><p>Let’s say your state becomes complex:</p><pre>const [state, setState] = useState({<br>  count: 0,<br>  step: 1,<br>  isActive: true<br>});</pre><p>Now updates look like:</p><pre>setState(prev =&gt; ({<br>  ...prev,<br>  count: prev.count + prev.step<br>}));</pre><p>As logic grows:</p><ul><li>Multiple updates</li><li>Conditions everywhere</li><li>Hard to read</li></ul><h3>Solution 2: useReducer</h3><h3>What useReducer Does</h3><p>It lets you <strong>manage complex state using structured logic</strong>.</p><p>Instead of:</p><blockquote><em>“Update state directly”</em></blockquote><p>You say:</p><blockquote><em>“Dispatch an action → React decides how state changes”</em></blockquote><h3>Mental Model</h3><p>Think of it like a mini system:</p><pre>Action → Reducer → New State</pre><h3>Why It Exists</h3><p>Because useState becomes messy when:</p><ul><li>State has multiple related values</li><li>Updates depend on previous state</li><li>Logic becomes complicated</li></ul><h3>Example Thinking (Conceptual)</h3><p>Instead of this:</p><pre>setCount(count + 1);<br>setCount(count + 2);</pre><p>You do:</p><pre>dispatch({ type: &quot;increment&quot; });</pre><p>And define logic in one place.</p><h3>When to Use useReducer</h3><p>Use it when:</p><ul><li>State logic is complex</li><li>Multiple updates affect the same state</li><li>You want predictable behaviour</li></ul><h3>What Problem It Solves</h3><p>Without it:</p><ul><li>Scattered logic</li><li>Hard debugging</li></ul><p>With it:</p><ul><li>Centralised logic</li><li>Cleaner updates</li><li>Easier scaling</li></ul><h3>Problem 3: Repeating Logic Everywhere</h3><p>Imagine this:</p><p>You write the same logic in multiple components:</p><ul><li>Fetch data</li><li>Handle loading</li><li>Handle errors</li></ul><p>Copy-paste… again and again.</p><h3>Solution 3: Custom Hooks</h3><h3>What Custom Hooks Are</h3><p>Custom hooks are <strong>your own reusable hooks</strong>.</p><p>They let you extract logic into reusable functions.</p><h3>Mental Model</h3><p>Instead of repeating this:</p><pre>// in Component A<br>// fetch logic<br><br>// in Component B<br>// same fetch logic</pre><p>You do:</p><pre>useFetchData()</pre><h3>Why They Exist</h3><p>Because React needed a way to:</p><ul><li>Reuse logic (not UI)</li><li>Keep components clean</li><li>Avoid duplication</li></ul><h3>Important Idea</h3><p>Custom hooks are just:</p><blockquote><em>Functions that use other hooks</em></blockquote><p>That’s it.</p><h3>Example Thinking</h3><p>Instead of:</p><pre>useEffect(() =&gt; {<br>  // fetch data<br>}, []);</pre><p>You create:</p><pre>function useData() {<br>  // fetch logic<br>}</pre><p>And reuse it anywhere.</p><h3>When to Use Custom Hooks</h3><p>Use them when:</p><ul><li>Logic is repeated</li><li>Components are getting cluttered</li><li>You want clean separation</li></ul><h3>Big Picture: How These Three Fit Together</h3><p>Let’s connect everything.</p><h3>useContext</h3><p>Shares data across components</p><h3>useReducer</h3><p>Manages complex state logic</p><h3>Custom Hooks</h3><p>Reuse logic cleanly</p><h3>Real App Example</h3><p>In a real app:</p><ul><li>useContext → provides user data globally</li><li>useReducer → manages user state changes</li><li>Custom hooks → handle API calls, validation, etc.</li></ul><p>Together, they make React scalable.</p><h3>A New Mental Shift</h3><p>Before:</p><ul><li>Components = UI + logic mixed together</li></ul><p>Now:</p><ul><li>Components → UI</li><li>Hooks → logic</li><li>Context → shared data</li></ul><p>This separation is what makes React powerful.</p><h3>Common Beginner Misconception</h3><blockquote><em>“These hooks are advanced.”</em></blockquote><p>They’re not.</p><p>They solve <strong>natural problems</strong> that appear as your app grows.</p><p>You don’t need them on day one.</p><p>But you <em>will</em> need them.</p><h3>What You Should Understand Now</h3><p>At this point, you should understand:</p><ul><li>Why prop drilling is a problem</li><li>Why useContext exists</li><li>Why useReducer exists</li><li>Why custom hooks exist</li><li>How React scales beyond useState</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df977fc15483" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React, Explained From Zero — Part 9: React Hooks (Why They Exist)]]></title>
            <link>https://medium.com/@saiamanaganti12/react-explained-from-zero-part-9-react-hooks-why-they-exist-c5497c203811?source=rss-d4a81cb46fd4------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5497c203811</guid>
            <category><![CDATA[useref]]></category>
            <category><![CDATA[useeffect]]></category>
            <category><![CDATA[hooks-in-react]]></category>
            <category><![CDATA[react-hook]]></category>
            <dc:creator><![CDATA[Sai Amanaganti]]></dc:creator>
            <pubDate>Wed, 11 Mar 2026 11:16:00 GMT</pubDate>
            <atom:updated>2026-03-11T11:16:00.505Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zaXOoFMSvZNRNt05EHMMqw.png" /></figure><p>In Part 8, you learned how React handles <strong>inputs and forms</strong>.</p><p>At this point, your apps can:</p><ul><li>Render components</li><li>Pass data with props</li><li>Store data in state</li><li>Respond to user events</li><li>Handle user input</li></ul><p>You can already build real things.</p><p>But sooner or later, every React beginner asks questions like:</p><ul><li>“How do I run code when the component loads?”</li><li>“How do I react when state changes?”</li><li>“How do I clean something up?”</li><li>“Why does this code keep running again?”</li></ul><p>Those questions lead us to <strong>hooks</strong>.</p><h3>Goal of This Part</h3><p>By the end of this article, you will:</p><ul><li>Understand what hooks are</li><li>Know why hooks exist</li><li>Understand what problems hooks solve</li><li>Stop thinking of hooks as “magic”</li><li>Be mentally ready for useEffect</li></ul><h3>Why React Introduced Hooks</h3><p>Earlier in the series, you learned that React components are just functions.</p><p>But functions have a limitation:</p><blockquote><strong><em>They don’t remember anything between calls.</em></strong></blockquote><p>If React re-renders a component, the function runs again from scratch.</p><p>So React needed a way for function components to:</p><ul><li>remember values</li><li>react to changes</li><li>run code at the right time</li></ul><p>That’s why hooks exist.</p><p><strong>Hooks give function components memory and behavior.</strong></p><h3>The Problem Hooks Solve</h3><p>So far, your components look like this:</p><pre>function App() {<br>  return &lt;h1&gt;Hello&lt;/h1&gt;;<br>}</pre><p>Or maybe this:</p><pre>function App() {<br>  const [text, setText] = useState(&quot;&quot;);<br>  <br>  return &lt;input value={text} onChange={e =&gt; setText(e.target.value)} /&gt;;<br>}</pre><p>These components run <strong>top to bottom</strong>.</p><p>But now imagine you want to:</p><ul><li>Fetch data when the component appears</li><li>Save something when state changes</li><li>Set up a timer</li><li>Clean up when the component disappears</li></ul><p>Where does that code go?</p><h3>The Big Question</h3><p>React components are just functions.</p><p>Functions:</p><ul><li>Run</li><li>Finish</li><li>Return JSX</li></ul><p>But real apps need code that runs:</p><ul><li><strong>At specific times</strong></li><li><strong>Because of changes</strong></li><li><strong>Outside rendering</strong></li></ul><p>That’s the problem hooks solve.</p><h3>What Hooks Actually Are</h3><p>In simple terms:</p><blockquote><strong><em>Hooks let you “hook into” React’s </em></strong><em>behaviour</em><strong><em> at specific moments.</em></strong></blockquote><p>They let you say things like:</p><ul><li>“Run this when state changes”</li><li>“Run this once when the component loads”</li><li>“Remember this value between renders”</li></ul><p>Hooks are <strong>React’s API for timing and memory</strong>.</p><h3>Why Hooks Exist (Historical Context, Light)</h3><h3>Before Hooks:</h3><ul><li>React used class components.</li><li>Lifecycle methods were split across files.</li><li>Logic was hard to reuse.</li><li>Code was harder to reason about.</li></ul><p><strong>Hooks were introduced to:</strong></p><ul><li>Keep components as functions</li><li>Make behavior reusable</li><li>Make lifecycle logic clearer</li></ul><h3>Class Components vs. Function Components</h3><p>Class components were once the norm in React, but they had a few downsides:</p><ul><li><strong>Verbose syntax</strong>: More code meant more potential for bugs.</li><li><strong>Lifecycle methods scattered across files</strong>: It became difficult to understand the flow of data and side effects across the entire component lifecycle.</li><li><strong>Reusability issues</strong>: Logic for common functionality could be duplicated across multiple components.</li></ul><p>Hooks revolutionized React by providing a much cleaner and more maintainable solution.</p><h3>You Do Not Need to Learn Class Components</h3><p>React has shifted away from class components. <strong>Hooks</strong> are the modern way. They offer more flexible and reusable patterns than class components, and they enable you to do everything you could do with class components, but in a simpler, more declarative manner.</p><h3>Hooks Only Work in Components (Important Rule)</h3><p>Hooks follow a few strict rules:</p><ul><li>Hooks can only be used inside React components</li><li>Hooks must be called <strong>in the same order every time the component runs</strong></li><li>Hooks must be called at the <strong>top level</strong> of the component</li><li>Hooks cannot be called conditionally</li></ul><p>Why?</p><p>React needs to track them consistently. If you call hooks conditionally or out of order, React won’t be able to track the component’s state or effects properly, leading to bugs that are difficult to debug. You’ll understand this better as you dive into more hooks, but for now, just remember these rules.</p><h3>Hooks Are About “When”, Not “What”</h3><p>This is the key mental shift.</p><ul><li>JSX answers: <strong>what the UI looks like</strong></li><li>State answers: <strong>what data exists</strong></li><li>Events answer: <strong>when users act</strong></li><li>Hooks answer: <strong>when React should run code</strong></li></ul><h3>Timing in React</h3><p>Hooks control <strong>timing</strong>. They allow you to manage side effects (e.g., fetching data, subscribing to an external event) and component lifecycle behaviours (e.g., componentDidMount, componentWillUnmount) in a functional component.</p><h3>The Most Important Hooks (Preview Only)</h3><p>You’ve already met one hook:</p><ul><li>useState → stores data</li></ul><p>Others you’ll learn soon:</p><ul><li>useEffect → runs code at specific times</li><li>useRef → remembers values without re-rendering</li></ul><p>You don’t need to know how they work yet.</p><p>Just know <strong>why they exist</strong>.</p><h3>A Mental Timeline of a Component</h3><p>Think of a component’s life like this:</p><pre>Component appears<br>Component renders<br>State changes<br>Component re-renders<br>Component disappears</pre><p>Hooks let you attach logic to those moments. Without hooks, React would be incomplete.</p><h3>Common Beginner Misconception</h3><blockquote><em>“Hooks are advanced.”</em></blockquote><p>They’re not.</p><p>Hooks are just:</p><ul><li>Structured timing</li><li>Predictable behavior</li><li>Explicit logic</li></ul><p>They <em>replace</em> complexity — they don’t add it.</p><h3>What You Should Understand Now</h3><p>At this point, you should understand:</p><ul><li>Why hooks exist</li><li>What problem they solve</li><li>Why useState is a hook</li><li>Why lifecycle matters</li></ul><p>You don’t need to write new code yet.</p><p>Understanding the <em>why</em> comes first.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5497c203811" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React, Explained From Zero — Part 8: Handling Input and Forms]]></title>
            <link>https://medium.com/@saiamanaganti12/react-explained-from-zero-part-8-handling-input-and-forms-987c5454392e?source=rss-d4a81cb46fd4------2</link>
            <guid isPermaLink="false">https://medium.com/p/987c5454392e</guid>
            <category><![CDATA[input-handling]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[putin]]></category>
            <category><![CDATA[user-interaction]]></category>
            <category><![CDATA[forms]]></category>
            <dc:creator><![CDATA[Sai Amanaganti]]></dc:creator>
            <pubDate>Wed, 11 Mar 2026 06:39:55 GMT</pubDate>
            <atom:updated>2026-03-11T06:39:55.281Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7enTLIIayaeJD0HRg-Rg7Q.png" /></figure><p>In Part 7, you learned how <strong>events</strong> let users interact with your app.</p><p>Users can click buttons and trigger logic.<br>That’s a big step forward.</p><p>But real applications don’t just respond to clicks.</p><p>They accept <strong>input</strong>.</p><p>Users type names, search terms, passwords, messages, and numbers.<br>Forms are where React apps start to feel <em>real</em>.</p><p>In this part, we’ll learn how React handles inputs — <strong>without fear or shortcuts</strong>.</p><h3>Goal of This Part</h3><p>By the end of this article, you will:</p><ul><li>Understand how input elements work in React</li><li>Learn what a <em>controlled component</em> is</li><li>Connect inputs to state</li><li>Handle form submission</li><li>Avoid common beginner mistakes</li></ul><h3>Why Inputs Are Different</h3><p>Let’s start with a basic input:</p><pre>&lt;input /&gt;</pre><p>You can type into it.<br>The browser handles everything automatically.</p><p>But React has a question:</p><blockquote><em>“If the user types something… should I know about it?”</em></blockquote><p>In React, the answer is usually <strong>yes</strong>.</p><p>Why?</p><p>Because:</p><ul><li>The UI depends on data</li><li>Inputs are data</li><li>Data should live in state</li></ul><h3>The Core Idea (Very Important)</h3><p>In React:</p><blockquote><strong><em>The value of an input usually comes from state.</em></strong></blockquote><p>This is called a <strong>controlled component</strong>.</p><p>It sounds scary — but it isn’t.</p><h3>Your First Controlled Input</h3><p>Let’s build the smallest useful example.</p><pre>import { useState } from &quot;react&quot;;<br><br>function App() {<br>  const [text, setText] = useState(&quot;&quot;);<br>  function handleChange(event) {<br>    setText(event.target.value);<br>  }<br>  return (<br>    &lt;div&gt;<br>      &lt;input value={text} onChange={handleChange} /&gt;<br>      &lt;p&gt;You typed: {text}&lt;/p&gt;<br>    &lt;/div&gt;<br>  );<br>}<br>export default App;</pre><p>Now type into the input.</p><p>The text appears below it.</p><p>That’s React working as designed.</p><h3>What Just Happened?</h3><p>Let’s slow it down.</p><pre>const [text, setText] = useState(&quot;&quot;);</pre><ul><li>text is the current value</li><li>setText updates it</li></ul><pre>&lt;input value={text} onChange={handleChange} /&gt;</pre><ul><li>The input <strong>gets its value from state</strong></li><li>When the user types, onChange fires</li></ul><pre>setText(event.target.value);</pre><ul><li>We update state with what the user typed</li><li>React re-renders</li><li>The input updates</li></ul><h3>The Mental Model That Matters</h3><pre>User types<br>   ↓<br>onChange event<br>   ↓<br>State updates<br>   ↓<br>UI re-renders</pre><p>The input does <strong>not</strong> control itself.</p><p><strong>State does.</strong></p><h3>Why This Feels Weird at First</h3><p>Beginners often think:</p><blockquote><em>“Why do I need state?<br>The browser already handles inputs.”</em></blockquote><p>That’s true — but React needs <strong>one source of truth</strong>.</p><p>If React doesn’t control the value:</p><ul><li>The UI can get out of sync</li><li>Bugs become harder to track</li><li>Logic becomes scattered</li></ul><p>Controlled inputs keep everything predictable.</p><h3>Common Beginner Mistake #1: Forgetting onChange</h3><p>This looks harmless:</p><pre>&lt;input value={text} /&gt;</pre><p>But now:</p><ul><li>The input becomes <strong>read-only</strong></li><li>Typing won’t work</li></ul><p>Why?</p><p>Because React controls the value — but you never update it.</p><p><strong>Rule:</strong></p><blockquote><em>If you set </em><em>value, you must handle </em><em>onChange.</em></blockquote><h3>Handling Form Submission</h3><p>Now let’s wrap this in a form.</p><pre>function App() {<br>  const [name, setName] = useState(&quot;&quot;);<br><br>  function handleSubmit(event) {<br>    event.preventDefault();<br>    alert(`Hello, ${name}`);<br>  }<br><br>  return (<br>    &lt;form onSubmit={handleSubmit}&gt;<br>      &lt;input<br>        value={name}<br>        onChange={(e) =&gt; setName(e.target.value)}<br>      /&gt;<br>      &lt;button type=&quot;submit&quot;&gt;Submit&lt;/button&gt;<br>    &lt;/form&gt;<br>  );<br>}</pre><h3>Why event.preventDefault()?</h3><p>By default, forms:</p><ul><li>Refresh the page</li><li>Lose all state</li></ul><p>React apps <strong>do not want page reloads</strong>.</p><p>So we stop the default behavior.</p><h3>Inputs Are Just Events + State</h3><p>There’s nothing magical here.</p><p>Inputs combine:</p><ul><li>onChange (event)</li><li>useState (state)</li><li>JSX (rendering)</li></ul><p>That’s it.</p><p>Once you see that, inputs stop feeling special.</p><h3>Handling Multiple Inputs (Simple Pattern)</h3><pre>function App() {<br>  const [email, setEmail] = useState(&quot;&quot;);<br>  const [password, setPassword] = useState(&quot;&quot;);<br><br>  return (<br>    &lt;form&gt;<br>      &lt;input<br>        placeholder=&quot;Email&quot;<br>        value={email}<br>        onChange={(e) =&gt; setEmail(e.target.value)}<br>      /&gt;<br><br>      &lt;input<br>        placeholder=&quot;Password&quot;<br>        value={password}<br>        onChange={(e) =&gt; setPassword(e.target.value)}<br>      /&gt;<br><br>      &lt;p&gt;{email}&lt;/p&gt;<br>      &lt;p&gt;{password}&lt;/p&gt;<br>    &lt;/form&gt;<br>  );<br>}</pre><p>Each input:</p><ul><li>Has its own state</li><li>Updates independently</li><li>Re-renders predictably</li></ul><h3>Common Beginner Mistake #2: Reading the DOM</h3><p>Don’t do this:</p><pre>document.querySelector(&quot;input&quot;).value</pre><p>In React:</p><ul><li>You don’t read the DOM</li><li>You read <strong>state</strong></li></ul><p>State already knows everything.</p><h3>Thinking the React Way</h3><p>React developers don’t think:</p><p>❌ “How do I get the value from the input?”<br>❌ “How do I read the DOM?”</p><p>They think:</p><p>✅ “What is the current state?”<br>✅ “How should the UI reflect it?”</p><h3>Mini Exercises (Try These)</h3><h3>Exercise 1: Live Preview</h3><p>Create an input where:</p><ul><li>The user types</li><li>The text updates live below it</li></ul><h3>Exercise 2: Simple Login Form</h3><p>Create a form with:</p><ul><li>Username input</li><li>Password input</li><li>Submit button</li></ul><p>On submit, log both values.</p><h3>Exercise 3: Break It on Purpose</h3><p>Remove onChange.</p><p>What happens?</p><p>Understanding <em>why</em> it breaks is how React clicks.</p><h3>What You Should Understand Now</h3><p>At this point, you should understand:</p><ul><li>How React handles inputs</li><li>What controlled components are</li><li>Why inputs use state</li><li>How forms work in React</li><li>Why React avoids DOM manipulation</li></ul><p>You’re now ready for the next big question:</p><blockquote><strong><em>“What if I want to run code when state changes?”</em></strong></blockquote><p>That question leads directly to <strong>effects</strong>.</p><h3>Next Up</h3><p><strong>React, Explained From Zero — Part 9: React Hooks (Why They Exist)</strong></p><p>This is where everything you’ve learned starts connecting.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=987c5454392e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React, Explained From Zero — Part 7: Events (How Users Talk to Your App)]]></title>
            <link>https://medium.com/@saiamanaganti12/react-explained-from-zero-part-7-events-how-users-talk-to-your-app-021b01368250?source=rss-d4a81cb46fd4------2</link>
            <guid isPermaLink="false">https://medium.com/p/021b01368250</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-events]]></category>
            <category><![CDATA[events]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Sai Amanaganti]]></dc:creator>
            <pubDate>Thu, 19 Feb 2026 09:40:07 GMT</pubDate>
            <atom:updated>2026-02-19T09:40:07.285Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GAVmYUu4B9DieUoqHfjjQQ.png" /></figure><p>In Part 6, you learned what <strong>state</strong> is and why it controls what appears on the screen.</p><p>Now we answer a different question:</p><blockquote><strong><em>How does the user tell React </em>when<em> something should change?</em></strong></blockquote><p>The answer is <strong>events</strong>.</p><p>Events are how your app listens to user actions and responds to them.</p><h3>Goal of This Part</h3><p>By the end of this article, you will:</p><ul><li>Understand what events are in React</li><li>Handle common user actions</li><li>See events without state</li><li>See events with state</li><li>Avoid common beginner mistakes</li><li>Think in <strong>user intent</strong>, not DOM manipulation</li></ul><h3>What Are Events?</h3><p>An <strong>event</strong> is something the user does.</p><p>Examples:</p><ul><li>Clicking a button</li><li>Typing into an input</li><li>Hovering over an element</li><li>Submitting a form</li></ul><p>React lets you listen to these actions and run code when they happen.</p><h3>Events Are Just Functions</h3><p>Let’s start with an example <strong>without state</strong>.</p><pre>function App() {<br>  function sayHello() {<br>    alert(&quot;Hello!&quot;);<br>  }<br>  return &lt;button onClick={sayHello}&gt;Say Hello&lt;/button&gt;;<br>}</pre><p>What’s important here:</p><ul><li>onClick listens for a click</li><li>sayHello is just a normal function</li><li>React calls it when the click happens</li></ul><p>No state involved.</p><p>This proves something important:</p><blockquote><strong><em>Events do not require state.<br>State responds to events.</em></strong></blockquote><h3>Event Naming in React</h3><p>React event names:</p><ul><li>Use <strong>camelCase</strong></li><li>Start with on</li></ul><p>Examples:</p><ul><li>onClick</li><li>onChange</li><li>onSubmit</li><li>onMouseEnter</li></ul><p>This is different from plain HTML.</p><h3>Passing Data into Event Handlers</h3><p>Event handlers can receive data.</p><pre>function App() {<br>  function greet(name) {<br>    alert(`Hello ${name}`);<br>  }<br><br>  return (<br>    &lt;div&gt;<br>      &lt;button onClick={() =&gt; greet(&quot;Alice&quot;)}&gt;Greet Alice&lt;/button&gt;<br>      &lt;button onClick={() =&gt; greet(&quot;Bob&quot;)}&gt;Greet Bob&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>Here:</p><ul><li>The event triggers the function</li><li>The function receives custom data</li></ul><p>This is very common in real apps.</p><h3>Common Beginner Mistake: Calling the Function</h3><p>Wrong:</p><pre>&lt;button onClick={greet(&quot;Alice&quot;)}&gt;Click&lt;/button&gt;</pre><p>This runs immediately — not on click.</p><p>Correct:</p><pre>&lt;button onClick={() =&gt; greet(&quot;Alice&quot;)}&gt;Click&lt;/button&gt;</pre><h3>Rule to remember:</h3><blockquote><strong><em>Events need a function reference, not a function call.</em></strong></blockquote><h3>Events + State (New Example: Mood Switch)</h3><p>Now let’s connect events to state — with a <strong>different example</strong>.</p><pre>import { useState } from &quot;react&quot;;<br><br>function App() {<br>  const [mood, setMood] = useState(&quot;🙂&quot;);<br>  function changeMood(newMood) {<br>    setMood(newMood);<br>  }<br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Current mood: {mood}&lt;/p&gt;<br>      &lt;button onClick={() =&gt; changeMood(&quot;😊&quot;)}&gt;Happy&lt;/button&gt;<br>      &lt;button onClick={() =&gt; changeMood(&quot;😐&quot;)}&gt;Neutral&lt;/button&gt;<br>      &lt;button onClick={() =&gt; changeMood(&quot;😢&quot;)}&gt;Sad&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}<br>export default App;</pre><p>What’s happening:</p><pre>User clicks button<br>     ↓<br>Event fires<br>     ↓<br>State updates<br>     ↓<br>UI reflects new mood</pre><p>Same state.<br>Different events.</p><h3>One Event, Multiple Outcomes</h3><p>An event handler can decide what to do.</p><pre>function App() {<br>  const [status, setStatus] = useState(&quot;offline&quot;);<br><br>  function toggleStatus() {<br>    if (status === &quot;offline&quot;) {<br>      setStatus(&quot;online&quot;);<br>    } else {<br>      setStatus(&quot;offline&quot;);<br>    }<br>  }<br>  <br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Status: {status}&lt;/p&gt;<br>      &lt;button onClick={toggleStatus}&gt;Toggle Status&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>Here:</p><ul><li>One event</li><li>One handler</li><li>State decides the UI</li></ul><h3>Events Do Not Touch the DOM</h3><p>This is a key React idea.</p><p>In React:</p><ul><li>You don’t hide elements manually</li><li>You don’t change text manually</li><li>You don’t query the DOM</li></ul><p>Instead:</p><blockquote><strong><em>You update state, and React updates the UI.</em></strong></blockquote><h3>Events Don’t Have to Change State</h3><p>This is important.</p><p>Sometimes events:</p><ul><li>Log data</li><li>Validate input</li><li>Show alerts</li><li>Trigger navigation</li></ul><p>Not every event needs state.</p><h3>Thinking in User Intent</h3><p>React developers don’t think:</p><p>❌ “When clicked, change text color”<br>❌ “Hide this div”</p><p>They think:</p><p>✅ “What does the user want to do?”<br>✅ “What should the UI look like after?”</p><p>Events capture <strong>intent</strong>.<br>State describes <strong>result</strong>.</p><h3>Mini Exercises</h3><h4>Exercise 1: Message Button</h4><p>Create a button that shows an alert when clicked.</p><p>No state needed.</p><h4>Exercise 2: Theme Selector</h4><p>Create buttons:</p><ul><li>Light</li><li>Dark</li></ul><p>Clicking a button updates a piece of state called theme and displays it.</p><h4>Exercise 3: Trace the Flow</h4><p>Answer this:</p><blockquote><em>Does the event change the UI directly — or does state do that?</em></blockquote><p>(Answer: state.)</p><h3>What You Should Understand Now</h3><p>You should now understand:</p><ul><li>What events are</li><li>That event handlers are normal functions</li><li>How to pass data into handlers</li><li>When events need state — and when they don’t</li><li>How users control your app</li></ul><p>You now have the <strong>full interaction loop</strong>:</p><pre>User → Event → State → UI</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=021b01368250" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React, Explained From Zero — Part 6: Understanding State Without Fear]]></title>
            <link>https://medium.com/@saiamanaganti12/react-explained-from-zero-part-6-understanding-state-without-fear-2e87d4914344?source=rss-d4a81cb46fd4------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e87d4914344</guid>
            <category><![CDATA[usestate-hook]]></category>
            <category><![CDATA[react-components]]></category>
            <category><![CDATA[react-hook-usestate]]></category>
            <dc:creator><![CDATA[Sai Amanaganti]]></dc:creator>
            <pubDate>Mon, 16 Feb 2026 11:25:22 GMT</pubDate>
            <atom:updated>2026-02-16T11:25:22.723Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PnacniHmon-pjjNN" /></figure><p>In Part 5 of this series, you learned how components receive data using props.</p><p>At that point, everything still feels very static.</p><p>The UI shows data, but it doesn’t <em>change</em> on its own.</p><p>Sooner or later, every beginner asks the same question:</p><blockquote><strong><em>“How does React know when to update the screen?”</em></strong></blockquote><p>The answer is <strong>state</strong>.</p><p>State is one of the most important ideas in React — and also one of the most misunderstood.<br>In this article, I’ll explain state slowly and clearly, without magic, shortcuts, or fear.</p><h3>Goal of This Part</h3><p>By the end of this article, you will:</p><ul><li>Understand what <strong>state</strong> really means</li><li>Know why normal variables don’t update the UI</li><li>Use useState for the first time</li><li>Understand how updating state re-renders the UI</li><li>Avoid common beginner misunderstandings</li><li>Think in <strong>UI changes</strong>, not variables</li></ul><h3>What “State” Really Means</h3><p>In React, <strong>state</strong> represents data that can change over time <strong>and affects what the user sees</strong>.</p><p>A simple way to think about it:</p><blockquote><strong><em>State is the current condition of the UI.</em></strong></blockquote><p>Examples of state:</p><ul><li>A counter value</li><li>Whether something is visible or hidden</li><li>Text entered in an input</li><li>Whether a button has been clicked</li></ul><h4>Rule of thumb:</h4><p>If changing a value should update the screen, that value belongs in <strong>state</strong>.</p><h3>State vs Static UI</h3><pre>State = 0        →  UI shows: Count: 0<br>State = 1        →  UI shows: Count: 1<br>State = 2        →  UI shows: Count: 2</pre><p>The UI is just a reflection of the current state.</p><h3>Why Normal Variables Don’t Update the UI</h3><p>Let’s start with something that <em>doesn’t</em> work.</p><pre>function App() {<br>  let count = 0;<br>  <br>  function increase() {<br>    count = count + 1;<br>    console.log(count);<br>  }<br>  <br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Count: {count}&lt;/p&gt;<br>      &lt;button onClick={increase}&gt;Increase&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>Click the button.</p><p>You’ll see the number increasing in the console — but <strong>not on the screen</strong>.</p><p>Why?</p><p>Because <strong>React does not watch normal variables.</strong></p><p>Changing a variable does <strong>not</strong> tell React that the UI needs to update.</p><h3>Enter State</h3><p>React needs a way to know:</p><blockquote>“Something changed — re-render the UI.”</blockquote><p>That’s exactly what <strong>state</strong> does.</p><p>React provides a built-in tool for this called useState.</p><h3>Introducing useState</h3><p>Here’s the same example, rewritten using state.</p><pre>import { useState } from &quot;react&quot;;<br><br>function App() {<br>  const [count, setCount] = useState(0);<br>  <br>  function increase() {<br>    setCount(count + 1);<br>  }<br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;Count: {count}&lt;/p&gt;<br>      &lt;button onClick={increase}&gt;Increase&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><p>Now the UI updates correctly.</p><p>Let’s break this down slowly.</p><h3>Understanding useState</h3><pre>const [count, setCount] = useState(0);</pre><p>This line means:</p><ul><li>count → the current state value</li><li>setCount → a function to update it</li><li>0 → the initial value</li></ul><p>Important rule:</p><blockquote><strong><em>Never change state directly. Always use the setter function.</em></strong></blockquote><h3>What Happens When State Changes</h3><pre>Button Click<br>     │<br>     ▼<br>setCount(count + 1)<br>     │<br>     ▼<br>State updates<br>     │<br>     ▼<br>Component re-runs<br>     │<br>     ▼<br>UI updates</pre><p>This is the core React cycle.</p><h3>Updating State Re-Renders the UI</h3><p>When you call:</p><pre>setCount(count + 1);</pre><p>React does two things:</p><ol><li>Updates the state value</li><li>Re-runs the component function</li></ol><p>When the component re-runs, React updates the UI automatically.</p><p>That’s why the number changes on the screen.</p><h3>State Drives the UI</h3><p>This is a crucial mental shift.</p><p>In React:</p><ul><li>You don’t manually update the DOM</li><li>You don’t tell React <em>how</em> to change the screen</li></ul><p>Instead:</p><blockquote><strong><em>You update the state → React updates the UI</em></strong></blockquote><p>The UI is always a reflection of the current state.</p><h3>Common Beginner Misunderstandings</h3><p>Let’s clear these up early.</p><h4>“Why can’t I just use variables?”</h4><p>Because React does not track them.<br>State exists so React knows when to re-render.</p><h4>“Why doesn’t state update immediately?”</h4><p>State updates are <strong>scheduled</strong>, not instant.<br>React may batch updates for performance.</p><p>For now, remember this:</p><blockquote>After React re-renders, the UI will always show the latest state.</blockquote><h4>“Can I change state directly?”</h4><p>No.</p><p>This is wrong:</p><pre>count = count + 1;</pre><p>Always use:</p><pre>setCount(count + 1);</pre><h3>Thinking in UI Changes, Not Variables</h3><p>This is how experienced React developers think:</p><p>❌ “I need to change a number”<br> ✅ “The UI needs to update when something happens”</p><p>When the UI needs to change → <strong>use state</strong>.</p><h3>Try These</h3><h4>Exercise 1: Change the Initial State</h4><p>Change this:</p><pre>useState(0);</pre><p>To start the counter at:</p><ul><li>5</li><li>10</li><li>100</li></ul><p>What happens to the UI?</p><h4>Exercise 2: Add a Decrease Button</h4><p>Add a second button that decreases the count.</p><p>Hint:</p><ul><li>Create a new function</li><li>Call setCount(count - 1)</li></ul><h3>What You Should Understand Now</h3><p>At this point, you should be comfortable with:</p><ul><li>What state represents</li><li>Why state exists</li><li>How useState works</li><li>Why updating state updates the UI</li><li>The difference between state and variables</li></ul><p>This understanding will carry you through <strong>all React development</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e87d4914344" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React, Explained From Zero — Part 5: Passing Data with Props]]></title>
            <link>https://medium.com/@saiamanaganti12/react-explained-from-zero-part-5-passing-data-with-props-2d6e9e495f47?source=rss-d4a81cb46fd4------2</link>
            <guid isPermaLink="false">https://medium.com/p/2d6e9e495f47</guid>
            <category><![CDATA[react-components]]></category>
            <category><![CDATA[react-props]]></category>
            <dc:creator><![CDATA[Sai Amanaganti]]></dc:creator>
            <pubDate>Fri, 13 Feb 2026 07:38:59 GMT</pubDate>
            <atom:updated>2026-02-13T07:38:59.995Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9PJc6NYD4vWstHAvXZ4-8w.png" /></figure><p>In Part 4 of this series, you learned how to break your UI into small, reusable components.</p><p>At this point, you might notice something important:</p><blockquote><em>Your components work…<br>but they all show </em><strong><em>fixed content</em></strong><em>.</em></blockquote><p>That’s where the next core concept of React comes in.</p><p>To build real applications, components need <strong>data</strong>.<br>And in React, data is passed into components using something called <strong>props</strong>.</p><h3>Goal of This Part</h3><p>By the end of this article, you will:</p><ul><li>Understand <strong>why</strong> components need data</li><li>Know what <strong>props</strong> are (in simple terms)</li><li>Pass data from one component to another</li><li>Use props inside JSX</li><li>Avoid common beginner mistakes</li><li>Understand why props are <strong>read-only</strong></li></ul><h3>Why Components Need Data</h3><p>So far, your components probably look like this:</p><pre>function Header() {<br>  return &lt;h1&gt;Welcome&lt;/h1&gt;;<br>}</pre><p>This works — but it’s limited.</p><p>What if you want:</p><ul><li>Different titles in different places?</li><li>The same component reused with different text?</li></ul><p>Hardcoding values doesn’t scale.</p><p>What we really want is this idea:</p><blockquote><strong><em>“Same component, different data.”</em></strong></blockquote><p>That’s exactly what props allow.</p><h3>What Are Props?</h3><p><strong>Props</strong> (short for <em>properties</em>) are how you pass data <strong>into</strong> a component.</p><p>A simple mental model:</p><blockquote><strong><em>Props are inputs to a React component.</em></strong></blockquote><p>Just like a function can receive arguments, a React component can receive props.</p><h3>Passing Props to a Component</h3><p>Let’s walk through this step by step.</p><h3>Step 1: Create a Component That Accepts Props</h3><pre>function Greeting(props) {<br>  return &lt;h2&gt;Hello!&lt;/h2&gt;;<br>}<br><br>export default Greeting;</pre><p>Right now, this component <strong>receives</strong> props — but it doesn’t use them yet.<br>Let’s fix that.</p><h3>Step 2: Pass Data from the Parent Component</h3><p>In App.jsx:</p><pre>import Greeting from &quot;./Greeting&quot;;<br><br>function App() {<br>  return (<br>    &lt;div&gt;<br>      &lt;Greeting name=&quot;React&quot; /&gt;<br>      &lt;Greeting name=&quot;World&quot; /&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><p>Here, we are passing a prop called name.</p><h3>Using Props Inside JSX</h3><p>Now update Greeting.jsx:</p><pre>function Greeting(props) {<br>  return &lt;h2&gt;Hello {props.name}&lt;/h2&gt;;<br>}<br><br>export default Greeting;</pre><p>Save the file.</p><p>You’ll now see:</p><pre>Hello React<br>Hello World</pre><p>Same component.</p><p>Different data.</p><p>That’s props in action.</p><h3>How props flow</h3><pre>App<br>│<br>├── &lt;Greeting name=&quot;React&quot; /&gt;<br>│          │<br>│          ▼<br>│     props.name = &quot;React&quot;<br>│<br>└── &lt;Greeting name=&quot;World&quot; /&gt;<br>           │<br>           ▼<br>      props.name = &quot;World&quot;</pre><blockquote><em>Each component receives its own props from the parent.</em></blockquote><h3>A Cleaner Way to Use Props (Very Common)</h3><p>Instead of writing props.name, most developers use <strong>destructuring</strong>.</p><pre>function Greeting({ name }) {<br>  return &lt;h2&gt;Hello {name}&lt;/h2&gt;;<br>}</pre><p>This does the same thing — just cleaner and easier to read.</p><p>As a beginner, you can use <strong>either approach</strong>.</p><h3>Props Flow in One Direction (Very Important)</h3><p>Props always flow:</p><blockquote><strong><em>From parent → to child</em></strong></blockquote><ul><li>App passes data</li><li>Greeting receives data</li></ul><p>The child component <strong>does not control</strong> the props it receives.</p><p>This one-way flow keeps React predictable and easy to debug.</p><h3>Common Beginner Mistakes with Props</h3><p>Everyone makes these at first — totally normal.</p><h3>Forgetting to Pass the Prop</h3><pre>&lt;Greeting /&gt;</pre><p>But using it like this:</p><pre>&lt;h2&gt;Hello {props.name}&lt;/h2&gt;</pre><p>Result: undefined</p><p>This is normal. It just means no value was passed.</p><h3>Misspelling Prop Names</h3><pre>&lt;Greeting name=&quot;React&quot; /&gt;</pre><p>But using:</p><pre>props.nmae</pre><p>JavaScript won’t warn you — you’ll just get undefined.</p><p>Careful naming matters.</p><h3>Expecting Props to Change by Themselves</h3><p>Props don’t change unless the <strong>parent changes them</strong>.</p><p>If you need something to change over time, that’s <strong>state</strong> — which we’ll cover next.</p><h3>Props Are Read-Only (Critical Rule)</h3><p>This is one of the most important rules in React:</p><blockquote><strong><em>Props should never be modified inside a component.</em></strong></blockquote><p>Don’t do this:</p><pre>props.name = &quot;New Name&quot;;</pre><p>React will not allow it.</p><p>Why?</p><p>Because props represent <strong>data owned by the parent</strong>, not the child.</p><p>If a component needs to change data, that data should live <strong>higher up</strong>.</p><p>This rule keeps your UI predictable.</p><h3>A Simple Real-World Example</h3><pre>function UserCard({ username }) {<br>  return &lt;p&gt;User: {username}&lt;/p&gt;;<br>}</pre><p>Used like this:</p><pre>&lt;UserCard username=&quot;alice&quot; /&gt;<br>&lt;UserCard username=&quot;bob&quot; /&gt;</pre><p>Same component.</p><p>Different users.</p><p>That’s exactly how real React apps work.</p><h3>What You Should Understand Now</h3><p>At this point, you should clearly understand:</p><ul><li>Why components need data</li><li>What props are</li><li>How to pass props</li><li>How to use props in JSX</li><li>Why props are read-only</li></ul><p>If this feels clear, you’ve crossed a <strong>major React milestone</strong>.</p><h3>Try these yourself</h3><h4>Exercise 1: Create a Reusable Title Component</h4><p><strong>Goal:</strong> Practice creating a component that accepts props.</p><ol><li>Create a new file called Title.jsx</li><li>Create a component that:</li></ol><ul><li>Accepts a text prop</li><li>Displays it inside an &lt;h1&gt;</li></ul><p>Example usage:</p><pre>&lt;Title text=&quot;Home Page&quot; /&gt;<br>&lt;Title text=&quot;Profile&quot; /&gt;<br>&lt;Title text=&quot;Settings&quot; /&gt;</pre><p>All three should reuse the <strong>same component</strong>.</p><h4>Exercise 2: Spot the Bug (Very Important Skill)</h4><p><strong>Goal:</strong> Learn to recognize common props mistakes.</p><p>Look at this code:</p><pre>&lt;Greeting name=&quot;React&quot; /&gt;</pre><p>But inside the component:</p><pre>function Greeting({ nmae }) {<br>  return &lt;h2&gt;Hello {nmae}&lt;/h2&gt;;<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2d6e9e495f47" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React, Explained From Zero — Part 4: Thinking in Components]]></title>
            <link>https://medium.com/@saiamanaganti12/react-explained-from-zero-part-4-thinking-in-components-e6dc6063f5eb?source=rss-d4a81cb46fd4------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6dc6063f5eb</guid>
            <category><![CDATA[reusable-component]]></category>
            <category><![CDATA[react-components]]></category>
            <category><![CDATA[splitting-components]]></category>
            <category><![CDATA[components]]></category>
            <dc:creator><![CDATA[Sai Amanaganti]]></dc:creator>
            <pubDate>Sat, 07 Feb 2026 06:48:12 GMT</pubDate>
            <atom:updated>2026-02-07T06:48:12.732Z</atom:updated>
            <content:encoded><![CDATA[<h3>React, Explained From Zero — Part 4: Thinking in Components</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q5BbH4JHKJpuhV1cxEZ2Lg.png" /></figure><p>In Part 3, you learned what React components are and how JSX works.</p><p>At this point, you can write JSX and change what appears on the screen — which is great. But React’s real power doesn’t come from writing JSX once.</p><p>It comes from <strong>breaking your UI into reusable pieces(components)</strong>.</p><p>That’s what this part is about.</p><h3>Goal of This Part</h3><p>By the end of this article, you will:</p><ul><li>Understand what it means to “think in components”</li><li>Know when something should become a component</li><li>Create and reuse your own components</li><li>Avoid putting everything inside App.jsx</li></ul><h3>Why Components Matter</h3><p>Imagine building a UI like this:</p><ul><li>A header</li><li>A main section</li><li>A footer</li></ul><p>You <em>could</em> write everything inside App.jsx.</p><p>If you keep everything in one file, even small apps become hard to read and harder to change.</p><p>Components are React’s way of keeping your UI organized as it grows. React solves this by letting you <strong>split the UI into small, reusable components</strong>.</p><p>A helpful mental model:</p><blockquote><strong><em>Components are like LEGO blocks for your UI.</em></strong></blockquote><p>Each block does one thing, and you combine them to build the full app.</p><h3>Your App Is Already a Component</h3><p>You’ve already written one component:</p><pre>function App() {<br>  return &lt;h1&gt;Hello React&lt;/h1&gt;;<br>}</pre><p>This means:</p><ul><li>App is not special because of its name</li><li>It’s just a component like any other</li><li>You can create more components the same way</li></ul><h3>Creating Your First Custom Component</h3><p>Let’s create a new component.</p><p>Inside the src folder, create a new file:</p><pre>Header.jsx</pre><p>Add this code:</p><pre>function Header() {<br>  return &lt;h2&gt;This is the Header&lt;/h2&gt;;<br>}<br><br>export default Header;</pre><p>That’s it.</p><p>You’ve just created a React component.</p><blockquote><strong>A component is just a JavaScript function that returns JSX. We usually put one component per file, but that’s a convention — not a rule.</strong></blockquote><h3>Using a Component Inside Another Component</h3><pre>App.jsx<br>┌─────────────────────────────────────────────┐<br>│ &lt;Header /&gt;                                  │<br>│ &lt;p&gt;This content is coming from App.jsx&lt;/p&gt;  │<br>└─────────────────────────────────────────────┘<br>        │<br>        ▼<br>Header.jsx<br>┌─────────────────────────────┐<br>│ &lt;h2&gt;This is the Header&lt;/h2&gt; │<br>└─────────────────────────────┘</pre><p>Now open App.jsx and update it:</p><pre>import Header from &quot;./Header&quot;;<br><br>function App() {<br>  return (<br>    &lt;div&gt;<br>      &lt;Header /&gt;<br>      &lt;p&gt;This content is coming from App.jsx&lt;/p&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><p>Save the file.</p><p>You’ll see both the header and the paragraph on the screen.</p><p>What just happened?</p><ul><li>You created a component</li><li>You imported it</li><li>You used it like an HTML tag</li></ul><p>That’s component composition.</p><h3>Components Look Like HTML — But They Aren’t</h3><p>Notice this line:</p><pre>&lt;Header /&gt;</pre><p>It looks like HTML, but:</p><ul><li>It starts with a capital letter</li><li>It refers to a JavaScript function</li><li>React knows to execute that function and render its JSX</li></ul><p><strong>Rule to remember:</strong></p><ul><li>HTML elements are lowercase (div, h1, p)</li><li>React components are capitalized (Header, App, Footer)</li></ul><h3>When Should Something Be a Component?</h3><p>This is a skill that developers get better at with experience.</p><p>For now, here’s a good beginner rule:</p><p>Create a component when:</p><ul><li>A piece of UI is reused</li><li>A section feels logically “separate”</li><li>A file is getting too long</li></ul><p>Examples of good components:</p><ul><li>A navigation bar</li><li>A footer</li><li>A blog post card</li><li>A header section</li></ul><h4>Bad reason to create a component:</h4><blockquote>“Because React lets me”</blockquote><p>Clarity always wins over over-engineering.</p><h3>Keeping Components Simple</h3><p>For now, your components should:</p><ul><li>Return JSX</li><li>Have no logic</li><li>Have no data passing between them</li></ul><p>We’ll add those features later.</p><p>Right now, the goal is to <strong>learn structure and composition</strong>.</p><h3>What You Should Understand Now</h3><p>At this stage, you should be comfortable with:</p><ul><li>Creating components</li><li>Importing components</li><li>Using components inside other components</li><li>Thinking of your UI as small, reusable pieces</li></ul><p>This mindset is the foundation of every React app you’ll ever build.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6dc6063f5eb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React, Explained From Zero — Part 3: Understanding Components, JSX, and TSX]]></title>
            <link>https://medium.com/@saiamanaganti12/react-explained-from-zero-part-3-understanding-components-jsx-and-tsx-27ef7ef74985?source=rss-d4a81cb46fd4------2</link>
            <guid isPermaLink="false">https://medium.com/p/27ef7ef74985</guid>
            <category><![CDATA[tsx]]></category>
            <category><![CDATA[react-components]]></category>
            <category><![CDATA[jsx]]></category>
            <dc:creator><![CDATA[Sai Amanaganti]]></dc:creator>
            <pubDate>Thu, 05 Feb 2026 09:47:33 GMT</pubDate>
            <atom:updated>2026-02-05T10:10:42.710Z</atom:updated>
            <content:encoded><![CDATA[<h3>React, Explained From Zero — Part 3: Understanding Components, JSX, and TSX</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aiSzeEGTOr4Hoq6Xmkw77Q.png" /></figure><p>In <strong>Part 2</strong>, we saw how a React application starts and which files actually matter.</p><p>At this point, most beginners can run the app successfully — but something still feels <em>weird</em>.</p><p>You open App.jsx and think:</p><blockquote><strong>“Why does this look like HTML inside JavaScript?”</strong></blockquote><p>That confusion is completely normal.</p><p>To understand React properly, you must understand <strong>components</strong> and <strong>JSX</strong>.<br> Once this clicks, React stops feeling magical and starts feeling logical.</p><p>That’s exactly what we’ll focus on in this part.</p><h3>Goal of This Part</h3><p>By the end of this article, you will:</p><ul><li>Understand what a React component really is</li><li>Know what JSX is and why React uses it</li><li>Be comfortable writing basic JSX</li><li>Understand what .jsx and .tsx files mean</li><li>Know when you need to care about TSX (and when you don’t)</li></ul><h3>Why React Code Looks Like HTML Inside JavaScript</h3><p>Let’s start with the confusion itself.</p><p>When you look at this:</p><pre>&lt;h1&gt;Hello React&lt;/h1&gt;</pre><p>It <em>looks</em> like HTML.</p><p>But this code lives inside a JavaScript file.</p><p>So what’s going on?</p><p>React uses a special syntax called <strong>JSX</strong> that allows you to write UI code in a way that <em>resembles</em> HTML, while still being JavaScript.</p><p>A simple mental model:</p><blockquote><strong>JSX lets you describe what the UI should look like, using a syntax that is easy for humans to read.</strong></blockquote><p>It’s designed this way on purpose — because UI is easier to understand visually than through plain JavaScript function calls.</p><h3>What Is a React Component?</h3><p>Before understanding JSX, we need to clearly understand <strong>components</strong>.</p><p>At its core, a React component is just a <strong>JavaScript function</strong>.</p><p>Here’s a simple example:</p><pre>function App() {<br>  return &lt;h1&gt;Hello React&lt;/h1&gt;;<br>}</pre><p>That’s it.</p><ul><li>App is a function</li><li>It returns something that looks like HTML</li><li>React uses that return value to build the UI</li></ul><p>A useful way to think about it:</p><blockquote><strong><em>A React component is a function that returns UI.</em></strong></blockquote><p>React takes that returned UI and displays it in the browser.</p><h3>What Is JSX?</h3><p>Now let’s name the thing we’ve been using.</p><p><strong>JSX</strong> stands for <strong><em>JavaScript XML</em></strong>.</p><p>It’s a syntax extension that allows you to write code like this:</p><pre>const element = &lt;p&gt;This is JSX&lt;/p&gt;;</pre><p>Even though it looks like HTML, this is <strong>not HTML</strong>.</p><ul><li>Browsers do not understand JSX</li><li>JSX runs inside JavaScript files</li><li>Tools like <strong>Vite</strong> convert JSX into normal JavaScript behind the scenes</li></ul><p>You don’t need to worry about how that works yet — just know that JSX is <strong>JavaScript syntax designed for writing UI</strong>.</p><h3>JSX vs HTML (Important Differences)</h3><p>JSX looks similar to HTML, but there are some important differences you should know early.</p><h3>1. JSX Must Return One Parent Element</h3><p>This is not allowed:</p><pre>&lt;h1&gt;Hello&lt;/h1&gt;<br>&lt;p&gt;Welcome&lt;/p&gt;</pre><p>This is allowed:</p><pre>&lt;div&gt;<br>  &lt;h1&gt;Hello&lt;/h1&gt;<br>  &lt;p&gt;Welcome&lt;/p&gt;<br>&lt;/div&gt;</pre><p>Everything must be wrapped in a single parent element.</p><h3>2. className Instead of class</h3><p>In JSX, you write:</p><pre>&lt;div className=&quot;container&quot;&gt;</pre><p>Not:</p><pre>&lt;div class=&quot;container&quot;&gt;</pre><p>Why?</p><p>Because class is a reserved keyword in JavaScript.</p><p>This is one of the <strong>most common beginner mistakes</strong> — and completely normal.</p><h3>3. JavaScript Goes Inside { }</h3><p>JSX allows you to insert JavaScript expressions using curly braces.</p><p>Example:</p><pre>function App() {<br>  const name = &quot;React&quot;;<br>  return &lt;h1&gt;Hello {name}&lt;/h1&gt;;<br>}</pre><p>This will display:</p><pre>Hello React</pre><p>You’ll use this pattern a lot later.</p><h3>What Is TSX?</h3><p>At some point, you may see files named:</p><ul><li>App.jsx</li><li>App.tsx</li></ul><p>The difference is simple:</p><ul><li><strong>JSX</strong> → JavaScript + JSX</li><li><strong>TSX</strong> → TypeScript + JSX</li></ul><p>TSX is used when a React project is written in <strong>TypeScript</strong> instead of JavaScript.</p><h3>Important Reassurance for Beginners</h3><p>If you’re learning React with JavaScript:</p><blockquote><strong><em>You do NOT need to worry about TSX right now.</em></strong></blockquote><p>The concepts are the same.<br> The syntax is almost identical.<br> TypeScript just adds extra type checking.</p><p>You can safely ignore TSX until you’re comfortable with React itself.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=27ef7ef74985" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React, Explained From Zero — Part 2: Understanding Your First React Project]]></title>
            <link>https://medium.com/@saiamanaganti12/react-explained-from-zero-part-2-understanding-your-first-react-project-16f46646516f?source=rss-d4a81cb46fd4------2</link>
            <guid isPermaLink="false">https://medium.com/p/16f46646516f</guid>
            <category><![CDATA[react-project-structure]]></category>
            <dc:creator><![CDATA[Sai Amanaganti]]></dc:creator>
            <pubDate>Wed, 04 Feb 2026 11:38:45 GMT</pubDate>
            <atom:updated>2026-02-04T11:39:38.384Z</atom:updated>
            <content:encoded><![CDATA[<h3>React, Explained From Zero — Part 2: Understanding Your First React Project</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YRH-jpuM8SDVFui-eXw-WQ.png" /></figure><p>In Part 1 of this series, you successfully created and ran a React application using Vite.</p><p>That alone is a solid milestone.</p><p>However, most beginners hit the same question immediately after:</p><blockquote><strong><em>“Okay… it’s running. But what am I actually looking at?”</em></strong></blockquote><p>Before writing React code, hooks, or JSX, you need to understand <strong>how the app starts</strong> and <strong>which files actually matter</strong>.</p><p>That’s exactly what we’ll do in this article.</p><h4><strong>Goal of This Part</strong></h4><p>By the end of this article, you will:</p><ul><li>Understand how a React app starts running</li><li>Know what index.html, main.jsx, and App.jsx actually do</li><li>Know <strong>which file to edit first</strong></li><li>Make your <strong>first meaningful UI change</strong> with confidence</li></ul><h3>How Does a React App Start?</h3><p>Let’s zoom out and keep this <strong>very simple</strong>.</p><p>When you open your React app in the browser, this is what happens:</p><ol><li>The browser loads index.html</li><li>index.html loads main.jsx</li><li>main.jsx tells React to render App.jsx</li><li>Whatever App.jsx returns appears on the screen</li></ol><p>That’s it.</p><h3>Understanding index.html</h3><p>Open the index.html file in your project root. You’ll see something like this:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>  &lt;head&gt;<br>    &lt;meta charset=&quot;UTF-8&quot; /&gt;<br>    &lt;title&gt;Vite + React&lt;/title&gt;<br>  &lt;/head&gt;<br>  &lt;body&gt;<br>    &lt;div id=&quot;root&quot;&gt;&lt;/div&gt;<br>    &lt;script type=&quot;module&quot; src=&quot;/src/main.jsx&quot;&gt;&lt;/script&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><p>The most important line here is:</p><pre>&lt;div id=&quot;root&quot;&gt;&lt;/div&gt;</pre><p>This is <strong>not</strong> your UI.<br>It’s an <strong>empty container</strong>.</p><p>A simple mental model to remember:</p><blockquote><strong>React needs an empty box in the HTML where it can place the entire application.</strong></blockquote><p>That empty box is called root.</p><p>React takes control of this &lt;div&gt; and inserts everything you see on the screen into it.<br> You usually won’t edit index.html often — and that’s completely normal.</p><h3>Understanding main.jsx</h3><p>Now open this file:</p><pre>src/main.jsx</pre><p>You’ll see something like:</p><pre>import React from &quot;react&quot;;<br>import ReactDOM from &quot;react-dom/client&quot;;<br>import App from &quot;./App&quot;;<br><br>ReactDOM.createRoot(document.getElementById(&quot;root&quot;)).render(<br>  &lt;App /&gt;<br>);</pre><p>Don’t worry about the syntax yet. Let’s read it in plain English.</p><h3>What does main.jsx do?</h3><ul><li>This is the <strong>entry point</strong> of your React app</li><li>It connects React to the browser</li><li>It tells React <strong>where</strong> the app should be rendered</li></ul><p>The key part is:</p><pre>document.getElementById(&quot;root&quot;)</pre><p>It grabs the &lt;div id=&quot;root&quot;&gt;&lt;/div&gt; from index.html.</p><p>Then React says:</p><blockquote>“Render the App component inside this element.”</blockquote><p>You typically don’t change this file very often.</p><p>A good way to think about it is:</p><blockquote><em>main.jsx</em><strong><em> is the power switch that turns your React app on.</em></strong></blockquote><h3>Understanding App.jsx</h3><p>Now we’re at the most important file.</p><p>Open:</p><pre>src/App.jsx</pre><p>You’ll see something like:</p><pre>function App() {<br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Hello React&lt;/h1&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><p>This file is special because:</p><ul><li>App is your <strong>first React component</strong></li><li>It controls <strong>what appears on the screen</strong></li><li>You’ll spend <strong>most of your time editing this file</strong></li></ul><p>Everything inside the <strong>return</strong> is what React displays in the browser.</p><p><strong>A simple rule to remember:</strong></p><blockquote><strong><em>“If I want to change what I see on the screen, I start with </em></strong><em>App.jsx</em><strong><em>.”</em></strong></blockquote><h3>Your First Safe Experiment</h3><p>Let’s make a small change.</p><p>Replace your App.jsx with this:</p><pre>function App() {<br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;My First React App 🚀&lt;/h1&gt;<br>      &lt;p&gt;This text is coming from App.jsx&lt;/p&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><p>Now save the file.</p><p><strong>What just happened?</strong></p><ul><li>You didn’t refresh the browser</li><li>The UI updated instantly</li></ul><p>This is Vite doing its job. It watches your files and updates the browser automatically when something changes.</p><p>This fast feedback loop is one of the reasons React + Vite feels so pleasant to work with, especially for beginners.</p><h3>Common Beginner Confusions (Read This Carefully)</h3><h4>“I changed something but nothing happened”</h4><ul><li>Make sure you saved the file</li><li>Make sure you edited App.jsx, not index.html</li><li>Check the browser console for errors</li></ul><h4>“Which file should I edit?”</h4><p>Most of the time:</p><p>App.jsx</p><p>Other files exist to <strong>support</strong> it.</p><h3>“Did I break React?”</h3><p>No<br>If the app is still running, you’re doing fine. Breaking things is part of learning, and React is more resilient than it looks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16f46646516f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>