<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hayk Sargsyan</title>
    <description>The latest articles on DEV Community by Hayk Sargsyan (@hayk_sargsyan_d4ff5b456d3).</description>
    <link>https://dev.to/hayk_sargsyan_d4ff5b456d3</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2480673%2Ff37a242e-a159-42c9-a8d4-270747790290.jpg</url>
      <title>DEV Community: Hayk Sargsyan</title>
      <link>https://dev.to/hayk_sargsyan_d4ff5b456d3</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hayk_sargsyan_d4ff5b456d3"/>
    <language>en</language>
    <item>
      <title>Why JavaScript Engineers are Secretly C# Masters</title>
      <dc:creator>Hayk Sargsyan</dc:creator>
      <pubDate>Mon, 09 Mar 2026 16:45:25 +0000</pubDate>
      <link>https://dev.to/playfulprogramming/why-javascript-engineers-are-secretly-c-masters-3d7l</link>
      <guid>https://dev.to/playfulprogramming/why-javascript-engineers-are-secretly-c-masters-3d7l</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fotxp76lnqfmirwwbgw82.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fotxp76lnqfmirwwbgw82.jpg" alt="House" width="800" height="640"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Photo by &lt;a href="https://unsplash.com/@ndcphoto" rel="noopener noreferrer"&gt;Denis N.&lt;/a&gt; on &lt;a href="https://unsplash.com/s/photos/architectural-buildings?asset=%5B%22Photos%22%2C%7B%22slug%22%3A%22a-building-with-a-clock-on-the-top-of-it-j2Zzr8uIQZw%22%7D%5D" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For a professional JavaScript developer, moving to TypeScript often feels like "cleaning up the room." But for those who look closer, TypeScript isn't just JavaScript with types; it is the spiritual successor to C# for the web. Understanding this connection is the shortcut to mastering backend architecture and high-scale systems.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Hejlsberg Lineage
&lt;/h2&gt;

&lt;p&gt;The most critical secret is that both languages share a father: &lt;strong&gt;Anders Hejlsberg.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hejlsberg led the design of C# at Microsoft before creating TypeScript in 2012.&lt;/li&gt;
&lt;li&gt;Because of this, the "feel" of the languages, how they handle generics, interfaces, and asynchronous patterns - is nearly identical.&lt;/li&gt;
&lt;li&gt;Learning TypeScript is, in many ways, an onboarding process for modern C# and .NET.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Write Once, Understand Both
&lt;/h2&gt;

&lt;p&gt;If you can read complex TypeScript, you can already read 80% of modern C#.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Async/Await:&lt;/strong&gt; Both languages use the exact same keywords and mental model for non-blocking I/O.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Access Modifiers:&lt;/strong&gt; Keywords like public, private, and protected function similarly in both environments to enforce encapsulation.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Arrow Functions vs. Lambdas:&lt;/strong&gt; What you call an "arrow function" in JS, a C# dev calls a "lambda expression" using the same =&amp;gt; token.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Generics:&lt;/strong&gt; The syntax for reusable components - List in C# and Array in TS - is virtually interchangeable.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdtrahy6zioaqypai6pgg.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdtrahy6zioaqypai6pgg.jpg" alt="DNA Digitak" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Photo by &lt;a href="https://unsplash.com/@mjh_shikder" rel="noopener noreferrer"&gt;MJH SHIKDER&lt;/a&gt; on &lt;a href="https://unsplash.com/s/photos/Digital-DNA?asset=%5B%22Photos%22%2C%7B%22slug%22%3A%22a-close-up-of-a-cell-phone-with-a-blurry-background--bJj_81Zois%22%7D%5D" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The "Erasure" vs. "Reified" Distinction
&lt;/h2&gt;

&lt;p&gt;The realization for engineers is understanding where they diverge: &lt;strong&gt;The Runtime&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;TypeScript uses Type Erasure. Types exist only at compile-time to help the developer, once it hits the browser/server, it’s just "naked" JavaScript.&lt;/li&gt;
&lt;li&gt;C# uses Reified Types. Type metadata stays with the code at runtime, allowing for powerful features like Reflection (inspecting code at runtime) that TypeScript cannot do natively.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Full-Stack Bridge
&lt;/h2&gt;

