<?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 Noran Saber Abdelfattah on Medium]]></title>
        <description><![CDATA[Stories by Noran Saber Abdelfattah on Medium]]></description>
        <link>https://medium.com/@noransaber685?source=rss-f9117bc94016------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*b-is1Hsfi2HI0vwkR6aSgA.jpeg</url>
            <title>Stories by Noran Saber Abdelfattah on Medium</title>
            <link>https://medium.com/@noransaber685?source=rss-f9117bc94016------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 14 Nov 2026 13:59:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@noransaber685/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[Next.js Routing Patterns Explained: Full Page Routes, Query Params, and Modals]]></title>
            <link>https://javascript.plainenglish.io/next-js-routing-patterns-explained-full-page-routes-query-params-and-modals-6137398522aa?source=rss-f9117bc94016------2</link>
            <guid isPermaLink="false">https://medium.com/p/6137398522aa</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[frontend]]></category>
            <dc:creator><![CDATA[Noran Saber Abdelfattah]]></dc:creator>
            <pubDate>Tue, 02 Jun 2026 03:53:28 GMT</pubDate>
            <atom:updated>2026-06-02T03:53:28.943Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JDjpQsR5vXhQY_xOgn1vDQ.png" /></figure><p><em>You’re building a Cover Letter Builder. A user clicks “Modern Template.” Now what? Do you navigate to a new page, update the URL quietly, or pop open a modal? The answer shapes your entire user experience — and most beginners guess wrong.</em></p><p>This guide breaks down the three routing patterns you’ll reach for constantly in Next.js, when to use each one, and the navigation mechanics (router.push, replace, Link) that tie it all together. By the end, you’ll have a simple decision rule you can apply to any feature you build.</p><h3>The Setup: What Are We Actually Choosing Between?</h3><p>Imagine you’re building a job application tool. Users browse a gallery of CV/cover letter templates and pick one to start editing. The moment they click “Use This Template,” you have three options:</p><pre>Option A → navigate to /cover-letter/modern       (Full Page Route)<br>Option B → stay on /templates?selected=modern     (Query Params)<br>Option C → open a popup on top of /templates      (Modal)</pre><p>Each one feels slightly different to the user. Each one has different implications for your code. Let’s go through them one by one.</p><h3>Pattern 1: Full Page Route</h3><h3>What it looks like</h3><pre>/cover-letter/modern<br>/cover-letter/minimal<br>/cover-letter/creative</pre><h3>How it works in Next.js App Router</h3><p>You create a folder structure with square brackets — that’s the “dynamic segment”:</p><pre>app/<br> └── cover-letter/<br>      └── [templateId]/<br>           └── page.tsx</pre><p>The [templateId] part is a placeholder. When a user visits /cover-letter/modern, Next.js automatically fills in:</p><p>ts</p><pre>params.templateId = &quot;modern&quot;</pre><p>Your page component receives this as a prop:</p><p>tsx</p><pre>// app/cover-letter/[templateId]/page.tsx<br>interface PageProps {<br>  params: { templateId: string }<br>}<br>export default function CoverLetterPage({ params }: PageProps) {<br>  const { templateId } = params<br>  // templateId = &quot;modern&quot; | &quot;minimal&quot; | &quot;creative&quot; etc.<br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Editing: {templateId} template&lt;/h1&gt;<br>      &lt;CoverLetterEditor templateId={templateId} /&gt;<br>    &lt;/div&gt;<br>  )<br>}</pre><p>You can also generate page metadata dynamically — great for SEO:</p><p>tsx</p><pre>// Same file, above the component<br>export async function generateMetadata({ params }: PageProps) {<br>  return {<br>    title: `${params.templateId} Cover Letter Template`,<br>    description: `Edit your cover letter using the ${params.templateId} layout`,<br>  }<br>}</pre><h3>Real-life examples of Full Page Routes</h3><p>These are all URLs that make sense to live at their own address:</p><pre>/products/nike-air-max-2024       ← a specific product<br>/blog/how-to-write-a-resume       ← a specific article<br>/users/johndoe                    ← a user profile<br>/checkout                         ← the checkout page<br>/dashboard/settings               ← settings section</pre><p>Think of it this way: if someone sent you that link in a WhatsApp message and you opened it, would it make sense? If yes — it belongs as a Full Page Route.</p><h3>When to use it</h3><p>Use Full Page Routes when the thing you’re showing has its own <strong>identity</strong>:</p><ul><li>It can be bookmarked and revisited later</li><li>It can be shared with someone else</li><li>It has its own loading state, error state, and metadata</li><li>The user is truly “going somewhere new” in your app</li></ul><h3>Pros</h3><p><strong>1. URLs are clean and readable</strong></p><pre>/cover-letter/modern    ← anyone can read this</pre><p><strong>2. Bookmarkable</strong> — users can save the link and come back a week later. Their work is right there.</p><p><strong>3. Shareable</strong> — paste the URL anywhere, it opens the same thing.</p><p><strong>4. Browser back button works naturally</strong> — tap back on mobile, you go to the previous page. No tricks needed.</p><p><strong>5. Great for SEO</strong> — Google prefers clean path-based URLs:</p><pre>/blog/react-hooks        ← Google loves this<br>/blog?id=react-hooks     ← Google likes this less</pre><p><strong>6. Each page has its own lifecycle</strong> — independent loading, error boundaries, and layout.</p><h3>Cons</h3><p><strong>1. Navigation takes a moment</strong> — you’re doing a full page transition, not a quick popup.</p><p><strong>2. Overkill for quick interactions</strong> — if you just want a user to preview an image or confirm a delete, a full page navigation is too heavy.</p><h3>Pattern 2: Query Params</h3><h3>What it looks like</h3><pre>/cover-letter?template=modern<br>/products?category=shoes&amp;color=black&amp;size=42<br>/search?q=react+hooks&amp;page=2</pre><h3>How it works in Next.js</h3><p>You read query params using the useSearchParams hook (client component only):</p><p>tsx</p><pre>&#39;use client&#39;<br>import { useSearchParams } from &#39;next/navigation&#39;<br>export default function CoverLetterPage() {<br>  const searchParams = useSearchParams()<br>  const template = searchParams.get(&#39;template&#39;)  // &quot;modern&quot;<br>  const page = searchParams.get(&#39;page&#39;)           // &quot;2&quot; (always a string)<br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Template: {template}&lt;/h1&gt;<br>    &lt;/div&gt;<br>  )<br>}</pre><blockquote><strong><em>Note:</em></strong><em> Query params are always strings. If you store a number like </em><em>?page=2, you&#39;ll need to convert it: </em><em>Number(searchParams.get(&#39;page&#39;)).</em></blockquote><p>You can update query params without a full page reload using useRouter:</p><p>tsx</p><pre>&#39;use client&#39;<br>import { useRouter, useSearchParams, usePathname } from &#39;next/navigation&#39;<br>export default function FilterBar() {<br>  const router = useRouter()<br>  const pathname = usePathname()<br>  const searchParams = useSearchParams()<br>  function setFilter(key: string, value: string) {<br>    // Build a new URLSearchParams from the current ones<br>    const params = new URLSearchParams(searchParams.toString())<br>    params.set(key, value)<br>    // Update the URL without navigating away<br>    router.push(`${pathname}?${params.toString()}`)<br>  }<br>  return (<br>    &lt;div&gt;<br>      &lt;button onClick={() =&gt; setFilter(&#39;color&#39;, &#39;black&#39;)}&gt;Black&lt;/button&gt;<br>      &lt;button onClick={() =&gt; setFilter(&#39;color&#39;, &#39;white&#39;)}&gt;White&lt;/button&gt;<br>    &lt;/div&gt;<br>  )<br>}</pre><h3>Real-life examples of Query Params</h3><p>You see these everywhere in e-commerce and search:</p><pre>amazon.com/s?k=laptop&amp;rh=p_36:10000-50000     ← search + price filter<br>youtube.com/results?search_query=next.js       ← search query<br>airbnb.com/s/Paris?checkin=2024-06-01         ← date filter<br>github.com/issues?q=is:open+label:bug          ← issue filte</pre><p>None of these are “new pages” — they’re all the same page with different data showing.</p><h3>When to use it</h3><p>Use query params when you’re controlling <strong>state within the same page</strong>, not navigating to a new concept:</p><ul><li>Filters (color, size, price range)</li><li>Sorting (newest, price low to high)</li><li>Pagination (page 1, page 2)</li><li>Active tab (overview, reviews, specs)</li><li>Search keywords</li><li>View mode (grid vs list)</li></ul><h3>Pros</h3><p><strong>1. Perfect for filters</strong> — the most common use case in the real world.</p><p><strong>2. Still shareable</strong> — ?color=black&amp;size=42 in the URL means someone else gets the same filtered view.</p><p><strong>3. Survives a refresh</strong> — if the user refreshes the page, their filters are still there (they’re in the URL, not in useState).</p><p><strong>4. Great for lightweight UI state</strong> — tabs, pagination, search — anything that’s “same page, different view.”</p><h3>Cons</h3><p><strong>1. Less readable than clean paths:</strong></p><pre>/cover-letter/modern        ← clear<br>/cover-letter?template=modern  ← slightly noisier</pre><p><strong>2. Not ideal for primary resources</strong> — if something is a standalone page (a product, a user profile, an article), it deserves its own path, not a query param.</p><p><strong>3. Slightly weaker SEO</strong> — for content that matters to Google, clean paths are better.</p><h3>Pattern 3: Modal</h3><h3>What it looks like</h3><pre>A popup appears on top of the current page.<br>The URL might not change at all.<br>The background page is still there, dimmed behind the modal.</pre><h3>How it works</h3><p>The simplest version uses local React state:</p><p>tsx</p><pre>&#39;use client&#39;<br><br>import { useState } from &#39;react&#39;<br>export default function TemplateGallery() {<br>  const [isOpen, setIsOpen] = useState(false)<br>  const [selectedTemplate, setSelectedTemplate] = useState&lt;string | null&gt;(null)<br>  function openPreview(templateId: string) {<br>    setSelectedTemplate(templateId)<br>    setIsOpen(true)<br>  }<br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Choose a Template&lt;/h1&gt;<br>      &lt;div className=&quot;grid&quot;&gt;<br>        {[&#39;modern&#39;, &#39;minimal&#39;, &#39;creative&#39;].map((id) =&gt; (<br>          &lt;div key={id} onClick={() =&gt; openPreview(id)}&gt;<br>            &lt;img src={`/templates/${id}.png`} alt={id} /&gt;<br>            &lt;button&gt;Preview&lt;/button&gt;<br>          &lt;/div&gt;<br>        ))}<br>      &lt;/div&gt;<br>      {/* The modal */}<br>      {isOpen &amp;&amp; selectedTemplate &amp;&amp; (<br>        &lt;div className=&quot;modal-overlay&quot; onClick={() =&gt; setIsOpen(false)}&gt;<br>          &lt;div className=&quot;modal-content&quot; onClick={(e) =&gt; e.stopPropagation()}&gt;<br>            &lt;button onClick={() =&gt; setIsOpen(false)}&gt;✕ Close&lt;/button&gt;<br>            &lt;h2&gt;Preview: {selectedTemplate}&lt;/h2&gt;<br>            &lt;img src={`/templates/${selectedTemplate}-preview.png`} alt=&quot;preview&quot; /&gt;<br>            &lt;a href={`/cover-letter/${selectedTemplate}`}&gt;<br>              Use This Template →<br>            &lt;/a&gt;<br>          &lt;/div&gt;<br>        &lt;/div&gt;<br>      )}<br>    &lt;/div&gt;<br>  )<br>}</pre><p>A more advanced version (like how Instagram does it) changes the URL when the modal opens — so it’s shareable — but still shows a modal on top of the gallery. This uses Next.js <strong>Parallel Routes with Intercepting Routes</strong>, which is an advanced topic for when you’re comfortable with the basics.</p><h3>Real-life examples of Modals</h3><pre>Instagram → click a photo   → modal opens, URL changes to /p/ABC123<br>GitHub    → delete a repo   → &quot;Are you sure?&quot; confirm modal<br>Figma     → right-click     → context menu / quick action modal<br>Airbnb    → photo gallery   → image lightbox (fullscreen zoom)<br>Notion    → create new page → simple name input modal<br>Linear    → create issue    → full-featured create modal<br>Stripe    → view payment    → details slide-in panel</pre><h3>When to use it</h3><p>Use a modal when the interaction is <strong>temporary</strong> — the user needs to do something quick and return to what they were doing:</p><ul><li>Confirm a destructive action (“Delete this file?”)</li><li>Preview something before committing (“See what this template looks like”)</li><li>Fill in a short form (“Add a comment”)</li><li>Zoom into an image</li><li>Show a login prompt</li></ul><h3>Pros</h3><p><strong>1. Fast</strong> — opens and closes instantly, no navigation.</p><p><strong>2. User stays in context</strong> — the original page is still there behind the modal. Great for workflows where they need to keep their place.</p><p><strong>3. Perfect for temporary interactions</strong> — confirm, preview, quick edit, zoom.</p><h3>Cons</h3><p><strong>1. Not shareable by default</strong> — there’s no URL to copy and paste (unless you add extra logic).</p><p><strong>2. Disappears on refresh</strong> — because the state lives in useState, a page reload closes the modal.</p><p><strong>3. Browser back button is tricky</strong> — by default, pressing back doesn’t close the modal, it navigates away from the page entirely. You need extra code to handle this.</p><p><strong>4. Accessibility requires extra work</strong> — you need to handle focus trapping (keyboard can’t escape the modal accidentally), the Escape key closing it, and preventing background scroll. Libraries like Radix UI or Headless UI handle this for you.</p><h3>The Decision Framework: 3 Questions</h3><p>Before you build anything, ask yourself these three questions in order:</p><pre>Question 1: &quot;Can someone send this URL to a friend and have it open the right thing?&quot;<br>            If yes → Full Page Route<br><br>Question 2: &quot;Is this just a different view of the same page?&quot;<br>            If yes → Query Param<br>Question 3: &quot;Is the user doing something quick and coming right back?&quot;<br>            If yes → Modal</pre><p>Here’s that mapped to the Cover Letter Builder example:</p><p>User actionBest patternWhyOpens the builder for “modern” templateFull Page Route/cover-letter/modern — it&#39;s their workspace, they&#39;ll bookmark itSwitches template inside the builderQuery Param/cover-letter?template=modern — same page, different viewPreviews a template before committingModalQuick look, then decide — no need for a full pageConfirms &quot;Delete my draft&quot;ModalTemporary destructive actionViews a friend&#39;s shared cover letterFull Page RouteShared URL should open something meaningful</p><h3>The Part Most Beginners Skip: Browser History &amp; Navigation Methods</h3><p>This is where it gets interesting — and where most beginners hit confusing bugs.</p><p>When you navigate in a browser, it maintains a <strong>history stack</strong>. Think of it like a stack of cards:</p><pre>[Home] [Templates] [Cover Letter / Modern]<br>                                    ↑ you are here</pre><p>Every time you go somewhere new, a card gets added. When you press Back, the top card is removed.</p><p>Next.js gives you three ways to navigate — and they behave very differently.</p><h3>Method 1: &lt;Link&gt; — The Default, Always Start Here</h3><p>&lt;Link&gt; is Next.js&#39;s version of an anchor tag. It handles client-side navigation (fast, no full page reload) automatically.</p><p>tsx</p><pre>import Link from &#39;next/link&#39;<br><br>// Basic navigation<br>&lt;Link href=&quot;/cover-letter/modern&quot;&gt;<br>  Open Modern Template<br>&lt;/Link&gt;<br>// With dynamic values<br>&lt;Link href={`/cover-letter/${templateId}`}&gt;<br>  Open {templateId}<br>&lt;/Link&gt;<br>// Prefetches the page on hover - instant feel<br>&lt;Link href=&quot;/templates&quot; prefetch={true}&gt;<br>  Browse Templates<br>&lt;/Link&gt;</pre><p><strong>What it does to browser history:</strong> Adds a new entry. User can press Back to return.</p><p><strong>Real-life analogy:</strong> Clicking a link in a book that takes you to a new chapter. You can flip back.</p><p><strong>Use it for:</strong> Almost all navigation. Links in navbars, buttons that take users to new pages, breadcrumbs.</p><h3>Method 2: router.push() — Programmatic Navigation</h3><p>Sometimes you need to navigate based on logic, not a click on a static link. For example: after a form submission, redirect the user.</p><p>tsx</p><pre>&#39;use client&#39;<br><br>import { useRouter } from &#39;next/navigation&#39;<br>export default function TemplateCard({ templateId }: { templateId: string }) {<br>  const router = useRouter()<br>  async function handleSelectTemplate() {<br>    // Maybe save to database first<br>    await saveSelection(templateId)<br>    // Then navigate<br>    router.push(`/cover-letter/${templateId}`)<br>  }<br>  return (<br>    &lt;button onClick={handleSelectTemplate}&gt;<br>      Use This Template<br>    &lt;/button&gt;<br>  )<br>}</pre><p><strong>What it does to browser history:</strong> Same as &lt;Link&gt; — adds a new entry. User can press Back.</p><p><strong>Real-life analogy:</strong> A staff member escorting you to a new room. You still came from somewhere, so you can go back.</p><p><strong>Use it for:</strong></p><ul><li>After form submission (redirect to success page)</li><li>After login (redirect to dashboard)</li><li>After completing a multi-step flow</li><li>Conditional navigation based on logic</li></ul><p>tsx</p><pre>// Common pattern: redirect after login<br>async function handleLogin(email: string, password: string) {<br>  const result = await login(email, password)<br><br>if (result.success) {<br>    router.push(&#39;/dashboard&#39;)        // go to dashboard<br>  } else {<br>    setError(&#39;Invalid credentials&#39;)  // stay on login page, show error<br>  }<br>}</pre><h3>Method 3: router.replace() — Navigate Without Leaving a History Trail</h3><p>replace is like push — it takes you to a new page — but it <strong>replaces</strong> the current history entry instead of adding a new one.</p><p>tsx</p><pre>router.replace(&#39;/cover-letter/modern&#39;)</pre><p><strong>What it does to browser history:</strong></p><pre>Before push:    [Home] [Templates]<br>After push:     [Home] [Templates] [Cover Letter/Modern]   ← new card added<br>Back works ✅</pre><pre>Before replace: [Home] [Templates]<br>After replace:  [Home] [Cover Letter/Modern]               ← current card swapped<br>Back goes to Home, not Templates ⚠️</pre><p><strong>Real-life analogy:</strong> An editor who changes the current page you’re on instead of giving you a new one. There’s no “previous version” to go back to.</p><p><strong>Use it for (the real cases):</strong></p><p><strong>Case 1: After login, don’t let users go “back” to the login page:</strong></p><p>tsx</p><pre>// After login succeeds:<br>router.replace(&#39;/dashboard&#39;)<br>// Now if user presses Back, they go to whatever was before the login page<br>// NOT back to the login form (which would be confusing and insecure)</pre><p><strong>Case 2: Multi-step forms — don’t let users go back to completed steps:</strong></p><p>tsx</p><pre>// Step 1 → Step 2 → Step 3<br>// When user completes step 1:<br>router.replace(&#39;/onboarding/step-2&#39;)<br>// Now Back from step 2 doesn&#39;t return to step 1<br>// (They already submitted step 1, going back would cause confusion)</pre><p><strong>Case 3: Resetting filters without polluting history:</strong></p><p>tsx</p><pre>function clearAllFilters() {<br>  router.replace(&#39;/products&#39;)  // go back to clean URL<br>  // Without replace: history stack fills up with filter combinations<br>}<br>&#39;use client&#39;<br>import Link from &#39;next/link&#39;<br>import { useRouter } from &#39;next/navigation&#39;<br>import { useState } from &#39;react&#39;<br>const templates = [&#39;modern&#39;, &#39;minimal&#39;, &#39;creative&#39;, &#39;executive&#39;]<br>export default function TemplatesPage() {<br>  const router = useRouter()<br>  const [previewTemplate, setPreviewTemplate] = useState&lt;string | null&gt;(null)<br>  async function handleUseTemplate(templateId: string) {<br>    // Save choice, then navigate (router.push - user can go back)<br>    await fetch(&#39;/api/drafts&#39;, {<br>      method: &#39;POST&#39;,<br>      body: JSON.stringify({ templateId }),<br>    })<br>    router.push(`/cover-letter/${templateId}`)<br>  }<br>  return (<br>    &lt;div&gt;<br>      &lt;nav&gt;<br>        {/* Link - simple navigation, adds to history */}<br>        &lt;Link href=&quot;/dashboard&quot;&gt;← Back to Dashboard&lt;/Link&gt;<br>      &lt;/nav&gt;<br>      &lt;h1&gt;Choose Your Template&lt;/h1&gt;<br>      &lt;div className=&quot;grid&quot;&gt;<br>        {templates.map((id) =&gt; (<br>          &lt;div key={id} className=&quot;card&quot;&gt;<br>            &lt;img src={`/previews/${id}.png`} alt={id} /&gt;<br>            &lt;h3&gt;{id}&lt;/h3&gt;<br>            {/* Quick preview → Modal */}<br>            &lt;button onClick={() =&gt; setPreviewTemplate(id)}&gt;<br>              Preview<br>            &lt;/button&gt;<br>            {/* Use template → router.push to builder page */}<br>            &lt;button onClick={() =&gt; handleUseTemplate(id)}&gt;<br>              Use This Template<br>            &lt;/button&gt;<br>          &lt;/div&gt;<br>        ))}<br>      &lt;/div&gt;<br>      {/* Modal - stays on same page, no URL change */}<br>      {previewTemplate &amp;&amp; (<br>        &lt;div className=&quot;modal-overlay&quot; onClick={() =&gt; setPreviewTemplate(null)}&gt;<br>          &lt;div className=&quot;modal&quot; onClick={(e) =&gt; e.stopPropagation()}&gt;<br>            &lt;button onClick={() =&gt; setPreviewTemplate(null)}&gt;✕&lt;/button&gt;<br>            &lt;img src={`/previews/${previewTemplate}-full.png`} alt=&quot;preview&quot; /&gt;<br>            &lt;button onClick={() =&gt; handleUseTemplate(previewTemplate)}&gt;<br>              Use This Template →<br>            &lt;/button&gt;<br>          &lt;/div&gt;<br>        &lt;/div&gt;<br>      )}<br>    &lt;/div&gt;<br>  )<br>}</pre><h3>Putting It All Together: A Real Cover Letter Builder Flow</h3><p>Here’s how all three navigation methods work together in one real feature:</p><p>tsx</p><pre>// app/templates/page.tsx<br>// The template gallery page</pre><p>tsx</p><pre>// app/cover-letter/[templateId]/page.tsx<br>// The actual builder page<br>&#39;use client&#39;<br>import { useRouter } from &#39;next/navigation&#39;<br>import { useSearchParams } from &#39;next/navigation&#39;<br>interface Props {<br>  params: { templateId: string }<br>}<br>export default function BuilderPage({ params }: Props) {<br>  const router = useRouter()<br>  const searchParams = useSearchParams()<br>  // Query param for active section within the builder<br>  // e.g., /cover-letter/modern?section=experience<br>  const activeSection = searchParams.get(&#39;section&#39;) ?? &#39;intro&#39;<br>  function switchSection(section: string) {<br>    // replace - switching sections shouldn&#39;t fill up history<br>    router.replace(`/cover-letter/${params.templateId}?section=${section}`)<br>  }<br>  async function handleSubmit() {<br>    await saveDraft()<br>    // replace - after saving, replace so Back doesn&#39;t re-submit<br>    router.replace(&#39;/dashboard?saved=true&#39;)<br>  }<br>  return (<br>    &lt;div className=&quot;builder&quot;&gt;<br>      &lt;h1&gt;Editing: {params.templateId} template&lt;/h1&gt;<br>      &lt;nav className=&quot;section-tabs&quot;&gt;<br>        {[&#39;intro&#39;, &#39;experience&#39;, &#39;skills&#39;].map((s) =&gt; (<br>          &lt;button<br>            key={s}<br>            onClick={() =&gt; switchSection(s)}<br>            className={activeSection === s ? &#39;active&#39; : &#39;&#39;}<br>          &gt;<br>            {s}<br>          &lt;/button&gt;<br>        ))}<br>      &lt;/nav&gt;<br>      &lt;SectionEditor section={activeSection} /&gt;<br>      &lt;button onClick={handleSubmit}&gt;Save &amp; Finish&lt;/button&gt;<br>    &lt;/div&gt;<br>  )<br>}</pre><h3>Quick Reference: Link vs push vs replace</h3><p>&lt;Link&gt;router.push()router.replace()Adds to history?✅ Yes✅ Yes❌ No (replaces)Back button works?✅ Yes✅ Yes⚠️ Skips this stepUse caseStatic links in UINavigate after logic/asyncRedirect after login, multi-step formsPrefetch support✅ Built-in❌❌ExampleNavbar linksPost-submit redirectAfter login, clear filter state</p><h3>The One-Sentence Summary for Each Pattern</h3><p><strong>Full Page Route</strong> — Use when the thing being shown deserves its own permanent address (product page, profile, article, builder).</p><p><strong>Query Params</strong> — Use when you’re adjusting the view of the same page (filters, sort, tabs, pagination).</p><p><strong>Modal</strong> — Use when the user needs to do something quick without losing their current place (confirm, preview, quick edit).</p><p><strong>router.push</strong> — Navigate forward and keep history (user can go back).</p><p><strong>router.replace</strong> — Navigate forward but erase the current step from history (login redirect, form steps).</p><p><strong>&lt;Link&gt;</strong> — The default for any clickable navigation in your UI.</p><h3>What to Build Next</h3><p>Now that you understand these patterns, a good exercise is to open any app you use daily (Airbnb, GitHub, Twitter, Notion) and identify which routing pattern each interaction uses. You’ll start seeing the logic behind every URL decision they made — and it’ll make your own decisions much easier.</p><p><em>Questions? Drop them in the comments — especially if you run into a case where none of these three patterns feels quite right. Those edge cases are where the real learning happens.</em></p><p>If you feel like you missed any concept, don’t hesitate to reach out — your feedback means a lot to me! 🌹. You can also connect with me on 🌹</p><p><a href="https://x.com/Noransaber11">Twitter </a>| <a href="https://www.linkedin.com/in/noran-saber-abdelfattah-6198471ba/">LinkedIn </a>| <a href="https://github.com/Noransaber">GitHub</a><br> — Noran 🌹</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6137398522aa" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/next-js-routing-patterns-explained-full-page-routes-query-params-and-modals-6137398522aa">Next.js Routing Patterns Explained: Full Page Routes, Query Params, and Modals</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Islands Architecture: The Idea That Changes How You Think About Web Performance]]></title>
            <link>https://javascript.plainenglish.io/islands-architecture-the-idea-that-changes-how-you-think-about-web-performance-fc3cd9b08f23?source=rss-f9117bc94016------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc3cd9b08f23</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[performance-management]]></category>
            <dc:creator><![CDATA[Noran Saber Abdelfattah]]></dc:creator>
            <pubDate>Wed, 27 May 2026 12:26:20 GMT</pubDate>
            <atom:updated>2026-05-27T12:26:20.771Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H3ZPJG4lLb7240gyofzQ5g.png" /></figure><p><em>Once you understand Islands Architecture, you’ll start seeing it everywhere — in the sites you visit, in the frameworks you use, and in every performance decision you make.</em></p><p>This isn’t about a specific framework or a new tool you need to learn. It’s a mental model for how you organize rendering on a page. Once it clicks, it’ll influence how you think about every web project you build.</p><p>Let’s build it from scratch.</p><h3>The One-Sentence Version</h3><p><strong>Islands Architecture = most of your page is static HTML, with small isolated interactive components scattered through it.</strong></p><pre>static page + isolated interactive components</pre><p>Those interactive components are the “<strong>islands</strong>.” They sit inside a sea of plain HTML — alive and interactive while everything around them is just markup.</p><p>That’s literally where the name comes from.</p><pre>🌊 HTML  🌊 HTML  🌊 HTML<br>🌊 HTML  🌊 HTML  🌊 HTML<br>🏝️ [ Search Box ]<br>🌊 HTML  🌊 HTML  🌊 HTML<br>        🏝️ [ Like Button ]<br>🌊 HTML  🌊 HTML  🌊 HTML</pre><h3>What a Page Actually Looks Like</h3><p>Imagine a typical blog article page:</p><pre>──────────────────────────────────────<br>  Header                  (static)<br>  Hero / Intro            (static)<br>  Article Content         (static)<br>  Images                  (static)<br><br><br>[ Newsletter Form ] (interactive ← island)<br><br>  Related Articles        (static)<br><br>      [ Like Button ]     (interactive ← island)<br><br>  Footer                  (static)<br>──────────────────────────────────────</pre><p><strong>Two interactive </strong>components out of eight sections. The rest is just HTML.</p><p>Now ask yourself: why would you ship a full JavaScript application for a page that’s 75% plain text and images?</p><p>That’s the question Islands Architecture was invented to answer.</p><h3>The Problem It Solves: A Short History</h3><p>To really get why this matters, you need to understand what came before.</p><h3>Era 1: Server-Rendered HTML (the old way)</h3><p>Back when the web was simpler, the server did everything. You’d request a page, the server would build the full HTML, and send it back:</p><p>html</p><pre>&lt;!-- Server sends this complete HTML --&gt;<br>&lt;h1&gt;My Blog Post&lt;/h1&gt;<br>&lt;p&gt;Here&#39;s the article content...&lt;/p&gt;<br>&lt;img src=&quot;photo.jpg&quot; alt=&quot;photo&quot; /&gt;<br>&lt;footer&gt;© 2024&lt;/footer&gt;</pre><p>The browser receives real content immediately. Pages loaded fast. But they weren’t very interactive — every click that needed new data required a full page reload.</p><h3>Era 2: Single Page Applications (SPAs)</h3><p>Then came React, Vue, Angular. The SPA era. Now the server sends almost nothing:</p><p>html</p><pre>&lt;!-- Server sends just this --&gt;<br>&lt;div id=&quot;root&quot;&gt;&lt;/div&gt;</pre><p>And JavaScript builds the entire page in the browser — every heading, paragraph, button, image. Everything.</p><p>This made apps incredibly dynamic and interactive. But it introduced a serious problem.</p><h3>The Problem: JavaScript Bloat</h3><p>Let’s say you have a blog post page with:</p><ul><li>A title</li><li>1,200 words of article text</li><li>5 images</li><li>A footer</li><li><strong>One Like button</strong></li></ul><p>With a full SPA, you might ship <strong>200KB–400KB of JavaScript</strong> to the user’s browser just to make that one Like button work.</p><p>The title doesn’t need JavaScript. The article text doesn’t need JavaScript. The images definitely don’t need JavaScript. But the SPA hydrates (makes interactive) the entire page anyway — because that’s how it’s built.</p><p>Islands Architecture looks at this and says: <strong>why are we doing this?</strong></p><blockquote><em>💡 Turn on the lights only in the rooms where people actually are — not the entire building.</em></blockquote><h3>The Core Concept: Hydration</h3><p>Before we go further, you need to understand <strong>hydration</strong>, because it’s central to how Islands work.</p><h3>What hydration means</h3><p>When a server renders HTML and sends it to the browser, the page <em>looks</em> correct — but nothing is wired up yet. The buttons don’t respond. The forms don’t submit. It’s like a beautiful stage set with no electricity.</p><p><strong>Hydration</strong> is the process of attaching JavaScript to that HTML so it becomes interactive.</p><pre>Before hydration:<br><br>&lt;button&gt;Like ❤️&lt;/button&gt;<br>↑ renders, looks fine, but clicking does nothing<br><br>After hydration:<br>&lt;button onClick={handleLike}&gt;Like ❤️&lt;/button&gt;<br>↑ now it actually works</pre><p>In a traditional SPA, hydration happens for the <strong>entire page</strong> — every component, every element, even the ones that don’t need it.</p><p>Islands Architecture says: <strong>only hydrate the parts that actually need to be interactive.</strong></p><pre>Full SPA hydration:<br>┌──────────────────────────────────┐<br>│  💧 Header                       │<br>│  💧 Hero                         │<br>│  💧 Article                      │<br>│  💧 Newsletter Form              │ ← only this actually needs JS<br>│  💧 Related Posts                │<br>│  💧 Like Button                  │ ← and this<br>│  💧 Footer                       │<br>└──────────────────────────────────┘<br>Hydrating: everything. JS shipped: 380KB.<br><br>Islands hydration:<br>┌──────────────────────────────────┐<br>│     Header                       │<br>│     Hero                         │<br>│     Article                      │<br>│  🏝️ Newsletter Form              │ ← hydrated<br>│     Related Posts                │<br>│  🏝️ Like Button                  │ ← hydrated<br>│     Footer                       │<br>└──────────────────────────────────┘<br>Hydrating: 2 components. JS shipped: 18KB.</pre><p>That difference in JavaScript shipped directly translates to faster pages, especially on mobile devices and slower connections.</p><h3>What Islands Look Like in Code</h3><p>The framework most associated with Islands Architecture is <strong>Astro</strong>. Here’s what a page might look like:</p><p>astro</p><pre>---<br>// This runs on the server. No JS sent to the browser.<br>import Header from &#39;./Header.astro&#39;<br>import ArticleContent from &#39;./ArticleContent.astro&#39;<br>import Footer from &#39;./Footer.astro&#39;<br>// These are interactive components<br>import LikeButton from &#39;./LikeButton.jsx&#39;<br>import NewsletterForm from &#39;./NewsletterForm.jsx&#39;<br>import SearchBox from &#39;./SearchBox.jsx&#39;<br>---<br>&lt;!-- Static components - zero JavaScript --&gt;<br>&lt;Header /&gt;<br>&lt;ArticleContent /&gt;<br>&lt;!-- Islands - JavaScript loaded and hydrated --&gt;<br>&lt;LikeButton client:load /&gt;<br>&lt;NewsletterForm client:visible /&gt;<br>&lt;SearchBox client:idle /&gt;<br>&lt;Footer /&gt;</pre><p>Notice the client: directives. These tell Astro <em>when</em> and <em>how</em> to hydrate each island:</p><p>Directive When it <strong>hydrates </strong>Best forclient:loadImmediately on page load Critical interactive elements (search, cart)client:idleWhen the browser is idleNon-urgent UI (theme toggle, share buttons)client:visibleWhen element scrolls into viewBelow-the-fold content (comments, newsletter)client:mediaWhen a CSS media query matchesMobile-only or responsive components</p><p>This granularity is powerful. You can say “load this search box immediately” but “wait until the user scrolls down to load the comments section.” That’s a level of control that traditional SPAs don’t give you.</p><h3>Real-World Examples</h3><h3>Example 1: A Blog Post Page</h3><pre>/blog/how-to-learn-react<br>Structure:<br>  - Blog post title         → static HTML<br>  - Author info             → static HTML<br>  - Article body (2000 words) → static HTML<br>  - Code blocks             → static HTML + CSS<br>  - Copy Code Button        → 🏝️ island (tiny JS to copy to clipboard)<br>  - Like / Bookmark         → 🏝️ island (JS to call API)<br>  - Comments Section        → 🏝️ island (loads when scrolled to)<br>  - Related Articles        → static HTML<br>  - Footer                  → static HTML<br>JavaScript sent: ~22KB (just for the 3 islands)<br>Instead of: ~350KB (for the full SPA version)</pre><h3>Example 2: An E-commerce Product Page</h3><pre>/products/nike-air-max<br><br>Structure:<br>  - Product images gallery  → static HTML (maybe with CSS lightbox)<br>  - Product title + brand   → static HTML<br>  - Description             → static HTML<br>  - Size guide              → static HTML<br>  - Color/Size Picker       → 🏝️ island (needs JS to update selection)<br>  - Add to Cart Button      → 🏝️ island (needs JS to call cart API)<br>  - Reviews Filter &amp; Sort   → 🏝️ island (needs JS to re-sort)<br>  - Stock Countdown Timer   → 🏝️ island (real-time countdown)<br>  - Shipping info           → static HTML<br>  - Footer                  → static HTML</pre><p>The customer can see the product, read the description, check the price — all instantly, before any JavaScript loads. Then the interactive pieces layer in progressively.</p><h3>Example 3: A Documentation Site</h3><pre>docs.yourframework.com<br><br>Structure:<br>  - Sidebar navigation      → static HTML<br>  - Page content / API docs → static HTML<br>  - Code blocks             → static HTML<br>  - Search                  → 🏝️ island (full-text search needs JS)<br>  - Copy Button per code block → 🏝️ island (small, per-block)<br>  - Theme Toggle (dark mode) → 🏝️ island (needs JS to switch)<br>  - &quot;Was this helpful?&quot; widget → 🏝️ island (feedback form)</pre><p>Sites like the old Astro docs and many developer documentation portals are built this way. The content renders instantly. The search box hydrates right away. The theme toggle can wait.</p><h3>Building a Simple Island Yourself</h3><p>You don’t need Astro to understand the concept. Here’s the idea in plain JavaScript to make it tangible.</p><h3>The static HTML (what the server sends):</h3><p>html</p><pre>&lt;!-- index.html — sent from server, renders instantly --&gt;<br>&lt;article&gt;<br>  &lt;h1&gt;My Blog Post&lt;/h1&gt;<br>  &lt;p&gt;A long article with lots of text...&lt;/p&gt;<br><br>&lt;!-- Island placeholder - empty shell --&gt;<br>  &lt;div id=&quot;like-button-island&quot; data-post-id=&quot;123&quot;&gt;<br>    &lt;!-- Will be filled by JavaScript --&gt;<br>    &lt;button disabled&gt;❤️ Like&lt;/button&gt;<br>  &lt;/div&gt;<br>  &lt;p&gt;More article content...&lt;/p&gt;<br>&lt;/article&gt;</pre><h3>The island JavaScript (loaded separately):</h3><p>javascript</p><pre>// like-button.js — only loaded for this one component<br>const island = document.getElementById(&#39;like-button-island&#39;)<br>const postId = island.dataset.postId<br>async function handleLike() {<br>  const response = await fetch(`/api/posts/${postId}/like`, {<br>    method: &#39;POST&#39;<br>  })<br>  const data = await response.json()<br>  island.innerHTML = `&lt;button&gt;❤️ ${data.likes} likes&lt;/button&gt;`<br>}<br>// Replace the disabled button with the real interactive one<br>island.innerHTML = `<br>  &lt;button onclick=&quot;handleLike()&quot;&gt;❤️ Like this post&lt;/button&gt;</pre><h3>The result:</h3><ul><li>The article loads instantly (pure HTML)</li><li>The like button activates after like-button.js downloads</li><li>If JavaScript is slow or fails, the user still sees the article just fine</li></ul><p>This is the essence of progressive enhancement — content first, interactivity layered on top.</p><h3>How Islands Compares to the Alternatives</h3><pre>Server-Only HTML   Full SPA      Islands Architecture<br>                    ─────────────────  ──────────    ────────────────────<br>Initial load speed  ✅ Very fast       ❌ Slow       ✅ Very fast<br>Interactivity       ❌ Limited         ✅ Full        ✅ Where needed<br>JavaScript sent     ✅ Minimal         ❌ All of it  ✅ Only islands<br>SEO                 ✅ Excellent       ⚠️ Depends    ✅ Excellent<br>Developer experience ⚠️ Limited        ✅ Great      ✅ Great<br>Best for            Simple sites      Apps           Content + some interactivity</pre><h3>When Islands Architecture Is the Right Choice</h3><h3>Use it for:</h3><p><strong>Blogs and editorial sites</strong> — The content is text and images. Maybe 5% of the page is interactive (comments, reactions, share buttons). Islands are a perfect fit.</p><p><strong>Marketing and landing pages</strong> — Hero text, pricing tables, testimonials are all static. A contact form, an interactive pricing calculator, or a video player are islands.</p><p><strong>Documentation sites</strong> — Docs are essentially books on the web. Static content with a search box, a copy button, and a theme toggle. Classic Islands territory.</p><p><strong>E-commerce product pages</strong> — The product info is static. The cart, variant picker, and reviews filter are islands.</p><p><strong>News sites</strong> — Articles are static. Live score widgets, weather, breaking news tickers — islands.</p><h3>Skip it when:</h3><p><strong>Your entire page is a dynamic application.</strong> If you’re building a Figma, a Notion, a Trello, or any kind of dashboard where every panel updates, every action triggers UI changes, and nothing is ever just “text that stays still” — Islands won’t give you much benefit. A client-heavy framework (Next.js App Router with client components, Remix, or a pure React SPA) is a better fit.</p><p><strong>Everything is user-specific.</strong> If nothing on your page is the same between users (a personalized dashboard, an inbox, a real-time editor), the “static sea” part of Islands doesn’t exist. There’s no sea, only islands — so you’ve just got an app.</p><p><strong>A rough rule of thumb:</strong></p><pre>Static content &gt; 60% of page?  →  Think Islands<br>Interactive content &gt; 60%?      →  Think SPA / App</pre><h3>The Performance Numbers That Make This Worth It</h3><p>Here’s why teams care about Islands enough to rearchitect sites around it:</p><p><strong>JavaScript bundle size</strong> — Moving from a full SPA to Islands can cut your JavaScript payload by 60–90% for content-heavy pages. Less JavaScript means less download time, less parse time, less execution time.</p><p><strong>Time to First Contentful Paint (FCP)</strong> — Because the HTML arrives from the server already complete, users see real content almost instantly — not a loading spinner waiting for JavaScript to boot.</p><p><strong>Time to Interactive (TTI)</strong> — With less JavaScript to execute, the page becomes fully interactive much sooner. On a slow mobile connection, this can be the difference between a 2-second TTI and a 9-second one.</p><p><strong>Core Web Vitals</strong> — Google’s ranking signals (LCP, FID, CLS) all improve when you send less JavaScript and more pre-rendered HTML. Islands Architecture is one of the most direct paths to excellent Core Web Vitals scores.</p><p><strong>Real-world example:</strong> When the Astro documentation site was rebuilt using Islands Architecture, their Lighthouse performance score went from the 70s to consistently hitting 98–100.</p><h3>Frameworks That Use This Pattern</h3><p><strong>Astro</strong> — The framework that popularized Islands Architecture. You can mix React, Vue, Svelte, Solid, or plain JS components as islands on the same page.</p><p><strong>Fresh</strong> (Deno) — Built on the Islands concept from the ground up. Islands are isolated by default; everything else is server-rendered.</p><p><strong>Marko</strong> — An older framework from eBay that pioneered similar ideas under different terminology before “Islands” became the standard term.</p><p><strong>Qwik</strong> — Takes the idea further with “resumability” — instead of hydrating islands on load, it defers JavaScript execution until the user actually interacts with a component.</p><p>You’ll also see Island-like patterns emerging in Next.js with React Server Components — where components are server-only by default, and you opt into client behavior with &#39;use client&#39;.</p><h3>The Mental Model to Keep</h3><p>Every time you design a page or feature, run this check:</p><pre>Step 1: Draw your page layout on paper (or in your head).<br><br>Step 2: Go through each section and ask:<br>        &quot;Does this section need to respond to user input?&quot;<br>        &quot;Does this section need to make API calls?&quot;<br>        &quot;Does this section need to update without a page reload?&quot;<br>Step 3: If the answer to all three is NO → static HTML<br>        If the answer to any is YES   → island</pre><p>Then count your islands. If your page has 2 islands and 10 static sections — Islands Architecture will give you a dramatic performance win. If your page has 10 islands and 2 static sections — you’re probably better off with a regular React/Next.js setup.</p><h3>The Analogy That Makes It Stick</h3><p>Think of your web page like a hotel at night.</p><p>A <strong>full SPA</strong> turns on every light in the entire building the moment anyone walks in — the lobby, every room, every floor, the rooftop — whether guests are there or not.</p><p><strong>Islands Architecture</strong> only turns on the lights in the rooms that actually have guests. The rest of the building stays in the dark (but it’s all there, fully built, you just can’t interact with it).</p><p>Less electricity. Same building. Same guest experience — actually better, because they’re not waiting for the whole building to power up before they can use their room.</p><h3>What to Explore Next</h3><ul><li><strong>Try Astro</strong> — Build a simple blog with one or two interactive islands. The client:load / client:visible directives are immediately satisfying to work with.</li><li><strong>Read about React Server Components</strong> — Next.js 13+ implements a similar philosophy: components are server-only by default, client behavior is opt-in.</li><li><strong>Look into Core Web Vitals</strong> — Understanding LCP, FID, and CLS will make you viscerally understand <em>why</em> sending less JavaScript matters.</li><li><strong>Inspect the sites you use</strong> — Open DevTools on any blog or news site and look at the JavaScript bundle size. Then open a web app like Figma or Notion. The difference will make Islands Architecture feel immediately practical.</li></ul><p><strong><em>The best architecture decisions aren’t about using the newest tool — they’re about matching the right tool to the shape of the problem. Islands Architecture is one of the clearest examples of that principle in modern web development.</em></strong></p><p><em>Found this helpful? Follow me for more content on navigating the modern tech job market.</em></p><p>If you feel like you missed any concept, don’t hesitate to reach out — your feedback means a lot to me! 🌹. You can also connect with me on 🌹</p><p><a href="https://x.com/Noransaber11">Twitter </a>| <a href="https://www.linkedin.com/in/noran-saber-abdelfattah-6198471ba/">LinkedIn </a>| <a href="https://github.com/Noransaber">GitHub</a><br> — Noran 🌹</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc3cd9b08f23" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/islands-architecture-the-idea-that-changes-how-you-think-about-web-performance-fc3cd9b08f23">Islands Architecture: The Idea That Changes How You Think About Web Performance</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Islands Architecture: The Idea That Changes How You Think About Web Performance]]></title>
            <link>https://medium.com/@noransaber685/islands-architecture-the-idea-that-changes-how-you-think-about-web-performance-2e6b0097ca25?source=rss-f9117bc94016------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e6b0097ca25</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[performance]]></category>
            <dc:creator><![CDATA[Noran Saber Abdelfattah]]></dc:creator>
            <pubDate>Tue, 26 May 2026 22:07:03 GMT</pubDate>
            <atom:updated>2026-05-26T22:07:03.875Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H3ZPJG4lLb7240gyofzQ5g.png" /></figure><p><em>Once you understand Islands Architecture, you’ll start seeing it everywhere — in the sites you visit, in the frameworks you use, and in every performance decision you make.</em></p><p>This isn’t about a specific framework or a new tool you need to learn. It’s a mental model for how you organize rendering on a page. Once it clicks, it’ll influence how you think about every web project you build.</p><p>Let’s build it from scratch.</p><h3>The One-Sentence Version</h3><p><strong>Islands Architecture = most of your page is static HTML, with small isolated interactive components scattered through it.</strong></p><pre>static page + isolated interactive components</pre><p>Those interactive components are the “<strong>islands</strong>.” They sit inside a sea of plain HTML — alive and interactive while everything around them is just markup.</p><p>That’s literally where the name comes from.</p><pre>🌊 HTML  🌊 HTML  🌊 HTML<br>🌊 HTML  🌊 HTML  🌊 HTML<br>🏝️ [ Search Box ]<br>🌊 HTML  🌊 HTML  🌊 HTML<br>        🏝️ [ Like Button ]<br>🌊 HTML  🌊 HTML  🌊 HTML</pre><h3>What a Page Actually Looks Like</h3><p>Imagine a typical blog article page:</p><pre>──────────────────────────────────────<br>  Header                  (static)<br>  Hero / Intro            (static)<br>  Article Content         (static)<br>  Images                  (static)<br></pre><pre>[ Newsletter Form ] (interactive ← island)</pre><pre>  Related Articles        (static)</pre><pre>      [ Like Button ]     (interactive ← island)</pre><pre>  Footer                  (static)<br>──────────────────────────────────────</pre><p><strong>Two interactive </strong>components out of eight sections. The rest is just HTML.</p><p>Now ask yourself: why would you ship a full JavaScript application for a page that’s 75% plain text and images?</p><p>That’s the question Islands Architecture was invented to answer.</p><h3>The Problem It Solves: A Short History</h3><p>To really get why this matters, you need to understand what came before.</p><h3>Era 1: Server-Rendered HTML (the old way)</h3><p>Back when the web was simpler, the server did everything. You’d request a page, the server would build the full HTML, and send it back:</p><p>html</p><pre>&lt;!-- Server sends this complete HTML --&gt;<br>&lt;h1&gt;My Blog Post&lt;/h1&gt;<br>&lt;p&gt;Here&#39;s the article content...&lt;/p&gt;<br>&lt;img src=&quot;photo.jpg&quot; alt=&quot;photo&quot; /&gt;<br>&lt;footer&gt;© 2024&lt;/footer&gt;</pre><p>The browser receives real content immediately. Pages loaded fast. But they weren’t very interactive — every click that needed new data required a full page reload.</p><h3>Era 2: Single Page Applications (SPAs)</h3><p>Then came React, Vue, Angular. The SPA era. Now the server sends almost nothing:</p><p>html</p><pre>&lt;!-- Server sends just this --&gt;<br>&lt;div id=&quot;root&quot;&gt;&lt;/div&gt;</pre><p>And JavaScript builds the entire page in the browser — every heading, paragraph, button, image. Everything.</p><p>This made apps incredibly dynamic and interactive. But it introduced a serious problem.</p><h3>The Problem: JavaScript Bloat</h3><p>Let’s say you have a blog post page with:</p><ul><li>A title</li><li>1,200 words of article text</li><li>5 images</li><li>A footer</li><li><strong>One Like button</strong></li></ul><p>With a full SPA, you might ship <strong>200KB–400KB of JavaScript</strong> to the user’s browser just to make that one Like button work.</p><p>The title doesn’t need JavaScript. The article text doesn’t need JavaScript. The images definitely don’t need JavaScript. But the SPA hydrates (makes interactive) the entire page anyway — because that’s how it’s built.</p><p>Islands Architecture looks at this and says: <strong>why are we doing this?</strong></p><blockquote><em>💡 Turn on the lights only in the rooms where people actually are — not the entire building.</em></blockquote><h3>The Core Concept: Hydration</h3><p>Before we go further, you need to understand <strong>hydration</strong>, because it’s central to how Islands work.</p><h3>What hydration means</h3><p>When a server renders HTML and sends it to the browser, the page <em>looks</em> correct — but nothing is wired up yet. The buttons don’t respond. The forms don’t submit. It’s like a beautiful stage set with no electricity.</p><p><strong>Hydration</strong> is the process of attaching JavaScript to that HTML so it becomes interactive.</p><pre>Before hydration:</pre><pre>&lt;button&gt;Like ❤️&lt;/button&gt;<br>↑ renders, looks fine, but clicking does nothing</pre><pre>After hydration:<br>&lt;button onClick={handleLike}&gt;Like ❤️&lt;/button&gt;<br>↑ now it actually works</pre><p>In a traditional SPA, hydration happens for the <strong>entire page</strong> — every component, every element, even the ones that don’t need it.</p><p>Islands Architecture says: <strong>only hydrate the parts that actually need to be interactive.</strong></p><pre>Full SPA hydration:<br>┌──────────────────────────────────┐<br>│  💧 Header                       │<br>│  💧 Hero                         │<br>│  💧 Article                      │<br>│  💧 Newsletter Form              │ ← only this actually needs JS<br>│  💧 Related Posts                │<br>│  💧 Like Button                  │ ← and this<br>│  💧 Footer                       │<br>└──────────────────────────────────┘<br>Hydrating: everything. JS shipped: 380KB.</pre><pre>Islands hydration:<br>┌──────────────────────────────────┐<br>│     Header                       │<br>│     Hero                         │<br>│     Article                      │<br>│  🏝️ Newsletter Form              │ ← hydrated<br>│     Related Posts                │<br>│  🏝️ Like Button                  │ ← hydrated<br>│     Footer                       │<br>└──────────────────────────────────┘<br>Hydrating: 2 components. JS shipped: 18KB.</pre><p>That difference in JavaScript shipped directly translates to faster pages, especially on mobile devices and slower connections.</p><h3>What Islands Look Like in Code</h3><p>The framework most associated with Islands Architecture is <strong>Astro</strong>. Here’s what a page might look like:</p><p>astro</p><pre>---<br>// This runs on the server. No JS sent to the browser.<br>import Header from &#39;./Header.astro&#39;<br>import ArticleContent from &#39;./ArticleContent.astro&#39;<br>import Footer from &#39;./Footer.astro&#39;<br>// These are interactive components<br>import LikeButton from &#39;./LikeButton.jsx&#39;<br>import NewsletterForm from &#39;./NewsletterForm.jsx&#39;<br>import SearchBox from &#39;./SearchBox.jsx&#39;<br>---<br>&lt;!-- Static components - zero JavaScript --&gt;<br>&lt;Header /&gt;<br>&lt;ArticleContent /&gt;<br>&lt;!-- Islands - JavaScript loaded and hydrated --&gt;<br>&lt;LikeButton client:load /&gt;<br>&lt;NewsletterForm client:visible /&gt;<br>&lt;SearchBox client:idle /&gt;<br>&lt;Footer /&gt;</pre><p>Notice the client: directives. These tell Astro <em>when</em> and <em>how</em> to hydrate each island:</p><p>Directive When it <strong>hydrates </strong>Best forclient:loadImmediately on page load Critical interactive elements (search, cart)client:idleWhen the browser is idleNon-urgent UI (theme toggle, share buttons)client:visibleWhen element scrolls into viewBelow-the-fold content (comments, newsletter)client:mediaWhen a CSS media query matchesMobile-only or responsive components</p><p>This granularity is powerful. You can say “load this search box immediately” but “wait until the user scrolls down to load the comments section.” That’s a level of control that traditional SPAs don’t give you.</p><h3>Real-World Examples</h3><h3>Example 1: A Blog Post Page</h3><pre>/blog/how-to-learn-react<br>Structure:<br>  - Blog post title         → static HTML<br>  - Author info             → static HTML<br>  - Article body (2000 words) → static HTML<br>  - Code blocks             → static HTML + CSS<br>  - Copy Code Button        → 🏝️ island (tiny JS to copy to clipboard)<br>  - Like / Bookmark         → 🏝️ island (JS to call API)<br>  - Comments Section        → 🏝️ island (loads when scrolled to)<br>  - Related Articles        → static HTML<br>  - Footer                  → static HTML<br>JavaScript sent: ~22KB (just for the 3 islands)<br>Instead of: ~350KB (for the full SPA version)</pre><h3>Example 2: An E-commerce Product Page</h3><pre>/products/nike-air-max</pre><pre>Structure:<br>  - Product images gallery  → static HTML (maybe with CSS lightbox)<br>  - Product title + brand   → static HTML<br>  - Description             → static HTML<br>  - Size guide              → static HTML<br>  - Color/Size Picker       → 🏝️ island (needs JS to update selection)<br>  - Add to Cart Button      → 🏝️ island (needs JS to call cart API)<br>  - Reviews Filter &amp; Sort   → 🏝️ island (needs JS to re-sort)<br>  - Stock Countdown Timer   → 🏝️ island (real-time countdown)<br>  - Shipping info           → static HTML<br>  - Footer                  → static HTML</pre><p>The customer can see the product, read the description, check the price — all instantly, before any JavaScript loads. Then the interactive pieces layer in progressively.</p><h3>Example 3: A Documentation Site</h3><pre>docs.yourframework.com</pre><pre>Structure:<br>  - Sidebar navigation      → static HTML<br>  - Page content / API docs → static HTML<br>  - Code blocks             → static HTML<br>  - Search                  → 🏝️ island (full-text search needs JS)<br>  - Copy Button per code block → 🏝️ island (small, per-block)<br>  - Theme Toggle (dark mode) → 🏝️ island (needs JS to switch)<br>  - &quot;Was this helpful?&quot; widget → 🏝️ island (feedback form)</pre><p>Sites like the old Astro docs and many developer documentation portals are built this way. The content renders instantly. The search box hydrates right away. The theme toggle can wait.</p><h3>Building a Simple Island Yourself</h3><p>You don’t need Astro to understand the concept. Here’s the idea in plain JavaScript to make it tangible.</p><h3>The static HTML (what the server sends):</h3><p>html</p><pre>&lt;!-- index.html — sent from server, renders instantly --&gt;<br>&lt;article&gt;<br>  &lt;h1&gt;My Blog Post&lt;/h1&gt;<br>  &lt;p&gt;A long article with lots of text...&lt;/p&gt;</pre><pre>&lt;!-- Island placeholder - empty shell --&gt;<br>  &lt;div id=&quot;like-button-island&quot; data-post-id=&quot;123&quot;&gt;<br>    &lt;!-- Will be filled by JavaScript --&gt;<br>    &lt;button disabled&gt;❤️ Like&lt;/button&gt;<br>  &lt;/div&gt;<br>  &lt;p&gt;More article content...&lt;/p&gt;<br>&lt;/article&gt;</pre><h3>The island JavaScript (loaded separately):</h3><p>javascript</p><pre>// like-button.js — only loaded for this one component<br>const island = document.getElementById(&#39;like-button-island&#39;)<br>const postId = island.dataset.postId<br>async function handleLike() {<br>  const response = await fetch(`/api/posts/${postId}/like`, {<br>    method: &#39;POST&#39;<br>  })<br>  const data = await response.json()<br>  island.innerHTML = `&lt;button&gt;❤️ ${data.likes} likes&lt;/button&gt;`<br>}<br>// Replace the disabled button with the real interactive one<br>island.innerHTML = `<br>  &lt;button onclick=&quot;handleLike()&quot;&gt;❤️ Like this post&lt;/button&gt;</pre><h3>The result:</h3><ul><li>The article loads instantly (pure HTML)</li><li>The like button activates after like-button.js downloads</li><li>If JavaScript is slow or fails, the user still sees the article just fine</li></ul><p>This is the essence of progressive enhancement — content first, interactivity layered on top.</p><h3>How Islands Compares to the Alternatives</h3><pre>Server-Only HTML   Full SPA      Islands Architecture<br>                    ─────────────────  ──────────    ────────────────────<br>Initial load speed  ✅ Very fast       ❌ Slow       ✅ Very fast<br>Interactivity       ❌ Limited         ✅ Full        ✅ Where needed<br>JavaScript sent     ✅ Minimal         ❌ All of it  ✅ Only islands<br>SEO                 ✅ Excellent       ⚠️ Depends    ✅ Excellent<br>Developer experience ⚠️ Limited        ✅ Great      ✅ Great<br>Best for            Simple sites      Apps           Content + some interactivity</pre><h3>When Islands Architecture Is the Right Choice</h3><h3>Use it for:</h3><p><strong>Blogs and editorial sites</strong> — The content is text and images. Maybe 5% of the page is interactive (comments, reactions, share buttons). Islands are a perfect fit.</p><p><strong>Marketing and landing pages</strong> — Hero text, pricing tables, testimonials are all static. A contact form, an interactive pricing calculator, or a video player are islands.</p><p><strong>Documentation sites</strong> — Docs are essentially books on the web. Static content with a search box, a copy button, and a theme toggle. Classic Islands territory.</p><p><strong>E-commerce product pages</strong> — The product info is static. The cart, variant picker, and reviews filter are islands.</p><p><strong>News sites</strong> — Articles are static. Live score widgets, weather, breaking news tickers — islands.</p><h3>Skip it when:</h3><p><strong>Your entire page is a dynamic application.</strong> If you’re building a Figma, a Notion, a Trello, or any kind of dashboard where every panel updates, every action triggers UI changes, and nothing is ever just “text that stays still” — Islands won’t give you much benefit. A client-heavy framework (Next.js App Router with client components, Remix, or a pure React SPA) is a better fit.</p><p><strong>Everything is user-specific.</strong> If nothing on your page is the same between users (a personalized dashboard, an inbox, a real-time editor), the “static sea” part of Islands doesn’t exist. There’s no sea, only islands — so you’ve just got an app.</p><p><strong>A rough rule of thumb:</strong></p><pre>Static content &gt; 60% of page?  →  Think Islands<br>Interactive content &gt; 60%?      →  Think SPA / App</pre><h3>The Performance Numbers That Make This Worth It</h3><p>Here’s why teams care about Islands enough to rearchitect sites around it:</p><p><strong>JavaScript bundle size</strong> — Moving from a full SPA to Islands can cut your JavaScript payload by 60–90% for content-heavy pages. Less JavaScript means less download time, less parse time, less execution time.</p><p><strong>Time to First Contentful Paint (FCP)</strong> — Because the HTML arrives from the server already complete, users see real content almost instantly — not a loading spinner waiting for JavaScript to boot.</p><p><strong>Time to Interactive (TTI)</strong> — With less JavaScript to execute, the page becomes fully interactive much sooner. On a slow mobile connection, this can be the difference between a 2-second TTI and a 9-second one.</p><p><strong>Core Web Vitals</strong> — Google’s ranking signals (LCP, FID, CLS) all improve when you send less JavaScript and more pre-rendered HTML. Islands Architecture is one of the most direct paths to excellent Core Web Vitals scores.</p><p><strong>Real-world example:</strong> When the Astro documentation site was rebuilt using Islands Architecture, their Lighthouse performance score went from the 70s to consistently hitting 98–100.</p><h3>Frameworks That Use This Pattern</h3><p><strong>Astro</strong> — The framework that popularized Islands Architecture. You can mix React, Vue, Svelte, Solid, or plain JS components as islands on the same page.</p><p><strong>Fresh</strong> (Deno) — Built on the Islands concept from the ground up. Islands are isolated by default; everything else is server-rendered.</p><p><strong>Marko</strong> — An older framework from eBay that pioneered similar ideas under different terminology before “Islands” became the standard term.</p><p><strong>Qwik</strong> — Takes the idea further with “resumability” — instead of hydrating islands on load, it defers JavaScript execution until the user actually interacts with a component.</p><p>You’ll also see Island-like patterns emerging in Next.js with React Server Components — where components are server-only by default, and you opt into client behavior with &#39;use client&#39;.</p><h3>The Mental Model to Keep</h3><p>Every time you design a page or feature, run this check:</p><pre>Step 1: Draw your page layout on paper (or in your head).</pre><pre>Step 2: Go through each section and ask:<br>        &quot;Does this section need to respond to user input?&quot;<br>        &quot;Does this section need to make API calls?&quot;<br>        &quot;Does this section need to update without a page reload?&quot;<br>Step 3: If the answer to all three is NO → static HTML<br>        If the answer to any is YES   → island</pre><p>Then count your islands. If your page has 2 islands and 10 static sections — Islands Architecture will give you a dramatic performance win. If your page has 10 islands and 2 static sections — you’re probably better off with a regular React/Next.js setup.</p><h3>The Analogy That Makes It Stick</h3><p>Think of your web page like a hotel at night.</p><p>A <strong>full SPA</strong> turns on every light in the entire building the moment anyone walks in — the lobby, every room, every floor, the rooftop — whether guests are there or not.</p><p><strong>Islands Architecture</strong> only turns on the lights in the rooms that actually have guests. The rest of the building stays in the dark (but it’s all there, fully built, you just can’t interact with it).</p><p>Less electricity. Same building. Same guest experience — actually better, because they’re not waiting for the whole building to power up before they can use their room.</p><h3>What to Explore Next</h3><ul><li><strong>Try Astro</strong> — Build a simple blog with one or two interactive islands. The client:load / client:visible directives are immediately satisfying to work with.</li><li><strong>Read about React Server Components</strong> — Next.js 13+ implements a similar philosophy: components are server-only by default, client behavior is opt-in.</li><li><strong>Look into Core Web Vitals</strong> — Understanding LCP, FID, and CLS will make you viscerally understand <em>why</em> sending less JavaScript matters.</li><li><strong>Inspect the sites you use</strong> — Open DevTools on any blog or news site and look at the JavaScript bundle size. Then open a web app like Figma or Notion. The difference will make Islands Architecture feel immediately practical.</li></ul><p><strong><em>The best architecture decisions aren’t about using the newest tool — they’re about matching the right tool to the shape of the problem. Islands Architecture is one of the clearest examples of that principle in modern web development.</em></strong></p><p><em>Found this helpful? Follow me for more content on navigating the modern tech job market.</em></p><p>If you feel like you missed any concept, don’t hesitate to reach out — your feedback means a lot to me! 🌹. You can also connect with me on 🌹</p><p><a href="https://x.com/Noransaber11">Twitter </a>| <a href="https://www.linkedin.com/in/noran-saber-abdelfattah-6198471ba/">LinkedIn </a>| <a href="https://github.com/Noransaber">GitHub</a><br> — Noran 🌹</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e6b0097ca25" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Ace an AI Interview: The Complete Playbook for Tech Professionals]]></title>
            <link>https://ai.plainenglish.io/how-to-ace-an-ai-interview-the-complete-playbook-for-tech-professionals-a97eb0810dc6?source=rss-f9117bc94016------2</link>
            <guid isPermaLink="false">https://medium.com/p/a97eb0810dc6</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[interview]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[generative-ai-tools]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Noran Saber Abdelfattah]]></dc:creator>
            <pubDate>Sat, 23 May 2026 10:43:52 GMT</pubDate>
            <atom:updated>2026-05-23T10:52:13.476Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bqWWz7wSK5gcY-6Lu1TFGg.png" /></figure><p><em>You studied the algorithms. You practiced LeetCode. But now you’re staring down an AI interviewer — and the rules have changed.</em></p><p>AI-powered interviews are becoming the new normal in tech hiring. Whether it’s a fully automated screening round or an AI co-pilot scoring your answers alongside a human, one thing is clear: the way you communicate matters just as much as what you actually know.</p><p>Here’s everything I learned about cracking the AI interview — broken down by question type, with tactical tips you can use right away.</p><h3>1. The 30-Second “Introduce Yourself” Formula</h3><p>This is the question everyone underestimates. It sounds simple, but it’s your first impression — and AI systems are trained to evaluate structure, clarity, and relevance from the very first sentence.</p><p>Here’s the formula that works:</p><p><strong>Step 1 — Say exactly who you are professionally.</strong> Not your life story. One clear sentence: your role, your domain, your years of experience. <em>“I’m a backend engineer with five years of experience building distributed systems at scale.”</em></p><p><strong>Step 2 — Share your single strongest skill or achievement.</strong> Pick one. The AI is looking for signal, not a resume dump. <em>“My main strength is designing APIs that reduce latency — I cut response times by 40% at my last company.”</em></p><p><strong>Step 3 — Explain why you’re here for this specific job.</strong> Connect the dots between your background and this role. Generic answers like “I’m passionate about technology” are invisible to AI scoring. Specificity wins. <em>“I’m applying because your team is working on real-time data pipelines, which is exactly where I’ve spent the last three years.”</em></p><p>Three sentences. Tight. Relevant. Done.</p><h3>2. Technical Questions: Quality Over Quantity</h3><p>One of the most common mistakes in technical interviews — AI or human — is listing every tool you’ve ever touched:</p><blockquote>“I know Python, Java, React, Node.js, Kubernetes, Terraform, Docker, Kafka, Redis, Spark…”</blockquote><p>AI interviewers don’t reward long lists. They reward depth. When you rattle off 15 technologies without explanation, you’re giving the system nothing concrete to evaluate.</p><p><strong>The better approach:</strong> Pick one or two tools and explain <em>how</em> you use them.</p><p>Instead of: <em>“I use Kafka for messaging.”</em></p><p>Say: <em>“I use Kafka as the backbone of our event-driven architecture. Specifically, I design topics around domain events and use consumer groups to horizontally scale processing — this lets us handle around 200,000 events per second without bottlenecking the downstream services.”</em></p><p>That answer tells the AI: you understand the tool, you’ve applied it in a real context, and you know the <em>why</em> behind your decisions. That’s what gets you to the next round.</p><h3>3. Problem-Solving Questions: Show Your Logic, Not Just the Answer</h3><p>When AI evaluates your problem-solving, it’s not just looking for the correct answer. It’s analyzing your reasoning process — specifically whether you think in clear, structured steps.</p><p>Here’s the three-part structure to follow:</p><p><strong>1. Define the problem.</strong> Restate it in your own words. This shows you understand the scope before jumping to solutions. <em>“So the core issue is that our deployment pipeline is causing 15-minute downtime windows, which is unacceptable for a 24/7 service.”</em></p><p><strong>2. Walk through your solution step by step.</strong> Use signpost words: <em>first, next, then, finally</em>. These signal structure to both AI and human listeners. <em>“First, I’d set up a blue-green deployment to eliminate downtime. Next, I’d add automated smoke tests to validate the new environment before switching traffic. Then, I’d implement a rollback trigger if error rates spike within the first five minutes.”</em></p><p><strong>3. Explain how you’ll measure success.</strong> This is the step most candidates skip — and it’s the one that separates good answers from great ones. It shows you’re not just fixing problems, you’re making sure they <em>stay</em> fixed. <em>“I’d measure success by tracking deployment-related incidents over the next 30 days and confirming downtime drops to under 30 seconds per release.”</em></p><p><strong>Problem → Steps → Metric. Every time.</strong></p><h3>4. Communication &amp; Teamwork Questions: The Non-Technical Test</h3><p>This type of question often involves a scenario like:</p><p><em>“Explain how a recommendation system works to a marketing manager.”</em></p><p>It sounds random, but the purpose is deliberate: AI is measuring whether you can translate complex concepts into business language for non-technical stakeholders. In real jobs, this skill is priceless.</p><p>The trap most engineers fall into: explaining the algorithm. The ML model, the collaborative filtering, the vector embeddings. That’s the wrong frame.</p><p><strong>What the AI wants to see:</strong> Focus on what the technology <em>does for the business or the user.</em></p><p>Good answer: <em>“A recommendation system looks at what similar users have liked in the past and uses that to predict what a specific user is most likely to engage with next. For a marketing manager, think of it as an automated way to show each customer the most relevant product at the right moment — which increases click-through rates and reduces the cost of generic, untargeted campaigns.”</em></p><p>No jargon. Real-world results. Business language. That’s the winning formula.</p><h3>5. Motivation &amp; Personality Fit: Be Specific, Be Genuine</h3><p>When asked about your motivations or opinions on big topics — like <em>“What are the risks of AI in healthcare?”</em> — vague answers will hurt you.</p><p>AI scoring systems flag answers that are too broad or too safe. Don’t say: <em>“AI has many risks and also many benefits.”</em> That’s filler.</p><p>Instead, pick a specific angle and own it. For healthcare AI, for instance:</p><ul><li><strong>Data privacy</strong> — patient data is among the most sensitive data that exists, and AI models trained on it create real exposure if not properly governed.</li><li><strong>Safety and validation</strong> — unlike a consumer app, a wrong prediction in a clinical setting can have life-or-death consequences. Models need rigorous validation pipelines before deployment.</li></ul><p>Naming concrete dimensions shows you’ve actually thought about the topic. It also makes your answer memorable — AI scoring rewards specificity.</p><h3>6. The Universal Answer Framework: Situation → Action → Result</h3><p>Regardless of question type, the highest-scoring answers follow a simple structure:</p><ul><li><strong>Situation</strong>: Set the context. What was the problem or challenge?</li><li><strong>Action</strong>: What did <em>you specifically</em> do to address it?</li><li><strong>Result</strong>: What happened? Quantify it if you can.</li></ul><p><em>“Our data ingestion pipeline was dropping roughly 5% of events during peak hours (Situation). I profiled the bottleneck, identified that our single-threaded consumer was the culprit, and refactored it into a multi-threaded implementation with a bounded queue (Action). After the fix, we saw zero event loss across the next 30 days and processed 3x the previous peak volume (Result).”</em></p><p>Notice the number: <em>3x.</em> AI systems are trained to look for quantified business outcomes. If you improved something, say by how much. If you reduced something, say the percentage. If you built something, mention the scale.</p><blockquote><em>A vague answer will prompt follow-up questions. If you say </em>“I use Excel for data analysis,”<em> the AI will ask: </em>“Which functions? What method?”<em> Be specific upfront and save everyone the time.</em></blockquote><h3>7. Time Management: The 2.5-Minute Rule</h3><p>Here’s something most people don’t know: <strong>if your answer runs past about 2.5 minutes, AI systems start losing scoring confidence.</strong></p><p>They’re optimized to capture structured, focused responses — not monologues. Long answers tend to drift, and drift hurts your score.</p><p>The fix is discipline:</p><ul><li>Use your structure (Situation → Action → Result) to stay on track.</li><li>Lead with the most important point, not background context.</li><li>Use numbers to compress information. <em>“Reduced latency by 60%”</em> says more in five words than a two-minute explanation.</li></ul><h3>8. Handling Questions You Don’t Understand</h3><p>Don’t panic. Don’t guess. Don’t stay silent.</p><p>The right move is to pause and ask for clarification — genuinely and without apology:</p><blockquote>“Could you please clarify that question? I want to make sure I’m answering what you’re actually asking.”</blockquote><p>This is not a weakness. It’s a communication signal. In a real team environment, asking for clarity before diving into a solution is exactly what senior engineers are supposed to do.</p><h3>9. The Silence Trap (And How to Escape It)</h3><p>Here’s a quirk of AI interview systems that catches a lot of people off guard: <strong>silence reads as hesitation or disengagement.</strong></p><p>If the AI asks a question and you sit quietly for several seconds thinking, some systems will interpret it as a non-answer and move on — before you’ve even started.</p><p>The fix is simple: <strong>speak to pause.</strong></p><p>Instead of silence, say:</p><ul><li><em>“Let me take a moment to think through that.”</em></li><li><em>“That’s a great question — give me a second to structure my answer.”</em></li><li><em>“Can you rephrase that slightly? I want to make sure I’m addressing the right thing.”</em></li></ul><p>Talking while you think — even briefly — keeps the AI engaged and shows self-awareness.</p><h3>10. Body Language Still Matters</h3><p>Even in a fully AI-powered video interview, your physical presence is being analyzed. Here’s what the system is actually watching for:</p><ul><li><strong>Eye contact with the camera</strong> — not the screen. This reads as direct, confident communication.</li><li><strong>Posture</strong> — sitting upright signals engagement and professionalism.</li><li><strong>Natural smiling</strong> — forced smiles read as anxiety; genuine ones read as confidence.</li><li><strong>Calm hand movements</strong> — expressive but controlled gestures signal engagement; excessive fidgeting signals nervousness.</li></ul><p>It sounds simple, but these nonverbal signals make up a meaningful portion of your overall score. Set up your environment well: good lighting, camera at eye level, minimal background distractions.</p><h3>The Short Version</h3><p>If you take nothing else from this article, take this:</p><ul><li><strong>Be structured.</strong> Every answer should have a clear beginning, middle, and end.</li><li><strong>Be specific.</strong> Numbers, tool names, real outcomes — they all beat vague generalities.</li><li><strong>Be concise.</strong> Under 2.5 minutes, every time.</li><li><strong>Never go silent.</strong> Speak to pause if you need time to think.</li><li><strong>Mirror the job description.</strong> Use the keywords from the role you’re applying for — they matter more than you think.</li></ul><p>AI interviews aren’t about tricking a machine. They’re about communicating clearly, thinking in structured steps, and showing the value you bring — just with a different audience on the other end of the camera.</p><p>Go nail it.</p><p><em>Found this helpful? Follow me for more content on navigating the modern tech job market.</em></p><h3>If you feel like you missed any concept, don’t hesitate to reach out — your feedback means a lot to me! ❤️. You can also connect with me on 🌹</h3><h3><a href="https://x.com/Noransaber11">Twitter </a>| <a href="https://www.linkedin.com/in/noran-saber-abdelfattah-6198471ba/">LinkedIn </a>| <a href="https://github.com/Noransaber">GitHub</a><br> — Noran 🌹</h3><h3>A message from our Founder</h3><p>Hey, <a href="https://linkedin.com/in/sunilsandhu">Sunil</a> here. I wanted to take a moment to thank you for reading until the end and for being a part of this community. Did you know that our team run these publications as a volunteer effort to over 3.5m monthly readers? We don’t receive any funding, we do this to support the community.</p><p>If you want to show some love, please take a moment to follow me on <a href="https://linkedin.com/in/sunilsandhu">LinkedIn</a>, <a href="https://tiktok.com/@messyfounder">TikTok</a>, <a href="https://instagram.com/sunilsandhu">Instagram</a>. You can also subscribe to our <a href="https://newsletter.plainenglish.io/">weekly newsletter</a>. And before you go, don’t forget to clap and follow the writer️!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a97eb0810dc6" width="1" height="1" alt=""><hr><p><a href="https://ai.plainenglish.io/how-to-ace-an-ai-interview-the-complete-playbook-for-tech-professionals-a97eb0810dc6">How to Ace an AI Interview: The Complete Playbook for Tech Professionals</a> was originally published in <a href="https://ai.plainenglish.io/">Artificial Intelligence in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Behind the Scenes, useEffect()]]></title>
            <link>https://javascript.plainenglish.io/react-behind-the-scenes-useeffect-c7de7b61d6a8?source=rss-f9117bc94016------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7de7b61d6a8</guid>
            <category><![CDATA[programmer]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[reactive-programming]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Noran Saber Abdelfattah]]></dc:creator>
            <pubDate>Tue, 13 Jan 2026 18:14:57 GMT</pubDate>
            <atom:updated>2026-01-13T18:14:57.570Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7nB72EM2VsFfMPv7_XpOBg.jpeg" /></figure><p>If you’ve just started learning React, there’s a very high chance that <strong>useEffect confused you</strong>.</p><p>You watched a tutorial, copied some code, and suddenly:</p><ul><li>Your API request runs twice</li><li>Your component keeps re-rendering</li><li>Someone tells you, “Just add it to the dependency array,” without explaining <em>why</em></li></ul><p>This usually makes beginners feel like React is “magic” or “too complex”.</p><p>The truth is: <strong>useEffect is not hard at all</strong> — it’s just explained in a way that doesn’t match how beginners think.</p><p>In this article, we’ll explain useEffect <strong>slowly, visually, and in plain English</strong>, with simple code examples and real-life analogies.<br> By the end, you won’t just <em>use</em> useEffect — you’ll actually <strong>understand when and why it runs</strong>.</p><h3>First: Forget React for a Second 🧠</h3><p>Think about <strong>real life</strong>.</p><p>You do <strong>things</strong> in response to <strong>events</strong>:</p><ul><li>You open the fridge → the light turns on</li><li>You click a button → something happens</li><li>You enter a page → data is loaded</li></ul><p>👉 These are called <strong>side effects</strong>.</p><h4>In React:</h4><ul><li>Rendering UI = main job</li><li>Doing <em>extra things</em> = <strong>side effects</strong></li></ul><h4>Examples of side effects:</h4><ul><li>Fetching data from an API</li><li>Adding an event listener</li><li>Updating the document title</li><li>Setting a timer</li></ul><p>That’s <strong>exactly</strong> what useEffect is for.</p><h3>What is useEffect In ONE sentence?</h3><blockquote><strong><em>useEffect lets you run code </em>after<em> React renders the UI.</em></strong></blockquote><p>That’s it. Nothing more.</p><h3>The Basic Shape of useEffect</h3><pre>useEffect(() =&gt; {<br>  // code you want to run<br>}, []);</pre><p>Let’s break it <strong>slowly</strong>.</p><h3>Part 1: The function</h3><pre><br>() =&gt; {<br>  console.log(&quot;Hello from useEffect&quot;);<br>}<br></pre><p>This is <strong>what you want to run</strong>.</p><p>React says:</p><blockquote><em>“I’ll run this function </em><strong><em>after rendering</em></strong><em>.”</em></blockquote><h3>Part 2: The dependency array []</h3><p>This part controls <strong>WHEN</strong> the effect runs.</p><p>Think of it as:</p><blockquote><em>“Hey React, run this effect WHEN these values change.”</em></blockquote><h3>Case 1: Empty dependency array []</h3><pre>useEffect(() =&gt; {<br>  console.log(&quot;Component mounted&quot;);<br>}, []);</pre><h3>What happens?</h3><ul><li>Runs <strong>once</strong></li><li>After the component renders the <strong>first time</strong></li><li>Never again</li></ul><h3>Mental model 🧠</h3><blockquote><em>“Run this when the component appears on the screen.”</em></blockquote><h3>Common use cases:</h3><ul><li>Fetch data</li><li>Set up subscriptions</li><li>Initialize something</li></ul><p>Example:</p><pre>useEffect(() =&gt; {<br>  fetch(&quot;/api/users&quot;)<br>    .then(res =&gt; res.json())<br>    .then(data =&gt; console.log(data));<br>}, []);</pre><h3>Case 2: Dependency array with values</h3><pre>useEffect(() =&gt; {<br>  console.log(&quot;Count changed&quot;);<br>}, [count]);</pre><h3>What happens?</h3><ul><li>Runs on first render</li><li>Runs <strong>again every time </strong><strong>count changes</strong></li></ul><h3>Mental model 🧠</h3><blockquote><em>“React, watch </em><em>count. If it changes, run this.”</em></blockquote><p>Example:</p><pre>const [count, setCount] = useState(0);<br>useEffect(() =&gt; {<br>  document.title = `Count: ${count}`;<br>}, [count]);</pre><p><strong>Now:</strong></p><ul><li>Click button</li><li>count changes</li><li>Effect runs</li><li>Title updates</li></ul><p>Simple ✅</p><h3>Case 3: No dependency array (❌ beginner trap)</h3><pre>useEffect(() =&gt; {<br>  console.log(&quot;Runs every render&quot;);<br>});</pre><h3>What happens?</h3><ul><li>Runs <strong>after every render</strong></li><li>That means: state change → render → effect → state change → render → 💥 infinite loop</li></ul><h3>Rule:</h3><p>🚫 <strong>Avoid this unless you REALLY know why you need it</strong></p><h3>Why does React need useEffect anyway?</h3><p>Because React renders <strong>pure UI</strong>.</p><p><strong>This is BAD:</strong></p><pre>function App() {<br>  fetch(&quot;/api/data&quot;); // ❌ side effect during render<br>  return &lt;div&gt;Hello&lt;/div&gt;;<br>}</pre><p><strong>This is GOOD:</strong></p><pre>function App() {<br>  useEffect(() =&gt; {<br>    fetch(&quot;/api/data&quot;);<br>  }, []);<br>return &lt;div&gt;Hello&lt;/div&gt;;<br>}</pre><p><strong>React likes:</strong></p><ul><li>Render first</li><li>Do side effects occur after</li></ul><h3>Cleanup — Stop Effects Before Leaving</h3><p>Sometimes you start <strong>something ongoing</strong>, like:</p><ul><li>A timer</li><li>Listening for a change (like chat messages)</li></ul><h4>If you don’t clean up, <strong>problems happen</strong>:</h4><ul><li>Memory leaks</li><li>Multiple timers stacking</li><li>Event handlers running multiple times</li></ul><h4>Example with cleanup:</h4><pre>useEffect(() =&gt; {<br>  const interval = setInterval(() =&gt; {<br>    console.log(&quot;Tick&quot;);<br>  }, 1000);<br><br>  return () =&gt; {<br>    clearInterval(interval); // stop the timer when component leaves<br>  };<br>}, []);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*gTcabEIAND7tvAsoggw_4g.png" /></figure><h3>Mental model 🧠</h3><blockquote><em>“When this component leaves the screen, clean up.”</em></blockquote><h3>The GOLDEN RULE of useEffect</h3><blockquote><strong><em>Everything you use inside </em></strong><strong><em>useEffect that can change<br> MUST be in the dependency array.</em></strong></blockquote><p>Example:</p><pre>useEffect(() =&gt; {<br>  console.log(userId);<br>}, [userId]);</pre><p>This keeps your app predictable and bug-free.</p><h3>One Last Simple Analogy 💡</h3><p>Think of useEffect like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3tTyUwQerocZJiw2C8GHVQ.png" /></figure><h3>Final Checklist ✅</h3><p>Before writing useEffect,Ask yourself:</p><ol><li>Is this a <strong>side effect</strong>?</li><li>When should it run?</li></ol><ul><li>Once → []</li><li>When value changes → <strong>[value]</strong></li></ul><h4>Do I need cleanup?</h4><p>If you answer these, useEffect becomes easy.</p><h3>Conclusion + Tiny Exercise ✅</h3><p>useEffect is React’s way of saying:</p><blockquote><em>“Run this side effect after rendering, watch the things you care about, and clean up when leaving.”</em></blockquote><p>Once you understand the <strong>timing</strong>, dependency array, and cleanup, useEffect becomes <strong>predictable</strong> — not scary.</p><p><strong>Exercise for you:</strong></p><ol><li>Create a state name with useState(&quot;&quot;).</li><li>Use useEffect to update document.title whenever name changes.</li><li>Add a timer inside the effect and clean it up when the component unmounts.</li></ol><p>This small practice will <strong>cement your understanding</strong> immediately.</p><h4>If you feel like you missed any concept, don’t hesitate to reach out — your feedback means a lot to me! ❤️. You can also connect with me on 🌹</h4><h4><a href="https://x.com/Noransaber11">Twitter </a>| <a href="https://www.linkedin.com/in/noran-saber-abdelfattah-6198471ba/">LinkedIn </a>| <a href="https://github.com/Noransaber">GitHub</a> | <a href="https://www.facebook.com/noran.abdelfattah.2025">Facebook</a><br> — Noran 🌹</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7de7b61d6a8" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/react-behind-the-scenes-useeffect-c7de7b61d6a8">React Behind the Scenes, useEffect()</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Behind the Scenes, useState()]]></title>
            <link>https://javascript.plainenglish.io/react-behind-the-scenes-usestate-9d54f164106a?source=rss-f9117bc94016------2</link>
            <guid isPermaLink="false">https://medium.com/p/9d54f164106a</guid>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Noran Saber Abdelfattah]]></dc:creator>
            <pubDate>Tue, 02 Dec 2025 06:02:01 GMT</pubDate>
            <atom:updated>2025-12-02T06:02:01.648Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/630/0*2MbouLkZiN6A-V28.png" /></figure><p>Welcome back to our React learning journey! 🔥<br> In this part, we’re going to uncover one of the most fundamental — yet often misunderstood — concepts in React: <strong>the useState() Hook</strong>.</p><p>If you’ve ever wondered how your React component “remembers” a user’s input, keeps track of a counter, or updates instantly when something changes — that’s all thanks to useState().</p><h4>In this guide, we’ll explore:</h4><ul><li>What useState() Really does under the hood.</li><li>Why normal variables don’t work the same way in React.</li><li>How React keeps track of your component’s memory using hook order.</li><li>And the golden rules every developer must follow to avoid those scary “Invalid Hook Call” errors.</li></ul><p>So grab your coffee ☕, get comfy, and let’s open the locker door to <strong>React’s memory system</strong> — one hook at a time. 🔐✨</p><h3>🧩 1. What is useState()?</h3><p>useState() is a <strong>React Hook</strong> that lets your <em>function components</em> remember data between renders.</p><p>It allows your component to have its <strong>own internal memory</strong> (called <em>state</em>).</p><h4>In plain words:</h4><blockquote><em>It’s how React components can “remember things” — like user input, toggle status, count, or fetched data.</em></blockquote><h3>🧠 Example</h3><pre>function Counter() {<br>  const [count, setCount] = useState(0);<br><br>return (<br>    &lt;button onClick={() =&gt; setCount(count + 1)}&gt;<br>      You clicked {count} times<br>    &lt;/button&gt;<br>  );<br>}</pre><h4>📍 Here’s what’s happening:</h4><ul><li>useState(0) — tells React:</li><li>“Hey, I want a piece of memory called count, starting at 0.”</li><li>React saves 0 in a hidden memory slot (<strong>position/spot</strong>).</li><li>setCount — gives you a way to <strong>update</strong> that memory later.</li><li>When you click the button:</li><li>React updates the stored value (to count + 1).</li><li>Then React <strong>re-renders</strong> the component to show the new number.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1Xm0EG4Jas5wyq_TwTW4gg.png" /></figure><h3>🧠 2. Why do we need useState()?</h3><p>Because <strong>normal variables don’t persist</strong> between renders.</p><p><strong>For example:</strong></p><pre>function Counter() {<br>  let count = 0;<br>  const increment = () =&gt; {<br>    count++;<br>    console.log(count);<br>  };<br>  return &lt;button onClick={increment}&gt;Click&lt;/button&gt;;<br>}</pre><h4>This looks fine — but it doesn’t work in React. 😅 Why?</h4><p>Because every time React re-renders this component, it runs the function <strong>from scratch</strong>, so count is reset to 0.</p><p>That’s why we need React to <strong>remember</strong> the variable for us → that’s what it useState() does.</p><h3>⚙️ 3. How to use useState()</h3><h3>🧩 Syntax</h3><pre>const [state, setState] = useState(initialValue);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*BFs7VPewOwdFSwjKgoc4zA.png" /></figure><h3>🧪 Example</h3><pre>const [name, setName] = useState(&quot;Noran&quot;);<br><br>// Access current state<br>console.log(name); // &quot;Noran&quot;<br>// Update state<br>setName(&quot;Sara&quot;);</pre><h3>🧠 Rules for using useState</h3><ol><li>✅ Only call it <strong>at the top level</strong> of your component.<br> (No loops, conditions, or nested functions.)</li><li>✅ Call it <strong>in the same order</strong> on every render.<br> (React relies on this order to match state slots.)</li><li>✅ Use it only <strong>inside React components or custom hooks.</strong></li></ol><h3>🔍 Curiosity mood on🔥</h3><ol><li>Why useState (and other hooks) must be called at the top level</li><li>Why only inside React components or custom hooks?</li><li>Why order matters</li><li>So what happens if you call hooks inside conditions or loops?</li></ol><h3>🧩 Why useState (and other hooks) must be called at the top level</h3><p>Let’s start by understanding how React <strong>tracks hooks internally</strong>.</p><p>React keeps an internal <strong>array (or linked list)</strong> of hook “slots” for each component — like this:</p><pre>Component A memory:<br>Slot 0 → useState(count)<br>Slot 1 → useEffect(...)<br>Slot 2 → useState(name)</pre><p>When your component renders, React walks through your code <strong>line by line</strong>, and each time it sees a Hook call (like useState), it says:</p><blockquote><em>“Okay, that’s hook #1 → I’ll use slot 0.”<br> “Next hook → slot 1.”<br> “Next hook → slot 2.”</em></blockquote><p>React doesn’t use variable names (count, name, etc.) to track state — It only depends on <strong>the order</strong> of hook calls.</p><h3>🧠 So what happens if you call hooks inside conditions or loops?</h3><pre>if (isLoggedIn) {<br>  useState(&quot;user&quot;);<br>}<br>useState(&quot;theme&quot;);</pre><p>Imagine on the <strong>first render</strong>, isLoggedIn = true, so:</p><pre>Slot 0 → useState(&quot;user&quot;)<br>Slot 1 → useState(&quot;theme&quot;)</pre><p>But on the <strong>next render</strong>, isLoggedIn = false, so the first useState is skipped:</p><pre>Slot 0 → useState(&quot;theme&quot;) ❌ (wrong!)</pre><p>Now React is totally confused 😵 — The slots got <strong>shifted</strong>, so it gives the wrong state value to the wrong variable!</p><h4>That’s why React says</h4><blockquote><em>❌ Don’t call hooks inside conditions, loops, or nested functions.<br> ✅ Always call them at the top level, in the same order every render.</em></blockquote><h3>🧩 Why only inside React components or custom hooks?</h3><p>Hooks are a <strong>bridge to React’s internal memory</strong> system — That memory only exists <strong>while React is rendering a component</strong>.</p><p>If you call a hook <strong>outside</strong> of a React component (like in plain JS code):</p><pre>const [count, setCount] = useState(0); // ❌ outside a component</pre><blockquote>React will say:</blockquote><blockquote><em>“Wait — I’m not rendering anything right now!<br> There’s no component context, no memory slot to attach this to.”</em></blockquote><p>So you’ll get an error like:</p><pre>Invalid hook call. Hooks can only be called inside the body of a function component.</pre><p>Because React can’t store that state anywhere — <br> No “memory box” exists outside the component render cycle.</p><h3>🧩 Why order matters</h3><p>Hooks are <strong>position-based</strong>, not <strong>name-based</strong>.</p><h4>So if on one render, you call:</h4><pre>useState(&quot;count&quot;);<br>useState(&quot;theme&quot;);</pre><h4>React assumes:</h4><ul><li>slot 0 → count</li><li>slot 1 → theme</li></ul><h4>If on the next render, you call:</h4><pre>useState(&quot;theme&quot;);<br>useState(&quot;count&quot;);</pre><h4>React will assign:</h4><ul><li>slot 0 → theme</li><li>slot 1 → count</li></ul><p>Now your states are swapped 😬 — it’s chaos.</p><p>That’s why the <strong>order must always stay the same</strong> every render.</p><h3>🧠 Analogy: “Hook lockers in a gym”</h3><p>Imagine React gives every component a <strong>row of lockers</strong>.</p><ul><li>Each useState gets one locker.</li><li>React remembers which locker number belongs to which state by <strong>order</strong> (not name).</li></ul><p>If you sometimes skip locker #1 or open a new locker mid-way,<br> React will start putting your stuff in the wrong lockers.</p><p>That’s why React says:</p><blockquote><em>Always open the lockers in the same order every time!</em></blockquote><h3>💬 Real-world analogy (super simple)</h3><p>Imagine React as a <strong>locker system at the gym 🏋️‍♀️</strong></p><ul><li>Each hook call gets a locker.</li><li>The locker has a number (its index).</li><li>useState() Put your stuff in that locker (the data).</li><li>When you come back (re-render), React remembers which locker belongs to you and retrieves your stuff.</li><li>When you call setStateYou replace what’s inside the locker — and React refreshes your view to match what’s new inside.</li></ul><h3>🧠 In One Sentence</h3><blockquote><em>useState() gives React components the power to </em><strong><em>remember values</em></strong><em> between renders and </em><strong><em>update the UI</em></strong><em> automatically when those values change.</em></blockquote><h4>If you feel like you missed any concept, don’t hesitate to reach out — your feedback means a lot to me! ❤️. You can also connect with me on 🌹</h4><h4><a href="https://x.com/Noransaber11">Twitter </a>| <a href="https://www.linkedin.com/in/noran-saber-abdelfattah-6198471ba/">LinkedIn </a>| <a href="https://github.com/Noransaber">GitHub</a> | <a href="https://www.facebook.com/noran.abdelfattah.2025">Facebook</a><br> — Noran 🌹</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9d54f164106a" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/react-behind-the-scenes-usestate-9d54f164106a">React Behind the Scenes, useState()</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My First Open-Source Contribution: How Debugging a Browser Extension Made Me Believe in Myself]]></title>
            <link>https://medium.com/@noransaber685/my-first-open-source-contribution-how-debugging-a-browser-extension-made-me-believe-in-myself-b0742aa3d6e7?source=rss-f9117bc94016------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0742aa3d6e7</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[frontend-development]]></category>
            <dc:creator><![CDATA[Noran Saber Abdelfattah]]></dc:creator>
            <pubDate>Sun, 30 Nov 2025 09:18:19 GMT</pubDate>
            <atom:updated>2025-11-30T09:18:19.076Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*4qalc5hdNxbEOoZQ2fp0AQ.avif" /></figure><p>I still remember staring at my screen, feeling a mix of excitement and panic. A browser extension I wanted to contribute to wasn’t working, and I had no idea if I could actually fix it. My hands hovered over the keyboard, heart racing, thinking, <em>“What if I break everything? What if I can’t figure this out?”</em> Little did I know, this one small bug would not only get fixed but also give me a confidence boost I’ll never forget — and spark my first real journey into open source.</p><h3>The Nervous First Steps</h3><p>I forked the repository, cloned it, installed the dependencies… and instantly got stuck. The development setup wasn’t something I’d ever done in this exact way. Vite, Vitest, web extension polyfills — it was a lot to take in.</p><p>I felt nervous, honestly. I kept thinking, <em>“</em><strong><em>Am I even capable of understanding this codebase? Everyone contributing here must be super experienced.</em></strong><em>”</em></p><p>But I started small: exploring the folder structure, reading the docs, and understanding how actions were recorded. I wanted to see the bigger picture — how clicks, inputs, navigation, scrolls, and form submissions were captured and then transformed into JSON files.</p><p>And slowly, the intimidating became exciting. Every function I read, every TypeScript type I understood, gave me a tiny spark of confidence.</p><h3>That One Bug That Made Me Feel Alive</h3><p>Then came the real test: there was a bug in the extension. The recorder wasn’t capturing clicks on a dropdown menu item. For most people, it might have been just another GitHub issue. For me, it felt like a challenge, a puzzle waiting to be solved.</p><p>I dove into the code, tracing how events were captured by the extension. Hours passed. I tried different approaches, looked at event listeners on the website, and then… <strong>I noticed it</strong>.</p><p>The extension was listening for click events, but the website used mousedown for that dropdown. That tiny mismatch was why the recorder failed.</p><p>My heart raced as I implemented the fix, ran the extension, and… it worked. The dropdown item was finally being recorded perfectly.💥</p><p>I can’t describe the feeling — pure joy mixed with disbelief. <em>“</em><strong><em>I did it. I actually did it.</em></strong><em>”</em></p><p>That moment hit me like a wave. I felt a surge of confidence I hadn’t felt before. I realised: if I can solve this, I can solve more. I <em>can</em> contribute meaningfully.</p><h3>From Fixing Bugs to Understanding the Platform</h3><p>After that, I started exploring more of the project. I worked on multi-page recording, overlay controls, multi-selector strategies, and real-time feedback.</p><p>I collaborated with other contributors via GitHub: branching, pull requests, code reviews, and issue tracking.</p><p>I also contributed to the <strong>main SaveAction platform</strong>, the no-code automated testing system that reads the JSON from the recorder and replays user interactions. I debugged core algorithms, optimized workflows, and improved documentation for future contributors.</p><p>Each task, no matter how small, reinforced something crucial: open source isn’t just about writing code. It’s about learning, problem-solving, and growing your confidence.</p><h3>What I Learned</h3><ol><li><strong>It’s okay to be nervous.</strong> Every contributor starts somewhere. Feeling unsure is part of the process.</li><li><strong>Persistence pays off.</strong> That dropdown bug could have defeated me if I had given up. But taking it step by step, reading the code carefully, and testing assumptions made all the difference.</li><li><strong>Collaboration is priceless.</strong> Code reviews, discussions, and feedback from other contributors were eye-opening. You learn more by working <em>with</em> others than by working alone.</li><li><strong>Confidence is built in small wins.</strong> Fixing that one bug didn’t just solve a problem — it made me believe in my abilities.</li></ol><h3>Why I’ll Keep Contributing</h3><p>Contributing to SaveAction taught me more than any tutorial or course could. It gave me confidence in my skills as a frontend engineer and showed me the joy of being part of a community.</p><p>Every pull request merged felt like a tiny <strong>victory</strong>, every <strong>bug fixed </strong>felt like levelling up. I now look at open source not as an intimidating world of experts but as a playground for learning, experimenting, and growing.</p><p>For anyone thinking about contributing for the first time, here’s what I’d say:</p><p><strong><em>Start small. Explore the code. Don’t be afraid to ask questions. And when you solve that first real problem? Trust me, you’ll never forget it.</em></strong></p><p>Open source is more than code. It’s confidence, curiosity, and the joy of building something bigger than yourself. And once you experience that first “I did it” moment, you realise — you can do so much more than you ever imagined.</p><p>And this is just the beginning! I’m already looking forward to my next contribution. In my upcoming article, I’ll share more about the <strong>SaveAction project</strong>, dive into the <strong>next bug I’m going to fix</strong>, and maybe even <strong>reveal a new feature I’ll be adding</strong>. I can’t wait to continue this journey, and I’m thrilled to take you along as I learn, debug, and grow even more in open source.</p><p>You can also connect with me on 🌹</p><h3><a href="https://x.com/Noransaber11">Twitter </a>| <a href="https://www.linkedin.com/in/noran-saber-abdelfattah-6198471ba/">LinkedIn </a>| <a href="https://github.com/Noransaber">GitHub</a> | <a href="https://www.facebook.com/noran.abdelfattah.2025">Facebook</a><br> — Noran 🌹</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0742aa3d6e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Understanding “State as a Snapshot” in React]]></title>
            <link>https://javascript.plainenglish.io/understanding-state-as-a-snapshot-in-react-2f00d17f11c2?source=rss-f9117bc94016------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f00d17f11c2</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[reactive-programming]]></category>
            <dc:creator><![CDATA[Noran Saber Abdelfattah]]></dc:creator>
            <pubDate>Sat, 01 Nov 2025 06:23:46 GMT</pubDate>
            <atom:updated>2025-11-01T06:23:46.704Z</atom:updated>
            <content:encoded><![CDATA[<h3>React Behind the Scenes, State as a Snapshot</h3><h3>Introduction</h3><p>The state in React is sneaky.</p><p>You <em>think</em> it’s a normal variable… until it smiles at you and says, “Haha, not so fast.”</p><p>Don’t worry — we’ll decode this mystery together. By the end of this article, you’ll know exactly why your console.log keeps lying to you (and you’ll never fall for its tricks again).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/1*h1g4h8weWD-vV7fe4nwrnQ.jpeg" /></figure><h3>🧠 Understanding “State as a Snapshot” in React</h3><p>When you first start using React, <strong>state variables</strong></p><pre>const [count, setCount] = useState(0) </pre><p>— <em>look</em> like regular JavaScript variables.</p><p>But here’s the catch:<br> 👉 They <strong>don’t behave like normal variables</strong> at all.</p><h3>🧩 Normal JS variables vs React state</h3><p>In regular JavaScript:</p><pre>let number = 0;<br>number = number + 1;<br>console.log(number); // 1</pre><p>When you change a variable, its value updates immediately.</p><h4>But in React:</h4><pre>const [number, setNumber] = useState(0);<br>setNumber(number + 1);<br>console.log(number); // still 0!</pre><p>Even though you just “set” it, number hasn’t changed yet.</p><p>That’s because React treats <strong>state</strong> differently — it treats it as a <strong>snapshot in time</strong>.</p><h3>📸 What does “snapshot” mean?</h3><p>Imagine React takes a <strong>photo</strong> of your component every time it renders.</p><h4>That photo (the “snapshot”) captures:</h4><ul><li>All your <strong>state variables</strong> (like number)</li><li>All your <strong>props</strong></li><li>All your <strong>event handlers</strong></li></ul><p>When your component is running (during one render), it’s looking at that frozen photo — even if you callsetState(), you’re just <em>asking React</em> to take a <strong>new photo</strong> next time.</p><h3>🧠 Key idea:</h3><blockquote><strong><em>Setting state doesn’t change the state right away.</em></strong><em><br> It just </em><strong><em>requests</em></strong><em> React to re-render with a new snapshot.</em></blockquote><h3>⚙️ Example: The +3 Counter</h3><pre>export default function Counter() {<br>  const [number, setNumber] = useState(0);<br><br>return (<br>    &lt;&gt;<br>      &lt;h1&gt;{number}&lt;/h1&gt;<br>      &lt;button onClick={() =&gt; {<br>        setNumber(number + 1);<br>        setNumber(number + 1);<br>        setNumber(number + 1);<br>      }}&gt;+3&lt;/button&gt;<br>    &lt;/&gt;<br>  )<br>}</pre><p>When you click the button, you might expect the number to go up by 3.<br> But it only increases by 1. Why?</p><p>Because during that one “photo” (render), number is still <strong>0</strong>.<br> So each line effectively does:</p><pre>setNumber(0 + 1); // sets to 1<br>setNumber(0 + 1); // sets to 1 again<br>setNumber(0 + 1); // sets to 1 again</pre><p>After React finishes running your event handler, it takes a new photo — and now number is 1.</p><p>That’s why you only see it increase once.</p><h3>🕰️ State over Time</h3><p>React doesn’t update state instantly — it updates it <strong>over time</strong>, between renders.</p><p><strong>For example:</strong></p><pre>&lt;button onClick={() =&gt; {<br>  setNumber(number + 5);<br>  alert(number);<br>}}&gt;+5&lt;/button&gt;</pre><p>This alert shows <strong>0</strong>, not 5, because number in this render is still 0.<br> React hasn’t re-rendered yet.</p><h4>Even if you delay the alert:</h4><pre>setNumber(number + 5);<br>setTimeout(() =&gt; alert(number), 3000);</pre><p>You’ll <em>still</em> see <strong>0</strong>, because the function “remembers” the state from the render it was created in.</p><h3>💡 Why React Does This</h3><p>This “snapshot” behaviour isn’t a bug — it’s a design choice.<br> It helps React keep your UI predictable and stable.</p><ul><li>Each render is <strong>self-contained</strong> — everything inside it is consistent.</li><li>You never get “half updated” UIs where only some parts have changed.</li><li>You can trust that your event handlers always use the state that existed when they were created.</li></ul><h3>🧰 How React Manages It</h3><p>Think of React’s state as being stored <strong>outside your component</strong>, like on a shelf.</p><ol><li>Every time React renders, it <strong>reads</strong> the state value from that shelf.</li><li>Your component gets a <strong>copy (snapshot)</strong> of that value for that render.</li><li>When you call setState, React doesn’t change the snapshot — it just says:</li></ol><ul><li>“Hey React, next time you render, use this new value.”</li></ul><p>If you feel like you missed any concept, don’t hesitate to reach out — your feedback means a lot to me! 🌹.</p><p>You can also connect with me on 🌹</p><h3><a href="https://x.com/Noransaber11">Twitter </a>| <a href="https://www.linkedin.com/in/noran-saber-abdelfattah-6198471ba/">LinkedIn </a>| <a href="https://github.com/Noransaber">GitHub</a> | <a href="https://www.facebook.com/noran.abdelfattah.2025">Facebook</a><br> — Noran 🌹</h3><h3>A message from our Founder</h3><p><strong>Hey, </strong><a href="https://linkedin.com/in/sunilsandhu"><strong>Sunil</strong></a><strong> here.</strong> I wanted to take a moment to thank you for reading until the end and for being a part of this community.</p><p>Did you know that our team run these publications as a volunteer effort to over 3.5m monthly readers? <strong>We don’t receive any funding, we do this to support the community. ❤️</strong></p><p>If you want to show some love, please take a moment to <strong>follow me on </strong><a href="https://linkedin.com/in/sunilsandhu"><strong>LinkedIn</strong></a><strong>, </strong><a href="https://tiktok.com/@messyfounder"><strong>TikTok</strong></a>, <a href="https://instagram.com/sunilsandhu"><strong>Instagram</strong></a>. You can also subscribe to our <a href="https://newsletter.plainenglish.io/"><strong>weekly newsletter</strong></a>.</p><p>And before you go, don’t forget to <strong>clap</strong> and <strong>follow</strong> the writer️!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f00d17f11c2" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/understanding-state-as-a-snapshot-in-react-2f00d17f11c2">🧠 Understanding “State as a Snapshot” in React</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Behind the Scenes, Hooks]]></title>
            <link>https://medium.com/@noransaber685/react-behind-the-scenes-hooks-1d592cb91833?source=rss-f9117bc94016------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d592cb91833</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[reactive-programming]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Noran Saber Abdelfattah]]></dc:creator>
            <pubDate>Tue, 14 Oct 2025 04:25:34 GMT</pubDate>
            <atom:updated>2025-10-14T04:25:34.619Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*lza3LpavxDnHWQCA.png" /></figure><h4>Welcome back to a new journey with React.🔥</h4><h3>🧭 What’s Really Happening Inside React?</h3><p>If you’ve ever used useState() or useEffect() and wondered,<br> <strong>“Wait — how does React actually remember this data between renders?”</strong>,<br> You’re in the right place.</p><p>Most developers learn Hooks by example — they <em>use</em> them, but don’t truly understand what’s happening <em>behind the scenes</em>.</p><p>In this deep dive, we’ll lift the curtain on React’s internal memory system — <br> how Hooks “hook into” React’s brain,<br> how state actually persists when your component re-renders,<br> and why <strong>the order of your Hooks</strong> matters more than you might think.</p><p>By the end of this article, you won’t just know how to <em>use</em> Hooks — <br> You’ll understand how React <em>thinks</em> when running them.</p><p>Welcome to the inner workings of React Hooks — <br> where simple functions gain memory, and React’s magic becomes logic. ⚙️✨</p><h3>🧠 1. What is a Hook?</h3><p><strong>A Hook</strong> in React is a <strong>special function</strong> that lets you “<strong>hook into</strong>” React’s internal features — like state, lifecycle, and context — <em>inside functional components.</em></p><p>In other words, Hooks let <strong>functions act like classes</strong> — they can now store data, handle events, and react to changes.</p><p><strong>🧩 Example Hooks:</strong></p><ul><li>useState() → for state (data that changes)</li><li>useEffect() → for side effects (fetching data, timers, etc.)</li><li>useContext() → for global data</li><li>useRef() → for referencing DOM elements</li></ul><h3>⚙️ 2. What is useState()?</h3><p>useState() is a <strong>React Hook</strong> that lets your component <strong>remember values between renders.</strong></p><p>Without it, every time your component re-renders, all variables would reset to their default.</p><p>So useState gives your component <strong>memory</strong> 💾.</p><h3>🧩 Syntax:</h3><pre>const [state, setState] = useState(initialValue);</pre><h3>💬 Example:</h3><pre>function Counter() {<br>  const [count, setCount] = useState(0); // 👈 initialize state with 0<br>return (<br>    &lt;div&gt;<br>      &lt;p&gt;You clicked {count} times&lt;/p&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;<br>        Click Me<br>      &lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><h3>🧠If it still isn’t clear — that’s perfectly normal. Let’s switch on <strong>curiosity mode🔍</strong> and walk through what’s happening, step by step:</h3><h4>When the component <strong>first renders</strong>, React calls useState(0) and remembers:</h4><ul><li>the current value → 0</li><li>the updater function → setCount</li><li>When you click the button, React calls setCount(count + 1)<br> That tells React:</li><li>“Hey, I have new data — please re-render me with count = 1.”</li><li>React <strong>re-renders</strong> the component, and now count becomes 1.</li></ul><p>So every render → React gives you the latest state value.</p><h3>🧠 What does “Hook into React’s internal features” mean?</h3><p>Think of React as a <strong>machine</strong> that:</p><ul><li>Keeps track of <em>state</em> (data)</li><li>Watch for changes</li><li>Re-renders your UI when data changes</li></ul><p>But by default, <strong>JavaScript functions are stateless</strong> — <br> Every time you call a function, it forgets everything from before.</p><p>So, React gives you a way to <em>“</em><strong><em>hook into</em></strong><em>”</em> its internal system of memory and updates.</p><p>💡 That’s why they’re called <strong>Hooks</strong> — <br> They <em>hook</em> your function component into React’s internal memory system, which keeps track of data between renders.</p><h3>🧩 Simple analogy:</h3><p><strong>Imagine React as a notebook 📒</strong></p><ul><li><strong>Normally, when you run a JS function, you write something and throw away the page.</strong></li><li><strong>But React keeps a notebook for each component.<br> Each time your function runs again, it opens the same notebook and looks up what you wrote before (your state).</strong></li></ul><p><strong>useState, </strong><strong>useEffect, etc., are like pages in that notebook.</strong></p><h3>⚙️ Why do we say “Hooks let functions act like classes”?</h3><p>Before Hooks, only <strong>class components</strong> could use:</p><ul><li>State (this.state)</li><li>Lifecycle methods (componentDidMount, componentDidUpdate, etc.)</li></ul><p>But functional components couldn’t — they were just dumb renderers.</p><h4>Hooks changed that.<br> Now a functional component can <em>store state</em> and <em>react to changes</em> — just like a class component — but with simpler syntax.</h4><p>Compare 👇</p><h3>🧩 Before (Class Component):</h3><pre>class Counter extends React.Component {<br>  state = { count: 0 };<br><br>increment = () =&gt; this.setState({ count: this.state.count + 1 });<br>  render() {<br>    return (<br>      &lt;button onClick={this.increment}&gt;<br>        Count: {this.state.count}<br>      &lt;/button&gt;<br>    );<br>  }<br>}</pre><h3>🧩 After (Functional + Hook):</h3><pre>function Counter() {<br>  const [count, setCount] = useState(0);<br>  return (<br>    &lt;button onClick={() =&gt; setCount(count + 1)}&gt;<br>      Count: {count}<br>    &lt;/button&gt;<br>  );<br>}</pre><p>Both do the <strong>same thing</strong> — <br> The Hook version is just shorter, cleaner, and more “functional”.</p><h3>⚙️How Hooks work internally</h3><p>Let’s demystify this 👇</p><ul><li>When React renders your component, it keeps a <strong>hidden array</strong> of states inside it.</li><li>Each time you call useState(), React adds one item to that list.</li></ul><p><strong>Example:</strong></p><pre>function Profile() {<br>  const [name, setName] = useState(&quot;Noran&quot;);   // 1️⃣ stored at index 0<br>  const [age, setAge] = useState(22);          // 2️⃣ stored at index 1<br>// render logic...<br>}</pre><p><strong>React internally keeps something like:</strong></p><pre>let hookStates = [<br>  &quot;Noran&quot;, // index 0<br>  22       // index 1<br>]</pre><p>When you call setName(&quot;Noor&quot;), React:</p><ol><li>Updates hookStates[0] = &quot;Noor&quot;</li><li>Re-renders your component</li><li>Reads from hookStates again → now name = &quot;Noor&quot;</li></ol><p>So React knows which Hook value to return by <strong>the order you call them</strong> — <br> That’s why Hooks must be at the top level and not inside conditions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jdT7Od95wfWTNwcOrXmGiQ.png" /></figure><h3>🧠 The Core Idea of Hooks</h3><h3>1️⃣ Normal JavaScript functions:</h3><ul><li>Run → do their job → forget everything.</li><li>Variables inside them vanish after the function ends.</li></ul><pre>function sayHi() {<br>  let count = 0;<br>  count++;<br>  console.log(count);<br>}<br>sayHi(); // 1<br>sayHi(); // 1 again (it forgets)</pre><p>Every call starts <strong>fresh</strong>, because functions in JS don’t have memory by default.</p><h3>2️⃣ React components re-render</h3><p>React needs to:</p><ul><li>Remember <em>some data</em> between renders (like a counter, input value, toggle)</li><li>Re-render when that data changes.</li></ul><p><strong>Therefore, it requires functions that can retain information across multiple executions</strong>.</p><h3>3️⃣ That’s why Hooks exist</h3><p>Hooks are like <strong>functions with memory</strong> — <br> They “hook into” React’s hidden memory system<strong>, allowing data to persist between renders.</strong></p><p>When you use a Hook like useState:</p><ul><li>React <em>remembers</em> your variable (state)</li><li>Gives you a way to <em>update</em> it (setState)</li><li>And when you update → React <em>re-runs</em> the component with new data</li></ul><pre>function Counter() {<br>  const [count, setCount] = useState(0); // 👈 Hook with memory<br>return (<br>    &lt;button onClick={() =&gt; setCount(count + 1)}&gt;<br>      {count}<br>    &lt;/button&gt;<br>  );<br>}</pre><p>Now:</p><ul><li>When the component re-renders, React doesn’t reset count to 0.</li><li>It looks up the previous value from its internal memory.</li><li>That’s how it remembers and reacts to changes.</li></ul><h4>They “hook into” React’s hidden memory system, allowing data to persist between renders. How do hooks hook into the React memory system?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qc9UhiEkhhJGmX_N-vO4og.png" /></figure><h3>⚙️ React’s “hidden memory system”</h3><ul><li>React’s genius solution is to give every component its own <strong>internal memory</strong>.</li><li>You can think of it as an <strong>array</strong> that React keeps secretly for each component.</li></ul><p>For example, if you have:</p><pre>function Profile() {<br>  const [name, setName] = useState(&quot;Noran&quot;);<br>  const [age, setAge] = useState(22);<br>  return &lt;h1&gt;{name} - {age}&lt;/h1&gt;;<br>}</pre><p><strong>React internally keeps something like:</strong></p><pre>componentMemory = [<br>  &quot;Noran&quot;, // 0th Hook → name<br>  22       // 1st Hook → age<br>];</pre><p>So, React doesn’t forget — it keeps your data in that “hidden memory array.”</p><h3>🪝 How Hooks “hook” into that memory</h3><p>Here’s what happens behind the scenes when React renders your component:</p><ul><li>React starts rendering your component and sets a <strong>pointer</strong> to track which Hook is being used (like an index starting at 0).</li></ul><pre>currentHookIndex = 0;</pre><ul><li>You call the first Hook:</li></ul><pre>const [name, setName] = useState(&quot;Noran&quot;);</pre><ul><li>React looks at its memory at the index 0.</li><li>If it’s the first render, it stores &quot;Noran&quot; there.</li><li>On later renders, it retrieves the <strong>existing</strong> value.</li><li>Then React increments the index:</li><li>currentHookIndex++;</li></ul><h4>Next Hook</h4><pre>const [age, setAge] = useState(22);</pre><ol><li>React looks at its memory at the index 1 this time, and does the same.</li><li>After rendering finishes, React resets the currentHookIndex back to 0 for the next render.</li></ol><ul><li>So, Hooks <strong>“hook into”</strong> React’s memory because each one is linked to a specific slot in that memory array.</li><li>React knows which state belongs to which Hook by the <strong>order</strong> they’re called.</li><li>That’s why you <strong>must not</strong> put Hooks inside if or for —<br> It would mess up the order, and React would lose track of which memory slot belongs to which state.</li></ul><h3>🧩 4️⃣ When you call setState()</h3><p>When you call something like:</p><pre>setName(&quot;Noor&quot;);</pre><h3>React:</h3><ol><li>Updates that internal memory slot (e.g., index 0 → “Noor”)</li><li>Marks the component as “dirty” (needs re-render)</li><li>Call your component function again</li><li>When it runs again, React starts from hookIndex = 0<br> and gives you back &quot;Noor&quot; as the first Hook’s value.</li></ol><p>This loop repeats — <br> And that’s how Hooks keep your data <strong>alive between renders.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ty9lz_OnGzFxPwE6GFhHww.png" /></figure><h3>🔍 5️⃣ In plain JS (simplified example)</h3><p>Here’s a tiny fake version of how React might implement this:</p><pre>let componentMemory = [];  // React’s internal memory<br>let currentHook = 0;<br><br><br>function useState(initialValue) {<br>  const hookIndex = currentHook;<br>  componentMemory[hookIndex] = componentMemory[hookIndex] ?? initialValue;<br>  const setValue = (newValue) =&gt; {<br>    componentMemory[hookIndex] = newValue;<br>    render(); // triggers re-render<br>  };<br>  currentHook++;<br>  return [componentMemory[hookIndex], setValue];<br>}<br>function render() {<br>  currentHook = 0; // reset before rendering<br>  Counter();       // re-run component<br>}<br>function Counter() {<br>  const [count, setCount] = useState(0);<br>  console.log(count);<br>  // simulate click<br>  setCount(count + 1);<br>}</pre><p>Each time Counter() runs, React pulls the right value from its internal componentMemory.</p><h3>🧭 So in short</h3><blockquote><em>Hooks “hook into” React’s internal memory system because React </em><strong><em>keeps a hidden array of Hook values per component</em></strong><em>,<br> and every time you call a Hook, React knows </em><strong><em>which memory slot</em></strong><em> that Hook is tied to — by </em><strong><em>call order</em></strong><em>.</em></blockquote><p>That’s how:</p><ul><li>Data persists between renders ✅</li><li>Functions can “remember” their state ✅</li><li>React knows when to re-render ✅</li></ul><h3>Summary diagram</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gqvFQlhvA94iCX4kn-ayHw.png" /></figure><h3>🏪 React Hooks Analogy — “The Hook Store”</h3><p>Think of React as managing a <strong>mall full of tiny stores</strong> 🏬<br> Each <strong>component</strong> (like Counter, Profile, etc.) has its own <strong>mall section</strong>.<br> Inside that section, React opens <strong>one store for every Hook</strong> you call.</p><h3>🎯 How It Works Step-by-Step</h3><ol><li>🏗️ <strong>Render starts</strong><br> React says: “Okay, time to render the Profile component. Let’s open its memory mall.”</li><li>🧾 <strong>React assigns store IDs (indexes)</strong><br> Each hook gets a unique store ID <strong>based on its order</strong> in the code:</li></ol><pre>const [name, setName] = useState(&quot;Noran&quot;); // Store #0<br> const [age, setAge] = useState(22) // Store #1</pre><ol><li>📦 <strong>Each store saves data</strong><br> React puts your data into the correct store:</li></ol><pre>Store #0 → &quot;Noran&quot;<br>Store #1 → 22</pre><ol><li>🔍 <strong>React remembers the location (ID)</strong><br> When React renders again, it goes to the same stores <em>in the same order</em><br> (That’s why hooks must always be called in the same order — React relies on store #0, #1, #2, etc.).</li><li>🧮 <strong>When you update state (setState)</strong><br> React goes to that exact store ID, updates the stored value,<br> and says: “Hey, something changed — let’s re-render this component.”</li><li>🔁 <strong>Re-render time!</strong><br> During re-render:</li></ol><ul><li>React reopens the same “mall section” for that component.</li><li>Goes to each store (Hook slot) in order.</li><li>Reads the updated values from each one.</li><li>Then re-renders the UI using those fresh values</li></ul><h3>Hooks in a Nutshell</h3><ul><li>React gives each component its own hidden memory array.</li><li>Each Hook (like useState) gets a fixed slot in that array, in call order.</li><li>On re-render, React reads and updates values from those same slots.</li><li>That’s why Hooks must always be called in the same order — it’s how React knows which state belongs where.</li><li>In essence, Hooks turn ordinary JS functions into stateful, reactive components.</li></ul><h3>🔥 What’s Next?</h3><p>This was just the beginning of our deep dive into <strong>React Hooks</strong> — <br> We uncovered how React secretly remembers your data and keeps your components alive between renders.</p><p>In the next articles, we’ll explore each Hook step by step — starting with the most essential ones:<br> <strong>useState, </strong><strong>useEffect, and </strong><strong>useContext</strong>.<br> You’ll learn <em>how they work, when to use them,</em> and <em>the hidden rules</em> that make them so powerful.</p><p>So… are you ready to go deeper into the React world? 🔥🔥<br> Follow along — the next chapter drops soon. 🚀</p><p>If you feel like you missed any concept, don’t hesitate to reach out — your feedback means a lot to me! ❤️.</p><p>You can also connect with me on 🌹</p><h4><a href="https://x.com/Noransaber11">Twitter </a>| <a href="https://www.linkedin.com/in/noran-saber-abdelfattah-6198471ba/">LinkedIn </a>| <a href="https://github.com/Noransaber">GitHub</a> | <a href="https://www.facebook.com/noran.abdelfattah.2025">Facebook</a><br> — Noran 🌹</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d592cb91833" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Behind the Scenes, map(), props, even handling & propagation]]></title>
            <link>https://medium.com/@noransaber685/react-behind-the-scenes-map-props-even-handling-propagation-52cd1d4260c4?source=rss-f9117bc94016------2</link>
            <guid isPermaLink="false">https://medium.com/p/52cd1d4260c4</guid>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[fullstack-development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Noran Saber Abdelfattah]]></dc:creator>
            <pubDate>Wed, 08 Oct 2025 06:11:56 GMT</pubDate>
            <atom:updated>2025-10-08T06:11:56.897Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*lza3LpavxDnHWQCA.png" /></figure><h4>Welcome back to a new journey with React.🔥</h4><p>If you’ve ever written React code and wondered <em>“how does </em><strong><em>map()</em></strong><em> really work under the hood?”</em>, or <em>“</em><strong><em>why do events bubble up to their parents?</em></strong><em>”</em>, you’re in the right place.</p><p>In this guide, we’ll break down three core concepts every front-end developer should master:</p><ol><li><strong>map()</strong> — how we transform and render data efficiently in JavaScript and React.</li><li><strong>Props</strong> — how React components talk to each other by passing data and functions.</li><li><strong>Event Handling &amp; Propagation</strong> — how user actions flow through the DOM and how React manages them.</li></ol><p>Think of this as understanding <em>how your app listens, talks, and reacts</em> — the foundation of everything you’ll build with React.</p><p>Grab your coffee, get comfortable, and join me on this next step of our React journey.☕</p><p>🔍 Whenever you spot this symbol, it means the curiosity mode is on ✨🔥</p><h3>🔍🧭 What is map() in JavaScript?</h3><p>👉 map() is a <strong>built-in array method</strong> that allows you to:</p><blockquote><em>Transform each item in an array </em><strong><em>into something new</em></strong><em>,<br> and return a </em><strong><em>new array</em></strong><em> with the transformed results.</em></blockquote><p>It does <strong>not</strong> change (mutate) the original array — it creates a <strong>new one</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x4vtn3Y76AllQ97z104tAw.png" /></figure><h3>💡 Simple Example</h3><pre>const numbers = [1, 2, 3, 4];<br>const doubled = numbers.map(num =&gt; num * 2);<br>console.log(doubled); // [2, 4, 6, 8]<br>console.log(numbers); // [1, 2, 3, 4]  (original not changed)</pre><p>So:</p><ul><li>Input: [1, 2, 3, 4]</li><li>Output: [2, 4, 6, 8]</li><li>Action: multiply every item by 2.</li></ul><h3>⚙️🔍 What does it do?</h3><p>It <strong>loops through</strong> each element of the array, applies a function you provide (called the <strong>callback function</strong>) to each element, and collects the results into a <strong>new array</strong>.</p><p>Think of it as a <strong>machine</strong>:</p><pre>[1, 2, 3]  →  map(fn)  →  [fn(1), fn(2), fn(3)]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YYGsg2HSxQ0F-JmpANxDgg.png" /></figure><h3>🧠 How it works internally</h3><p>You can imagine map() doing this behind the scenes:</p><pre>function customMap(array, callback) {<br>  const newArray = [];<br>  for (let i = 0; i &lt; array.length; i++) {<br>    const result = callback(array[i], i, array);<br>    newArray.push(result);<br>  }<br>  return newArray;<br>}</pre><p>That’s basically how it’s implemented in JS!</p><h3>🧩 Syntax</h3><pre>array.map(function(element, index, array) {<br>  // return something new<br>});</pre><p>Or using an arrow function:</p><pre>array.map((element, index, array) =&gt; expression);</pre><h3>📦 The map() arguments</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*bEjQvw_lQqbYsAZF9zluhQ.png" /></figure><p><strong>Example:</strong></p><pre>[10, 20, 30].map((num, index, arr) =&gt; {<br>  console.log(num, index, arr);<br>  return num + 5;<br>});</pre><h3>🧰 When do we need map()?</h3><h3>✅ In general JavaScript:</h3><ul><li>When you want to <strong>transform data</strong> from one <strong>form </strong>to another.<br><strong> Example:</strong></li></ul><pre>const names = [&quot;noran&quot;, &quot;ali&quot;, &quot;sara&quot;]; <br>const upper = names.map(name =&gt; name.toUpperCase());<br> console.log(upper); // [&quot;NORAN&quot;, &quot;ALI&quot;, &quot;SARA&quot;]</pre><h3>⚛️ In React:</h3><p>map() is <strong>essential</strong> when rendering lists.</p><p><strong>Example:</strong></p><pre>const users = [&quot;Noran&quot;, &quot;Ali&quot;, &quot;Sara&quot;];<br>function UserList() {<br>  return (<br>    &lt;ul&gt;<br>      {users.map(user =&gt; (<br>        &lt;li key={user}&gt;{user}&lt;/li&gt;<br>      ))}<br>    &lt;/ul&gt;<br>  );<br>}</pre><p><strong>React will render:</strong></p><pre>• Noran<br>• Ali<br>• Sara</pre><p>Here, map() transforms an array of <strong>data</strong> → into an array of <strong>JSX elements</strong>.</p><h3>⚛️ Why in React we “just give it the element”, not the index or array?</h3><p>When you write this:</p><pre>const users = [&quot;Noran&quot;, &quot;Ali&quot;, &quot;Sara&quot;];<br>function UserList() {<br>  return (<br>    &lt;ul&gt;<br>      {users.map(user =&gt; (<br>        &lt;li key={user}&gt;{user}&lt;/li&gt;<br>      ))}<br>    &lt;/ul&gt;<br>  );<br>}</pre><p>You only use the <strong>first parameter</strong> — user.<br> But remember: map() <em>still</em> passes <strong>three arguments</strong> under the hood:</p><pre>array.map((element, index, array) =&gt; { ... })</pre><p>You’re simply <em>choosing</em> to use only the first one.</p><h3>🧠 Why do we usually only use the element in React?</h3><p>Because in most cases:</p><ul><li>We only need the <strong>data</strong> (user) to display it.</li><li>We <strong>don’t care</strong> about the position (index) unless it’s for something like a key or styling.</li><li>The <strong>array itself</strong> is already available in scope (users), so we don’t need it either.</li></ul><p>So React devs often do this:</p><p>✅ <strong>Use only the element</strong></p><pre>users.map(user =&gt; &lt;li&gt;{user}&lt;/li&gt;)</pre><p>But we <em>could</em> do this if we wanted:</p><p>✅ <strong>Use element + index</strong></p><pre>users.map((user, i) =&gt; &lt;li key={i}&gt;{i + 1}. {user}&lt;/li&gt;)</pre><h3>💡 The reason map() works perfectly in React</h3><p>Because map() always <strong>returns a new array</strong>,<br> and React needs exactly that — <strong>an array of JSX elements</strong> to render.</p><p><strong>Example:</strong></p><pre>users.map(user =&gt; &lt;li&gt;{user}&lt;/li&gt;)</pre><p><strong>returns:</strong></p><pre>[<br>  &lt;li&gt;Noran&lt;/li&gt;,<br>  &lt;li&gt;Ali&lt;/li&gt;,<br>  &lt;li&gt;Sara&lt;/li&gt;<br>]</pre><p>React then takes that array and renders each &lt;li&gt; to the <strong>real DOM</strong>.</p><h3>⚠️ But what about the key?</h3><p>React requires a key prop when rendering lists because it needs to track elements efficiently during re-renders (for diffing).</p><p><strong>Example:</strong></p><pre>users.map((user, index) =&gt; (<br>  &lt;li key={index}&gt;{user}&lt;/li&gt;<br>))</pre><p>✅ This works, but key={index} is only safe if:</p><ul><li>The list order never changes.</li></ul><p>If items can be reordered or deleted, you should use a <strong>unique ID</strong> instead of the index:</p><pre>users.map(user =&gt; &lt;li key={user.id}&gt;{user.name}&lt;/li&gt;)</pre><h3>⚙️ 1️⃣ What is an event handler?</h3><p>An <strong>event handler</strong> is just a <strong>function</strong> that runs when a specific event happens — like a click, typing, mouse move, submit, etc.</p><p>🧠 Think of it like:</p><blockquote><em>“When this happens → do that.”</em></blockquote><p>Example (plain JS):</p><pre>const button = document.querySelector(&quot;button&quot;);<br>button.addEventListener(&quot;click&quot;, () =&gt; {<br>  alert(&quot;Button clicked!&quot;);<br>});</pre><p>Here, the arrow function is your <strong>event handler</strong>.<br> It “handles” the click event.</p><h3>⚛️ 2️⃣ In React, it’s the same idea</h3><p>React gives you an easier, declarative way to attach event handlers.</p><p>Example:</p><pre>function App() {<br>  function handleClick() {<br>    alert(&quot;Button clicked!&quot;);<br>  }<br>return &lt;button onClick={handleClick}&gt;Click Me&lt;/button&gt;;<br>}</pre><h4>✅ Here:</h4><ul><li>onClick is a <strong>JSX attribute</strong> (like className, id, etc.).</li><li>handleClick is your <strong>event handler function</strong>.</li><li>React listens for clicks on that button, and when it happens, it calls handleClick().</li></ul><h3>🧩 3️⃣ But wait — how does it actually work?</h3><p>JSX is just syntax sugar.<br> This:</p><pre>&lt;button onClick={handleClick}&gt;Click Me&lt;/button</pre><p>is translated by <strong>Babel</strong> into:</p><pre>React.createElement(&quot;button&quot;, { onClick: handleClick }, &quot;Click Me&quot;);</pre><p>So when React creates the real DOM element under the hood, it:</p><ol><li>Creates a &lt;button&gt; element.</li><li>Adds a <strong>real browser event listener</strong> to it (element.addEventListener(&quot;click&quot;, handleClick)).</li><li>So when you click → React calls your function.</li></ol><p>That’s why it <em>feels like magic</em>, but it’s actually plain JS happening under the hood.</p><h3>💬 What is a prop?</h3><p><strong>Props</strong> (short for <em>properties</em>) are <strong>inputs to components</strong>.</p><p>They <strong>allow you to pass data or functions (such as event handlers) from parent to child</strong> components.</p><p>Think of props like function parameters.</p><p>Example:</p><pre>function Greeting(props) {<br>  return &lt;h1&gt;Hello, {props.name}!&lt;/h1&gt;;<br>}<br><br>function App() {<br>  return &lt;Greeting name=&quot;Noran&quot; /&gt;;<br>}</pre><p><strong>Babel turns it into:</strong></p><pre>React.createElement(Greeting, { name: &quot;Noran&quot; });</pre><p><strong>in plain JS</strong></p><pre>Greeting({ name: &quot;Noran&quot; });</pre><p>✅ What happens:</p><ul><li>App passes a prop: name=&quot;Noran&quot;.</li><li>Inside GreetingYou can access it via props.name.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dT0lPC47UbOLRvgxVrByYQ.png" /></figure><h3>🧠 How can props hold functions (like event handlers)?</h3><p>Props can hold <strong>any JavaScript value, including strings, numbers, arrays, functions, and more</strong>.</p><p>So, when you pass an event handler:</p><pre>function App() {<br>  function sayHello() {<br>    alert(&quot;Hello!&quot;);<br>  }<br><br>return &lt;Button onClick={sayHello} /&gt;;<br>}</pre><p>✅ Here:</p><ul><li>onClick is a <strong>prop</strong> passed to the Button component.</li><li>Inside ButtonYou can use it like this:</li></ul><pre>function Button(props) <br>{   <br>    return &lt;button onClick={props.onClick}&gt;Click me&lt;/button&gt;; <br>}</pre><ul><li>When the &lt;button&gt; is clicked, React calls props.onClick() — which is your sayHello function.</li></ul><p>So, <strong>React doesn’t care what the function is doing</strong>; it just passes it down and runs it when needed.</p><h3>🎯 Why do we use props?</h3><p>Because they make components <strong>reusable and dynamic</strong>.</p><p><strong>Example:</strong></p><pre>function Button({ label, onClick }) {<br>  return &lt;button onClick={onClick}&gt;{label}&lt;/button&gt;;<br>}<br><br>function App() {<br>  return (<br>    &lt;&gt;<br>      &lt;Button label=&quot;Say Hello&quot; onClick={() =&gt; alert(&quot;Hello!&quot;)} /&gt;<br>      &lt;Button label=&quot;Say Bye&quot; onClick={() =&gt; alert(&quot;Bye!&quot;)} /&gt;<br>    &lt;/&gt;<br>  );<br>}</pre><p>Now the same A Button component can behave differently depending on the props it receives.<br> That’s <strong>reusability</strong> — a core React principle.</p><h3>💬 3️⃣ Props are read-only</h3><p>This is important. The <strong>child</strong> component (that receives props) cannot modify them — it can only <em>read</em> them.</p><p><strong>Example:</strong></p><pre>function Greeting({ name }) {<br>  name = &quot;Sara&quot;; // ❌ bad practice — props should not be changed<br>  return &lt;h1&gt;Hello, {name}&lt;/h1&gt;;<br>}</pre><p>React follows a <strong>one-way data flow</strong>:</p><blockquote><em>Parent → Child (downward only)</em></blockquote><h3>⚛️ How props make components reusable</h3><p>Let’s take an example:</p><pre>function Button({ label, color }) {<br>  return &lt;button style={{ background: color }}&gt;{label}&lt;/button&gt;;<br>}<br><br>function App() {<br>  return (<br>    &lt;&gt;<br>      &lt;Button label=&quot;Save&quot; color=&quot;green&quot; /&gt;<br>      &lt;Button label=&quot;Cancel&quot; color=&quot;red&quot; /&gt;<br>    &lt;/&gt;<br>  );<br>}</pre><ul><li>App passes different <strong>props</strong> each time (label, color).</li><li>The same Button component behaves differently → <strong>reusability</strong>.</li></ul><p>React renders each &lt;Button&gt; separately with the props it got.</p><h3>🧩 Props can be <em>any data type</em></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/1*XQuitPzOgbFiKihmGernyw.png" /></figure><h3>⚙️ Destructuring props</h3><p>Instead of always writing props.name, props.age...</p><p>You can <strong>destructure</strong>:</p><pre>function Greeting({ name, age }) {<br>  return &lt;p&gt;Hello {name}, you’re {age} years old!&lt;/p&gt;;<br>}</pre><p>Same result, cleaner code.</p><h3>🔁 7️⃣ How props flow in React tree</h3><p>Let’s visualise:</p><pre>App<br> ├── Header title=&quot;My App&quot;<br> ├── User name=&quot;Noran&quot;<br> │     └── Avatar src=&quot;profile.jpg&quot;<br> └── Footer year={2025}</pre><p>Here:</p><ul><li>App passes props down.</li><li>Each child receives their own props.</li><li>Data flows one way → downward.</li><li>If something needs to go up (like a button click), we pass a <strong>function as a prop</strong> (the event handler idea).</li></ul><h4>Simply, think about it like a parent is giving their child a gift</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/235/1*fr7AczzkG4hRXWUjzvbOHw.png" /></figure><p>Imagine a <strong>parent</strong> gives their <strong>child</strong> a gift — let’s say a <em>toy car</em>.<br> Now, think of the <strong>parent</strong> as the <em>parent component</em> and the <strong>child</strong> as the <em>child component</em>.</p><ul><li>The parent says, “Here’s your toy car 🚗.”<br> → This is like <strong>passing a prop</strong></li><li>&lt;Child gift=&quot;toy car&quot; /&gt;</li><li>The child receives the toy car and can <strong>play with it</strong>, <strong>show it</strong>, or <strong>use it</strong> in any way.<br> → That means the child component can <strong>use</strong> the prop:</li></ul><pre>function Child(props) {<br>   return &lt;p&gt;I&#39;m playing with my {props.gift}!&lt;/p&gt;; <br>}</pre><ul><li>But the child <strong>can’t change the gift itself</strong> — they can’t turn the toy car into a bike 🚲.<br> → Because <strong>props are read-only</strong>, the child can use them, but not modify them.</li></ul><h3>🧠 So in React terms:</h3><ul><li>Parent → passes data = <strong>props</strong></li><li>Child → receives data = <strong>via function parameters</strong></li><li>Child → can <strong>use</strong> the prop but <strong>not modify</strong> it.</li></ul><h3>⚙️ 1️⃣ What is Event Propagation?</h3><p><strong>Event propagation</strong> describes <strong>how events travel through the DOM tree</strong> when something happens — like a click.</p><p>🧠 Think of it like <strong>ripples in water</strong>:</p><blockquote><em>You click a button → that click “bubbles” up through its parent elements → and each parent </em>can also react<em> to it.</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/1*xMg6bjg2kxydfO32r5R2Lw.png" /></figure><h3>🧭 2️⃣ The 3 Phases of Event Propagation</h3><p>When an event (like a click) happens, the browser processes it in <strong>three phases</strong>:</p><pre>window<br>  ↓<br>document<br>  ↓<br>html<br>  ↓<br>body<br>  ↓<br>div<br>  ↓<br>button (you clicked here)</pre><h3>🔹 Phase 1 — Capturing (Trickling Down)</h3><p>The event starts from the <strong>top (window)</strong> and goes <strong>down to the target</strong>.<br> Like someone walking from the roof to the room where the click happens.</p><h3>🔹 Phase 2 — Target</h3><p>The event reaches the <strong>exact element</strong> that was clicked (the button itself).</p><h3>🔹 Phase 3 — Bubbling (Going Up)</h3><p>Then the event “bubbles” back <strong>up</strong> from the target to the top.<br> So the parent &lt;div&gt;, &lt;body&gt;, and even &lt;html&gt; can all “see” that event.</p><h3>💡 3️⃣ Example: Bubbling in Action</h3><h4>HTML:</h4><pre>&lt;div id=&quot;parent&quot;&gt;<br>  &lt;button id=&quot;child&quot;&gt;Click me&lt;/button&gt;<br>&lt;/div&gt;</pre><h4>JS:</h4><pre>document.getElementById(&quot;parent&quot;).addEventListener(&quot;click&quot;, () =&gt; {<br>  console.log(&quot;Parent clicked&quot;);<br>});<br><br>document.getElementById(&quot;child&quot;).addEventListener(&quot;click&quot;, () =&gt; {<br>  console.log(&quot;Child clicked&quot;);<br>});</pre><h4>🖱️ When you click the button:</h4><pre>Child clicked<br>Parent clicked</pre><p>✅ The event first triggers on the <strong>child</strong>,<br> then <strong>bubbles up</strong> to the parent.</p><h3>🔁 4️⃣ React and Event Propagation</h3><p>React uses a <strong>synthetic event system</strong> — a wrapper around the browser’s native events to make them consistent across browsers.</p><p>But <strong>propagation still works the same</strong>!</p><h4>Example:</h4><pre>function App() {<br>  function handleParentClick() {<br>    console.log(&quot;Parent clicked&quot;);<br>  }<br><br>function handleChildClick() {<br>    console.log(&quot;Child clicked&quot;);<br>  }<br>  return (<br>    &lt;div onClick={handleParentClick}&gt;<br>      &lt;button onClick={handleChildClick}&gt;Click Me&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><h4>🖱️ Clicking the button logs:</h4><pre>Child clicked<br>Parent clicked</pre><p>Because the event bubbles up through React’s virtual DOM system.</p><h3>🚫 5️⃣ Stopping Event Propagation</h3><p>Sometimes you <strong>don’t want</strong> the parent to react to a child’s event.</p><h4>You can stop the bubbling using:</h4><pre>event.stopPropagation();</pre><h4>Example:</h4><pre>function App() {<br>  function handleParentClick() {<br>    console.log(&quot;Parent clicked&quot;);<br>  }<br>function handleChildClick(e) {<br>    e.stopPropagation();<br>    console.log(&quot;Child clicked&quot;);<br>  }<br>  return (<br>    &lt;div onClick={handleParentClick}&gt;<br>      &lt;button onClick={handleChildClick}&gt;Click Me&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><h4>🖱️ Now, clicking the button only logs:</h4><pre>Child clicked</pre><h3>⚠️ 6️⃣ What can cause event propagation issues?</h3><ol><li><strong>Nested event listeners</strong> (like parent &amp; child both have onClick).</li><li><strong>Not using </strong><strong>stopPropagation()</strong> when you should.</li><li><strong>Accidentally stopping propagation</strong> when you shouldn’t (breaking other features).</li><li><strong>Event delegation</strong> — where you rely on bubbling to handle many child elements from one parent listener.</li></ol><h3>🎯 7️⃣ The Effect of Event Propagation</h3><p>✅ <strong>Pros:</strong></p><ul><li>Enables <strong>event delegation</strong> → attach one listener to a parent instead of many children.</li><li>Efficient — React attaches events at the <strong>root</strong>, not on every single element.</li></ul><p>❌ <strong>Cons:</strong></p><ul><li>It can cause <strong>unexpected multiple triggers</strong> if you forget how bubbling works.</li><li>Need to manually control flow with stopPropagation() or preventDefault().</li></ul><h3>🧭 8️⃣ Summary Table</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*J1HbMZpz5uF5NP71S7mKYQ.png" /></figure><p>Maybe you are asking now</p><h3>🔁 When to use stopPropagation()</h3><p>Use it when you <strong>don’t want parent elements to react</strong> to an event that happened inside their child.</p><h3>✅ Example 1: A modal with a background</h3><p>You want to close the modal when you click the background,<br> but <strong>not</strong> when you click inside the modal content.</p><pre>function Modal({ onClose }) {<br>  return (<br>    &lt;div className=&quot;backdrop&quot; onClick={onClose}&gt;<br>      &lt;div<br>        className=&quot;modal-content&quot;<br>        onClick={(e) =&gt; e.stopPropagation()}<br>      &gt;<br>        &lt;h2&gt;Modal&lt;/h2&gt;<br>        &lt;p&gt;Clicking here shouldn&#39;t close the modal!&lt;/p&gt;<br>      &lt;/div&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>🧠 Here’s what happens:</p><ul><li>Click on backdrop → triggers onClose → closes modal.</li><li>Click inside the modal → stopPropagation() stops the event → doesn’t bubble to backdrop.</li></ul><p>✅ That’s the perfect use case.</p><h3>✅ Example 2: Nested interactive elements</h3><p>You have a parent with a click handler <strong>and</strong> a button inside it that should do something different.</p><pre>function Card() {<br>  function handleCardClick() {<br>    console.log(&quot;Card clicked&quot;);<br>  }<br><br>function handleButtonClick(e) {<br>    e.stopPropagation();<br>    console.log(&quot;Button clicked&quot;);<br>  }<br>  return (<br>    &lt;div onClick={handleCardClick}&gt;<br>      &lt;button onClick={handleButtonClick}&gt;Click&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><h4>🖱️ Clicking the button now only prints:</h4><pre>Button clicked</pre><p>without also triggering &quot;Card clicked&quot; — because you <strong>stopped the event</strong> from bubbling.</p><h3>🚫 4️⃣ When you should not use stopPropagation()</h3><p>Avoid it when:</p><ol><li>You’re handling <strong>global behaviours</strong> (like closing dropdowns when clicking anywhere else). You might accidentally block those global listeners.</li><li>You don’t need to — React’s event system is already optimised.</li><li>It hides bugs (you’re “silencing” something instead of understanding why it bubbles).</li></ol><p>In short:</p><blockquote><em>❌ Don’t use </em><em>stopPropagation() to fix a logic bug.<br> ✅ Only use it when you </em>intentionally<em> need to isolate an event.</em></blockquote><h3>💡 5️⃣ Important: Event target vs where it’s attached</h3><p>Let’s say:</p><pre>&lt;div onClick={handleParentClick}&gt;<br>  &lt;button onClick={handleButtonClick}&gt;Click&lt;/button&gt;<br>&lt;/div&gt;</pre><ul><li><strong>Clicking the button</strong> → triggers both handlers (button, then div — bubbling phase).</li><li><strong>Clicking the div (outside button)</strong> → triggers only handleParentClick.</li></ul><p>So, the <strong>event target</strong> is where you actually clicked,<br> But <strong>propagation</strong> allows parent listeners to fire <em>afterwards</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*0n8-XUx-wA6dW9ayKXH70Q.png" /></figure><h3>Recall</h3><p>This is what happens when you click a button, even when travelling from <strong>top </strong>to <strong>bottom</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4D61kPhp34pAcBQYODcbCw.png" /></figure><h4>Bubbles up</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/982/1*F5V2PKYAHZJMrtTTBtjxyg.png" /></figure><h3>💧 Life Example: for a better understanding</h3><p>Imagine you throw a <strong>small stone</strong> into a <strong>calm lake</strong> 🪨🌊.</p><p>What happens?</p><ol><li>The stone <strong>hits one small spot</strong> first — <em>that’s the event starting point</em> (like clicking a button).</li><li>Then, <strong>ripples</strong> start spreading outward — <strong>small circle → bigger circle → even bigger circle</strong>.</li><li>Each ripple touches a wider area — just like the event moves <strong>from the target element up to its parent, then grandparent, and so on</strong>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*5wVqwFYSnS8r1FxpXP3GgQ.png" /></figure><h3>🔍🧠 addEventListener() under the hood</h3><h3>💡 What it is:</h3><p>addEventListener() is a <strong>built-in DOM method</strong> in plain JavaScript used to <strong>attach an event handler</strong> (function) to an element.</p><p>So when something happens — like a click, scroll, input, etc. — the function you attached will run.</p><pre>element.addEventListener(eventType, handler, options);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/709/1*S4iWFb2fY78x2hXD3oPtBA.png" /></figure><h3>🧩 Example:</h3><pre>const btn = document.querySelector(&quot;button&quot;);<br>btn.addEventListener(&quot;click&quot;, function (event) {<br>  console.log(&quot;Button clicked!&quot;);<br>});</pre><p>✅ When you click the button → &quot;Button clicked!&quot; logs in the console.</p><h3>🧠 Optional third parameter (options)</h3><p>You can control how and when the listener fires:</p><pre>element.addEventListener(&quot;click&quot;, handler, {<br>  capture: false, // default = bubbling phase<br>  once: true,     // handler runs once only<br>  passive: true   // improves performance for scroll/touch<br>});</pre><p>OR you can pass true instead of an object:</p><pre>element.addEventListener(&quot;click&quot;, handler, true); // capture phase</pre><h3>🔁 2. stopPropagation()</h3><h3>💡 What it is:</h3><p>A <strong>method</strong> available on the <strong>event object</strong> (event.stopPropagation()).</p><p>It tells the browser:</p><blockquote><em>“Stop this event from moving further up (or down) the DOM tree.”</em></blockquote><h3>🧱 Syntax:</h3><pre>event.stopPropagation();</pre><h3>⚙️ Example:</h3><pre>&lt;div class=&quot;parent&quot;&gt;<br>  &lt;button class=&quot;child&quot;&gt;Click me&lt;/button&gt;<br>&lt;/div&gt;<br>&lt;script&gt;<br>  const parent = document.querySelector(&quot;.parent&quot;);<br>  const child = document.querySelector(&quot;.child&quot;);<br>  parent.addEventListener(&quot;click&quot;, () =&gt; {<br>    console.log(&quot;Parent clicked&quot;);<br>  });<br>  child.addEventListener(&quot;click&quot;, (event) =&gt; {<br>    event.stopPropagation(); // stop the bubbling here!<br>    console.log(&quot;Child clicked&quot;);<br>  });<br>&lt;/script&gt;</pre><h3>🧩 Output when clicking the button:</h3><pre>Child clicked</pre><blockquote><em>“Parent clicked” won’t run because the event stopped bubbling upward.</em></blockquote><h3>🧩 . Summary</h3><p>In this article, we explored how React brings JavaScript’s fundamentals to life inside your UI:</p><ul><li><strong>map()</strong> helps React efficiently render dynamic lists by transforming data into JSX.</li><li><strong>Props</strong> connect components, allowing information and behaviour to flow in one direction — from parent to child.</li><li><strong>Event handling &amp; propagation</strong> show how React listens, manages, and optimises user interactions using its synthetic event system.</li></ul><h4>If you feel like you missed any concept, don’t hesitate to reach out — your feedback means a lot to me! ❤️. You can also connect with me on 🌹</h4><h4><a href="https://x.com/Noransaber11">Twitter </a>| <a href="https://www.linkedin.com/in/noran-saber-abdelfattah-6198471ba/">LinkedIn </a>| <a href="https://github.com/Noransaber">GitHub</a> | <a href="https://www.facebook.com/noran.abdelfattah.2025">Facebook</a><br> — Noran 🌹</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52cd1d4260c4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>