&lt;p&gt;Engineers use this connection to bridge the gap between frontend and backend.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Frameworks like Nest.js (Node.js) are explicitly modeled after ASP.NET Core (C#). If you understand one’s Dependency Injection or Controller pattern, you understand the other.&lt;/li&gt;
&lt;li&gt;The languages are actively borrowing from each other. C# recently added Pattern Matching, while JavaScript/TypeScript adopted Decorators, a staple of C# attributes for years.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The "lift" from TypeScript to C# is often smaller and more productive than moving to Go or Rust because the mental model remains consistent.&lt;/p&gt;

&lt;h2&gt;
  
  
  The "Awaitable" Pattern
&lt;/h2&gt;

&lt;p&gt;Both languages implement asynchronous programming using a virtually identical mental and syntactic model: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A JavaScript Promise and a C# Task are ideologically equivalent, representing an ongoing operation that will complete in the future.&lt;/li&gt;
&lt;li&gt;Both use the async and await keywords to flatten asynchronous callbacks into a synchronous-looking flow.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fex8gisiaenw30gotv459.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fex8gisiaenw30gotv459.jpg" alt="Pathway" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Photo by &lt;a href="https://unsplash.com/@pokornymichal" rel="noopener noreferrer"&gt;Michal Pokorný&lt;/a&gt; on &lt;a href="https://unsplash.com/s/photos/Bridges-and-Pathways%3A?asset=%5B%22Photos%22%2C%7B%22slug%22%3A%22a-wooden-bridge-with-a-wire-fence-over-it--C3Q3vw6MSU%22%7D%5D" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The symmetry between C# and TypeScript represents a calculated evolution of industrial-scale engineering. By sharing a primary architect, both languages have aligned on a specific "developer ergonomics" that prioritizes predictability, maintainability, and architectural discipline.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>React Concurrent Model is unstoppable</title>
      <dc:creator>Hayk Sargsyan</dc:creator>
      <pubDate>Thu, 22 Jan 2026 11:42:14 +0000</pubDate>
      <link>https://dev.to/hayk_sargsyan_d4ff5b456d3/-22od</link>
      <guid>https://dev.to/hayk_sargsyan_d4ff5b456d3/-22od</guid>
      <description>&lt;div class="ltag__link"&gt;
  &lt;a href="/hayk_sargsyan_d4ff5b456d3" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2480673%2Ff37a242e-a159-42c9-a8d4-270747790290.jpg" alt="hayk_sargsyan_d4ff5b456d3"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="https://dev.to/hayk_sargsyan_d4ff5b456d3/react-lanes-the-internal-engine-powering-modern-concurrent-rendering-1o5c" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;React Lanes: The Internal Engine Powering Modern Concurrent Rendering&lt;/h2&gt;
      &lt;h3&gt;Hayk Sargsyan ・ Jan 22&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#react&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#reactnative&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#javascript&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#frontend&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


</description>
      <category>react</category>
      <category>reactnative</category>
      <category>javascript</category>
      <category>frontend</category>
    </item>
    <item>
      <title>React Lanes: The Internal Engine Powering Modern Concurrent Rendering</title>
      <dc:creator>Hayk Sargsyan</dc:creator>
      <pubDate>Thu, 22 Jan 2026 09:32:39 +0000</pubDate>
      <link>https://dev.to/playfulprogramming/react-lanes-the-internal-engine-powering-modern-concurrent-rendering-1o5c</link>
      <guid>https://dev.to/playfulprogramming/react-lanes-the-internal-engine-powering-modern-concurrent-rendering-1o5c</guid>
      <description>&lt;p&gt;We use React every day, but we haven’t been paying enough attention to one of the most important aspects of it: how React has evolved since v16, how the new concurrent model works.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkwzvor8krzrrsrscv8gt.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkwzvor8krzrrsrscv8gt.jpg" alt="Unstoppable" width="800" height="532"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Photo by &lt;a href="https://unsplash.com/@timmossholder" rel="noopener noreferrer"&gt;Tim Mossholder&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/red-blue-and-yellow-abstract-painting-tq8Cuap8_wY" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Wow.. React is unstoppable!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  The Great Rewrite of v16
&lt;/h2&gt;

&lt;p&gt;Before we talk about Lanes, we must acknowledge the foundation. In 2017, React v16 introduced Fiber, a complete rewrite of the reconciliation engine. Before Fiber, React used a "stack-based" reconciler that processed updates synchronously - once a render started, it couldn't be stopped until it finished. &lt;br&gt;
Fiber changed the game by introducing a linked-list tree structure that allowed React to break rendering into small units of work. This was the birth of &lt;strong&gt;Incremental Rendering&lt;/strong&gt;: the ability to pause work, yield to the browser for a high-priority task (like a user click), and then resume. &lt;/p&gt;
&lt;h2&gt;
  
  
  From Expiration Times to Lanes
&lt;/h2&gt;

&lt;p&gt;Initially, Fiber used a linear "Expiration Time" model to prioritize work: the longer an update waited, the higher its priority. However, this model struggled with "IO-bound" updates where different tasks needed to be handled in separate "streams" without blocking each other. &lt;br&gt;
In 2026, we don't just use Fiber; we use React Lanes. This is a 31-bit bitmask system that allows React to manage multiple updates with granular precision. Instead of a single "time to expire," React assigns updates to specific lanes (like a highway), allowing it to&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;OR (|)&lt;/code&gt; for Merging: When multiple state updates occur, React doesn't store them in an array. It merges them into a single pendingLanes integer using &lt;code&gt;a | b&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;AND (&amp;amp;)&lt;/code&gt; for Filtering: To check if a specific work cycle includes a particular priority, React uses &lt;code&gt;(pendingLanes &amp;amp; SyncLane) !== NoLane&lt;/code&gt;. &lt;/li&gt;
&lt;li&gt;Interrupt a low-priority "Transition Lane" (e.g., loading a search result) to process a "Sync Lane" (e.g., the user typing).&lt;/li&gt;
&lt;li&gt;Merge tasks to ensure that the UI remains consistent across disparate state changes. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;But why are bitmasks used?&lt;/strong&gt; Because this allows React to use bitwise operators &lt;code&gt;(&amp;amp;, |, ~)&lt;/code&gt; to merge or filter updates in constant time &lt;code&gt;O(1)&lt;/code&gt; rather than iterating through arrays.&lt;/p&gt;

&lt;p&gt;Because updates are grouped, React can pause a low-priority render (like a heavy data list) to handle a high-priority "SyncLane" event immediately. Once the urgent work is done, it resumes the lower-priority work using the same lane state.&lt;/p&gt;

&lt;p&gt;A common issue with priority-based systems is &lt;strong&gt;starvation&lt;/strong&gt;, where low-priority tasks (like an idle background task) never run because the user is constantly interacting with high-priority tasks (&lt;strong&gt;SyncLanes&lt;/strong&gt;).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;React tracks how long each lane has been pending. If a lane remains in the &lt;strong&gt;pendingLanes&lt;/strong&gt; mask for too long, it "expires".&lt;/li&gt;
&lt;li&gt;React then automatically merges that expired lane into the next SyncLane pass. This "promotes" the task, forcing it to render even if higher-priority work is still coming in, ensuring the UI eventually becomes consistent. &lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  Hierarchical Propagation (childLanes)
&lt;/h3&gt;

&lt;p&gt;Merging isn't just about combining updates, it's about &lt;strong&gt;signaling&lt;/strong&gt;. When a child component has a pending update, its lane is merged into its parent's &lt;strong&gt;childLanes&lt;/strong&gt; field. &lt;br&gt;
This propagates all the way up to the Root Fiber.&lt;br&gt;
During a render pass, if a parent component's lanes and childLanes bitwise intersection with the current "render lane" is zero (NoLanes), React can instantly skip (bail out) the entire subtree. It knows with 100% certainty that no urgent work exists below that point. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnnlt8qo5jvjqlwe4g5in.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnnlt8qo5jvjqlwe4g5in.jpg" alt="I'm getting stronger with React" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Photo by &lt;a href="https://unsplash.com/@brucetml" rel="noopener noreferrer"&gt;Bruce Tang&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/white-and-gray-robot-during-daytime-nKO_1QyFh9o" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I'm getting stronger!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;
  
  
  The Hierarchy of Lanes
&lt;/h2&gt;

&lt;p&gt;React defines several categories of lanes to handle different types of user and system work: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;SyncLane&lt;/strong&gt;: Highest priority. Reserved for discrete user events like clicks and key presses that require immediate feedback.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;InputContinuousLane&lt;/strong&gt;: Used for continuous interactions like scrolling or mouse movement.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DefaultLane&lt;/strong&gt;: The standard priority for general setState updates.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TransitionLanes&lt;/strong&gt;: A set of 16 different lanes specifically for useTransition and startTransition. These are interruptible and can be processed in parallel.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IdleLane&lt;/strong&gt;: Lowest priority for background tasks or offscreen content. &lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  useTransition vs. useDeferredValue
&lt;/h2&gt;

&lt;p&gt;As engineers, we must view these hooks not as "performance boosters," but as manual lane selectors for React's scheduler. Both hooks leverage Transition Lanes to move non-urgent work out of the SyncLane, preventing heavy renders from blocking user input.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;useTransition&lt;/strong&gt; (Imperative Orchestration): Use this when you have direct access to the state-updating code (e.g., setSearchTerm). By wrapping the update in startTransition, you explicitly tell React to assign this task a lower-priority lane. This is ideal for major UI shifts, like switching tabs or filtering lists, where you can also use the isPending flag to show a "Loading..." state. 
(&lt;a href="https://react.dev/reference/react/useTransition" rel="noopener noreferrer"&gt;https://react.dev/reference/react/useTransition&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  The problem: The Heavy Data Dashboard
&lt;/h3&gt;

&lt;p&gt;Imagine an enterprise dashboard where clicking a "Global Analytics" tab triggers a massive re-render involving thousands of data points or complex SVG charts. &lt;/p&gt;

&lt;p&gt;Without useTransition (Blocking):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;User clicks the "Analytics" tab.&lt;/li&gt;
&lt;li&gt;React triggers an urgent state update.&lt;/li&gt;
&lt;li&gt;The JavaScript main thread is locked for 500ms while React calculates the massive chart.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The Problem:&lt;/strong&gt; If the user suddenly realizes they clicked the wrong tab and clicks "Home," the browser won't respond until the Analytics render finishes. The UI feels "frozen".&lt;/p&gt;
&lt;h3&gt;
  
  
  With useTransition (Concurrent/Interruptible):
&lt;/h3&gt;

&lt;p&gt;We wrap the tab-switching logic in startTransition. This moves the "Analytics" render into a lower-priority Transition Lane.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;isPending&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;startTransition&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useTransition&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;tab&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setTab&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;home&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;handleTabChange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nextTab&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// 1. High-priority: UI stays responsive to the next click&lt;/span&gt;

  &lt;span class="nf"&gt;startTransition&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// 2. Low-priority: This heavy render can be INTERRUPTED&lt;/span&gt;
    &lt;span class="nf"&gt;setTab&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;nextTab&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;nav&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;TabButton&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;handleTabChange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;analytics&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;isPending&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Spinner&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Analytics&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;TabButton&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;TabButton&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setTab&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;home&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Home&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;TabButton&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;nav&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;useDeferredValue&lt;/strong&gt; (Declarative Buffering): Use this when a value is passed down as a prop and you have no control over the source setState call. It creates a "lagging mirror" of a value. React will first re-render the UI with the old value (keeping the input responsive) and then, in the background, schedule a separate render for the new value in a Transition Lane. 
(&lt;a href="https://react.dev/reference/react/useDeferredValue" rel="noopener noreferrer"&gt;https://react.dev/reference/react/useDeferredValue&lt;/a&gt;)
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;          &lt;span class="nx"&gt;r&lt;/span&gt; &lt;span class="err"&gt;→&lt;/span&gt; &lt;span class="nx"&gt;re&lt;/span&gt; &lt;span class="err"&gt;→&lt;/span&gt; &lt;span class="nx"&gt;rea&lt;/span&gt; &lt;span class="err"&gt;→&lt;/span&gt; &lt;span class="nx"&gt;reac&lt;/span&gt; &lt;span class="err"&gt;→&lt;/span&gt; &lt;span class="nx"&gt;react&lt;/span&gt;
&lt;span class="nx"&gt;deferredQuery&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="dl"&gt;""&lt;/span&gt; &lt;span class="err"&gt;→&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt; &lt;span class="err"&gt;→&lt;/span&gt; &lt;span class="nx"&gt;r&lt;/span&gt; &lt;span class="err"&gt;→&lt;/span&gt; &lt;span class="nx"&gt;re&lt;/span&gt; &lt;span class="err"&gt;→&lt;/span&gt; &lt;span class="nx"&gt;react&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The problem: expensive filtering blocks typing
&lt;/h3&gt;

&lt;p&gt;Imagine a list with 10,000 items.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Search&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setQuery&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;filteredItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt;
        &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="na"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;List&lt;/span&gt; &lt;span class="na"&gt;items&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;filteredItems&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  What goes wrong?
&lt;/h3&gt;

&lt;p&gt;setQuery triggers a re-render on every keystroke&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;filter() runs every time&lt;/li&gt;
&lt;li&gt;Large lists = input lag&lt;/li&gt;
&lt;li&gt;Typing feels “sticky”&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now let’s introduce &lt;strong&gt;useDeferredValue&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useDeferredValue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Search&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setQuery&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;deferredQuery&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useDeferredValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;filteredItems&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;items&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;item&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class="nx"&gt;item&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;deferredQuery&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt;
        &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
        &lt;span class="na"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setQuery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;List&lt;/span&gt; &lt;span class="na"&gt;items&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;filteredItems&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What changed? Only one thing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;query&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;deferredQuery&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  While the user is typing:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Query updates immediately (high priority)&lt;/li&gt;
&lt;li&gt;Input stays smooth&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Meanwhile:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;deferredQuery lags behind&lt;/li&gt;
&lt;li&gt;Filtering runs less often&lt;/li&gt;
&lt;li&gt;React schedules it as low priority&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Concurrent Model: Standardized in 2026
&lt;/h2&gt;

&lt;p&gt;While Concurrent Mode was once an experimental opt-in, as we move through 2026, it is the default paradigm for high-performance React architecture. With React 19 now fully established, features like &lt;code&gt;startTransition&lt;/code&gt;, &lt;code&gt;useDeferredValue&lt;/code&gt;, and automatic batching aren't just "cool tricks" - they are the primary tools we use to orchestrate the "Update Streams" that Lanes manage under the hood. &lt;/p&gt;

&lt;h3&gt;
  
  
  What’s Next: The Priority Trilogy
&lt;/h3&gt;

&lt;p&gt;Understanding Lanes is the first step in mastering React’s internal orchestration. However, Lanes are only the "logic" layer. To get the full picture of how React maintains 60fps in complex applications, we need to look at the systems on either side of the Lane bitmask.&lt;br&gt;
In my upcoming articles, I will be doing deep-dives into:&lt;br&gt;
&lt;strong&gt;The Event Priority System&lt;/strong&gt;: How React translates physical user intent (clicks vs. scrolls) into Lane requests.&lt;br&gt;
&lt;strong&gt;The Scheduler&lt;/strong&gt;: How React negotiates with the browser's main thread to execute Lane-prioritized work without dropping frames.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc8s34e05j4uz6ngxapqv.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fc8s34e05j4uz6ngxapqv.jpg" alt="Crossroads" width="800" height="421"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Photo by &lt;a href="https://unsplash.com/@loaldesign" rel="noopener noreferrer"&gt;Alex Kalinin&lt;/a&gt; on &lt;a href="https://unsplash.com/photos/birds-eye-view-photography-of-asphalt-road-in-between-trees-8bs-Kz8ACdM" rel="noopener noreferrer"&gt;Unsplash&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>reactnative</category>
      <category>javascript</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Understanding Promises and Coroutines in JavaScript</title>
      <dc:creator>Hayk Sargsyan</dc:creator>
      <pubDate>Fri, 09 May 2025 13:42:08 +0000</pubDate>
      <link>https://dev.to/playfulprogramming/understanding-promises-and-coroutines-in-javascript-50gd</link>
      <guid>https://dev.to/playfulprogramming/understanding-promises-and-coroutines-in-javascript-50gd</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbsj6jdsf0nry5opblt6g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbsj6jdsf0nry5opblt6g.png" width="800" height="800"&gt;&lt;/a&gt;&lt;br&gt;
As a JavaScript developer, you've probably heard terms like Promise, async/await, and maybe even coroutines thrown around a lot. Let’s break them down in a human way - no fancy words, just real-world explanations.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is a Promise?
&lt;/h2&gt;

&lt;p&gt;Think of a Promise as a placeholder for a value that you’ll get later.&lt;br&gt;
Let’s say you order a pizza. You get a receipt — that's the promise. You don’t have the pizza yet, but the promise says, “Don’t worry, it’s coming.”&lt;br&gt;
In code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pizzaOrder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isPizzaReady&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;isPizzaReady&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Pizza is ready!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nf"&gt;reject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Sorry, no pizza today.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;pizzaOrder&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, .then() is like, “What do I do when the pizza arrives?” and .catch() is, “What if it doesn’t?”&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Do We Use Promises?
&lt;/h2&gt;

&lt;p&gt;JavaScript is single-threaded — it can do one thing at a time. Promises help us avoid blocking things while waiting for slower tasks (like API calls or timers).&lt;/p&gt;

&lt;p&gt;Instead of freezing the app, Promises let JavaScript say, “I’ll come back to this when it’s ready,” and keep moving.&lt;/p&gt;

&lt;h2&gt;
  
  
  Async/Await = Cleaner Promises
&lt;/h2&gt;

&lt;p&gt;Dealing with .then() and .catch() can get messy, especially with many steps.&lt;br&gt;
So, JavaScript gave us a cleaner syntax: async and await.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;makeDinner&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pizza&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;pizzaOrder&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pizza&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// "Pizza is ready!"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;await tells JavaScript to pause until the promise is done — but it only works inside an async function.&lt;br&gt;
This is where things start to feel like “coroutines.”&lt;/p&gt;
&lt;h2&gt;
  
  
  What’s a Coroutine?
&lt;/h2&gt;

&lt;p&gt;In simple terms, a coroutine is a function that can pause and resume its execution.&lt;br&gt;
JavaScript doesn’t have built-in coroutines like Python does with yield, but async/await gives us similar power.&lt;br&gt;
With await, your function looks synchronous (step-by-step), but it actually runs asynchronously under the hood.&lt;/p&gt;
&lt;h2&gt;
  
  
  Coroutine Mechanics via Generators
&lt;/h2&gt;

&lt;p&gt;Yielding Values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nf"&gt;greeter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hi&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Bye&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;it&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;greeter&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;it&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// { value: "Hi", done: false }&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;it&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// { value: "Hello", done: false }&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;it&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt; &lt;span class="c1"&gt;// { value: "Bye", done: true }&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can send values back into a coroutine using next(value).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;async/await is JavaScript's native coroutine syntax. It abstracts away yield and generator handling.&lt;/strong&gt;&lt;br&gt;
Under the hood, async functions return a Promise and behave like auto-resuming coroutines.&lt;/p&gt;

&lt;h2&gt;
  
  
  When Should You Use Promises or Async/Await?
&lt;/h2&gt;

&lt;p&gt;Use Promise when:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You want a task to run in the background.&lt;/li&gt;
&lt;li&gt;You need to chain steps (.then().then().catch()).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Use async/await when:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You want cleaner, more readable async code.&lt;/li&gt;
&lt;li&gt;You need to handle multiple async tasks step-by-step.&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;Promises and async/await make writing asynchronous code in JavaScript a lot easier than it used to be. Think of them as your way to say, “Do this thing, but let’s not freeze the app while we wait.”&lt;/p&gt;

&lt;p&gt;If you're comfortable with Promises and async/await, you already know how to use coroutines - even if JavaScript doesn’t officially call them that.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Official Goodbye: The End of an Era for Create React App</title>
      <dc:creator>Hayk Sargsyan</dc:creator>
      <pubDate>Sun, 16 Feb 2025 08:47:36 +0000</pubDate>
      <link>https://dev.to/playfulprogramming/official-goodbye-the-end-of-an-era-for-create-react-app-2a2i</link>
      <guid>https://dev.to/playfulprogramming/official-goodbye-the-end-of-an-era-for-create-react-app-2a2i</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9bydyfs9zedurybmit8e.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9bydyfs9zedurybmit8e.jpg" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
Hi! &lt;br&gt;
A New Era Begins in the History of React.js!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Today, we’re deprecating Create React App for new apps, and encouraging existing apps to migrate to a framework. We’re also providing docs for when a framework isn’t a good fit for your project, or you prefer to start by building a framework.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As of February 13 2025, the recommended way to start a new React project is by using a &lt;strong&gt;framework&lt;/strong&gt; that integrates seamlessly with React's architecture.&lt;/p&gt;

&lt;p&gt;There are already involved variants of frameworks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Next.js&lt;/li&gt;
&lt;li&gt;React Router&lt;/li&gt;
&lt;li&gt;Expo&lt;/li&gt;
&lt;li&gt;Custom Builder&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Next.js (App Router)&lt;/strong&gt;&lt;br&gt;
Next.js’s App Router is a React framework that takes full advantage of React’s architecture to enable full-stack React apps.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-next-app@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;React Router (v7)&lt;/strong&gt; &lt;br&gt;
React Router is the most popular routing library for React and can be paired with Vite to create a full-stack React framework. It emphasizes standard Web APIs and has several ready to deploy templates for various JavaScript runtimes and platforms.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-router@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Expo (for native apps)&lt;/strong&gt; &lt;br&gt;
Expo is a React framework that lets you create universal Android, iOS, and web apps with truly native UIs. It provides an SDK for React Native that makes the native parts easier to use. To create a new Expo project, run.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-expo-app@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can build your custom framework according instructions &lt;a href="https://react.dev/learn/building-a-react-framework" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Unlocking the Power of React Server Components | Part 1</title>
      <dc:creator>Hayk Sargsyan</dc:creator>
      <pubDate>Tue, 26 Nov 2024 12:55:01 +0000</pubDate>
      <link>https://dev.to/playfulprogramming/unlocking-the-power-of-react-server-components-part-1-1jgc</link>
      <guid>https://dev.to/playfulprogramming/unlocking-the-power-of-react-server-components-part-1-1jgc</guid>
      <description>&lt;p&gt;👋 Hi, everyone!&lt;br&gt;
React.js is one of the most popular JavaScript libraries for building user interfaces. While the React community well-documented, there are still some lesser-known themes and concepts.&lt;br&gt;
&lt;strong&gt;Let's make tea or coffee, let's go!&lt;/strong&gt;&lt;br&gt;
React Server Components (RSC) are a new experimental feature introduced by the React team to optimize rendering performance. They allow developers to build parts of their app that are rendered on the server while still maintaining the React component model.&lt;br&gt;
It's running in a separate environment from client or SSR server, and can be called once at build time on CI server, or they can be run for each request using a web server.&lt;br&gt;
With power of React Server components we can read file content right in the our React component.&lt;br&gt;
Below, there are a simple example, how can we do it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;marked&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;marked&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Not included in bundle&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;sanitizeHtml&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sanitize-html&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Not included in bundle&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Page&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// NOTE: loads *during* render, when the app is built.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;content&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;readFile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;page&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;.md`&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;sanitizeHtml&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;marked&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;content&lt;/span&gt;&lt;span class="p"&gt;))}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The client will only see the rendered output from the file. This means the content is visible during first page load, and the bundle does not include the expensive libraries (marked, sanitize-html) needed to render the static content.&lt;/p&gt;

&lt;h2&gt;
  
  
  Server Components with a Server
&lt;/h2&gt;

&lt;p&gt;With Server Components we can communicate with database, fetch any data and use in the client. It's we can do it in Next.js applications too, integrate any ORMs.&lt;br&gt;
Below is a simple example of the usage of Server Components for fetching data from database.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./database&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Note&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// NOTE: loads *during* render.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;note&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;notes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Author&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;note&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;authorId&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;note&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Author&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// NOTE: loads *after* Note,&lt;/span&gt;
  &lt;span class="c1"&gt;// but is fast if data is co-located.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;author&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;authors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;span&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;By&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;author&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/span&amp;gt;&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In database file there can be implementation of data query from database.&lt;br&gt;
For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;notes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;dbClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;SELECT * FROM notes WHERE id = ?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;authors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;dbClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;SELECT * FROM authors WHERE id = ?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The bundler then combines the data, rendered Server Components and dynamic Client Components into a bundle. When the page loads, the browser does not see the original Note and Author components; only the rendered output is sent to the client. &lt;strong&gt;Server Components can be made dynamic by re-fetching them from a server, where they can access the data and render again.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The power of Async Components with Server Components
&lt;/h2&gt;

&lt;p&gt;Server Components introduce a new way to write Components using async/await. When you await in an async component, React will suspend and wait for the promise to resolve before resuming rendering. This works across server/client boundaries with streaming support for Suspense.&lt;br&gt;
The example of Server Component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Server Component&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./database&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Page&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Will suspend the Server Component.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;note&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;notes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="c1"&gt;// NOTE: not awaited, will start here and await on the client. &lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;commentsPromise&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;db&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;comments&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;note&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;div&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;note&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Suspense&lt;/span&gt; &lt;span class="nx"&gt;fallback&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Loading&lt;/span&gt; &lt;span class="nx"&gt;Comments&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&amp;gt;}&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;        &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Comments&lt;/span&gt; &lt;span class="nx"&gt;commentsPromise&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;commentsPromise&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;      &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/Suspense&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;    &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/div&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Client Component&lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;use client&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;use&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Comments&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="nx"&gt;commentsPromise&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// NOTE: this will resume the promise from the server.&lt;/span&gt;
  &lt;span class="c1"&gt;// It will suspend until the data is available.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;comments&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;commentsPromise&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;comments&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;commment&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;comment&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/p&amp;gt;&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="err"&gt;;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The comments are lower-priority, so we start the promise on the server, and wait for it on the client with the *&lt;em&gt;use *&lt;/em&gt; API. This will Suspend on the client, without blocking the note content from rendering.&lt;/p&gt;

&lt;p&gt;In next parts, we will discuss Server Actions and Directives ("use client", "use server") power, and why "use server" doesn't have same role as "use client"🤔 &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;See you soon!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;While Server Components are still in the experimental phase, they are slowly gaining attention for their potential to improve large-scale applications. They eliminate the need for unnecessary JavaScript to be sent to the client, which results in faster loading times and a smoother user experience.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>web</category>
      <category>news</category>
    </item>
  </channel>
</rss>
