<?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: Afzal Imdad</title>
    <description>The latest articles on DEV Community by Afzal Imdad (@afzalimdad9).</description>
    <link>https://dev.to/afzalimdad9</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%2F1278171%2F527f2357-36c3-41df-8ca7-c8e85a31cb05.jpeg</url>
      <title>DEV Community: Afzal Imdad</title>
      <link>https://dev.to/afzalimdad9</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/afzalimdad9"/>
    <language>en</language>
    <item>
      <title>Why I chose Zed over Visual Studio Code</title>
      <dc:creator>Afzal Imdad</dc:creator>
      <pubDate>Fri, 26 Dec 2025 18:14:34 +0000</pubDate>
      <link>https://dev.to/afzalimdad9/why-i-chose-zed-over-visual-studio-code-41fb</link>
      <guid>https://dev.to/afzalimdad9/why-i-chose-zed-over-visual-studio-code-41fb</guid>
      <description>&lt;p&gt;I often see mixed reviews about using Zed instead of Visual Studio Code . Some people are extremely enthusiastic about Zed’s speed, while others are dissatisfied because they don’t have the vast plugin ecosystem of VS Code.&lt;/p&gt;

&lt;p&gt;In all of this, I would like to share my experience.&lt;/p&gt;

&lt;p&gt;In the development world, choosing a code editor is an almost sacred decision, one of those personal preferences that can ignite endless arguments.&lt;/p&gt;

&lt;p&gt;For years, Visual Studio Code has been my trusted companion, an undisputed behemoth offering almost unlimited flexibility and power. Yet, recently, I made a choice that might seem like a step backwards to some: I switched to Zed.&lt;/p&gt;

&lt;p&gt;And I’ll explain why this decision, for me, was the most logical and productive.&lt;/p&gt;

&lt;h2&gt;
  
  
  When less is really more
&lt;/h2&gt;

&lt;p&gt;In the past, my work focused primarily on web development with PHP, HTML, CSS, and MySQL, along with teaching. For this reason, I was always looking for tools that could be used on Mac, Windows, and Linux.&lt;/p&gt;

&lt;p&gt;Today, more out of passion or the needs of some old clients, I occasionally update existing projects. I no longer need an arsenal of complex tools or features that extend to machine learning or desktop application development.&lt;/p&gt;

&lt;p&gt;My primary need is just one: an agile, fast development environment that doesn’t get between me and the code.&lt;/p&gt;

&lt;p&gt;Visual Studio Code, with its vast ecosystem of extensions, can do practically anything. But this incredible versatility is also its greatest burden.&lt;/p&gt;

&lt;p&gt;Over time, I felt it becoming increasingly “large,” a transatlantic liner where all I needed was a fast motorboat to navigate my projects. Startup was no longer instantaneous, and resource consumption, though optimized, was taking its toll.&lt;/p&gt;

&lt;p&gt;This is where Zed came into play.&lt;/p&gt;

&lt;p&gt;The difference in performance was obvious from the first moment. Zed is incredibly lightweight and responsive. Opening files, global searches, and the overall fluidity of the interface gave me a sense of immediacy I’d forgotten.&lt;/p&gt;

&lt;h2&gt;
  
  
  A focused focus on my workflow
&lt;/h2&gt;

&lt;p&gt;Zed’s philosophy seems almost tailored to my needs. Being a relatively new editor, it doesn’t claim to be a “jack of all trades.” Its feature set is essential, clean, and focused on what you really need to write code.&lt;/p&gt;

&lt;p&gt;For my tech stack, this simplicity is a strength, not a weakness.&lt;/p&gt;

&lt;p&gt;Of course, Zed’s maturity is still a work in progress. The plugin ecosystem, for example, isn’t even close to that of VS Code. I’d like the plugins for PHP, HTML, and CSS to be more complete and refined, perhaps with the same level of development found on Microsoft’s platform.&lt;/p&gt;

&lt;p&gt;Become a member&lt;br&gt;
But honestly, this isn’t a problem that’s holding me back. Zed is growing rapidly, and its community is active and promising. I’m confident that, with time, these shortcomings will be overcome.&lt;/p&gt;

&lt;h2&gt;
  
  
  Zed vs. VS Code: The Differences That Matter
&lt;/h2&gt;

&lt;p&gt;Ignoring for a moment the features we now take for granted (such as debugging, Git integration, or AI assistance), I find these aspects particularly interesting:&lt;/p&gt;

&lt;h3&gt;
  
  
  Zed:
&lt;/h3&gt;

&lt;p&gt;Speed&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; , Extremely fast and lightweight, thanks to the use of Rust and GPU rendering.&lt;/li&gt;
&lt;li&gt;Minimalism: Clean, distraction-free interface designed for maximum focus on your code.&lt;/li&gt;
&lt;li&gt;Collaboration: Natively integrated code sharing and collaborative editing capabi
lities.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  VS Code:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Flexibility: Highly customizable, although this can lead to a more chaotic environment.&lt;/li&gt;
&lt;li&gt;Extensibility: Large and mature ecosystem, with thousands of extensions for almost every need imaginable.&lt;/li&gt;
&lt;li&gt;Comprehensiveness: It is a tool that adapts to any language, framework or platform.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  The choice of the editor is not a competition, but a question of context
&lt;/h4&gt;

&lt;p&gt;We often fall into the trap of looking for the “best” editor. The truth is, none exists.&lt;/p&gt;

&lt;p&gt;The choice should not be dictated only by speed, the beauty of the interface or the number of features, but by the specific use we make of it every day.&lt;/p&gt;

&lt;p&gt;VS Code remains an extraordinary tool, and for many developers with different needs than mine, it’s undoubtedly the best choice. But for me, with my focus on web development with PHP, HTML, and CSS, Zed fits the bill perfectly.&lt;/p&gt;

&lt;p&gt;It gives me exactly what I need, without frills and with a performance that allows me to focus only on what really matters: my idea and the code.&lt;/p&gt;

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

&lt;p&gt;My switch to Zed is not a rejection of Visual Studio Code, but a conscious choice based on my work context.&lt;/p&gt;

&lt;p&gt;Because the perfect editor doesn’t exist. However, there is the perfect editor for the job at hand. And for me, today, that editor is Zed.&lt;/p&gt;

&lt;p&gt;Have you also made the switch to Zed or are you considering it? Share your experience in the comments, and if this article was helpful, please give it a thumbs up!&lt;/p&gt;

</description>
      <category>vscode</category>
      <category>zed</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>New JavaScript pipeline operator: Transform anything into a one-liner 😲</title>
      <dc:creator>Afzal Imdad</dc:creator>
      <pubDate>Fri, 10 Jan 2025 23:51:39 +0000</pubDate>
      <link>https://dev.to/afzalimdad9/new-javascript-pipeline-operator-transform-anything-into-a-one-liner-31</link>
      <guid>https://dev.to/afzalimdad9/new-javascript-pipeline-operator-transform-anything-into-a-one-liner-31</guid>
      <description>&lt;p&gt;With the pipeline operator you'll stop writing code like this:&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%2F9axe0pyhsblgo8iysl5l.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%2F9axe0pyhsblgo8iysl5l.png" width="700" height="461"&gt;&lt;/a&gt;&lt;br&gt;
And start writing code like this:&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%2Fhf7pg552asa44zkny38x.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%2Fhf7pg552asa44zkny38x.png" width="700" height="590"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So refreshingly clean — and elegant! All those temporary variables are gone — not to mention the time it took to come up with those names &lt;em&gt;and&lt;/em&gt; type them (not everyone types like The Flash, unfortunately).&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%2Fxbwih9sf3zw8jyjg2ady.gif" 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%2Fxbwih9sf3zw8jyjg2ady.gif" alt="The Flash" width="374" height="374"&gt;&lt;/a&gt;&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%2F5hqryon989e6qq7a6l74.gif" 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%2F5hqryon989e6qq7a6l74.gif" alt="and a cat who types like him… apparently." width="518" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You may have heard this partially true joke attributed to Phil Karlton: "There are only two hard things in computer science: &lt;em&gt;cache invalidation and naming things&lt;/em&gt;".&lt;/p&gt;

&lt;p&gt;Using the JavaScript pipeline operator clears out the clutter to boost readability and write data-transforming code (basically all code) in a more intuitive manner.&lt;/p&gt;

&lt;p&gt;Verbosity should be avoided as much as possible, and this works so much better to compact code than reusing short-named variables:&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%2Fytodlv2eiyebz35vv869.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%2Fytodlv2eiyebz35vv869.png" width="700" height="467"&gt;&lt;/a&gt;&lt;br&gt;
Hopefully, almost no one codes like this on a regular basis. It's a pretty horrible technique when done in a large scale; a perfect example showing why we embrace immutability and type systems.&lt;/p&gt;

&lt;p&gt;Unlike the pipeline operator, there's no certainty that the variable always contains the value you set at any given point; you'll need to climb up the scope to look for re-assignments. We could have used the _ at an earlier point in the code; the value it has at various points in the code is simply not guaranteed.&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%2Fg0uqh75vygfvc9oheo51.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%2Fg0uqh75vygfvc9oheo51.png" width="700" height="428"&gt;&lt;/a&gt;&lt;br&gt;
Now we're just using an underscore, so without checking out the right-hand side of those re-assignments you can't quickly know what the type of the variable is, unless you have a smart editor like VS Code (although I guess you could say that doesn't matter since they're supposed to be "temporary" — at least until they're not!).&lt;/p&gt;

&lt;p&gt;All in all, poor readability. Fragile and Unstable. 5 times harder for someone new to understand. Also, some would say underscores are "ugly", especially in languages like JavaScript where they hardly show up.&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%2F452y6e89lw46azow12c7.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%2F452y6e89lw46azow12c7.png" alt="Image description" width="700" height="576"&gt;&lt;/a&gt;&lt;br&gt;
Okay, so why don't we just avoid this infestation of temporary underscores, and nest them into &lt;a href="https://www.codingbeautydev.com/blog/javascript-one-liners" rel="noopener noreferrer"&gt;one gigantic one-liner&lt;/a&gt;?&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%2Fu2ju8xbjsjpfhiqqn8ys.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%2Fu2ju8xbjsjpfhiqqn8ys.png" alt="Image description" width="700" height="619"&gt;&lt;/a&gt;&lt;br&gt;
It's a mess. The underscore is gone, but who in the world can understand this at a glance? How easy is it to tell how the data flows throughout this code and make any necessary adjustments?&lt;/p&gt;

&lt;p&gt;Understanding, at a glance — this is what we should strive for with every line of code we write.&lt;/p&gt;

&lt;p&gt;The pipeline operator greatly outshines every other method, giving us both freedom from temporary variables and readability. It was designed for this.&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%2F0ve53f4d5gbh8mnmxs58.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%2F0ve53f4d5gbh8mnmxs58.png" alt="Image description" width="700" height="537"&gt;&lt;/a&gt;&lt;br&gt;
Here the &lt;code&gt;%&lt;/code&gt; only exists within this particular pipeline.&lt;/p&gt;

&lt;h2&gt;
  
  
  Method chaining?
&lt;/h2&gt;

&lt;p&gt;Who hasn't used and combined heavily popular array methods like &lt;code&gt;map&lt;/code&gt;, &lt;code&gt;filter&lt;/code&gt;, and &lt;code&gt;sort&lt;/code&gt;? Very hard to avoid in applications involving any form of list manipulation.&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%2F4bg2kbmd5qpf66frfhwc.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%2F4bg2kbmd5qpf66frfhwc.png" alt="Image description" width="700" height="609"&gt;&lt;/a&gt;&lt;br&gt;
This is actually great. There aren't any temporary variables or unreadable nesting here either and we can easily follow the chain from start to finish.&lt;/p&gt;

&lt;p&gt;The formatting lets us easily add more methods at any point in the chain; &lt;a href="https://www.codingbeautydev.com/blog/vscode-tips-tricks" rel="noopener noreferrer"&gt;feature-packed editor like VS Code&lt;/a&gt; can easily swap the processing order of two methods, with the &lt;code&gt;Ctrl + Up&lt;/code&gt; and &lt;code&gt;Ctrl + Down&lt;/code&gt; shortcuts.&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%2Fq8zv0vk9lro88bq4p16w.gif" 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%2Fq8zv0vk9lro88bq4p16w.gif" alt="Image description" width="800" height="499"&gt;&lt;/a&gt;&lt;br&gt;
There's a reason why libraries like core &lt;code&gt;http&lt;/code&gt; and &lt;code&gt;jQuery&lt;/code&gt; are designed like this:&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%2Fflwb472jj5imrjtoeizm.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%2Fflwb472jj5imrjtoeizm.png" alt="Image description" width="700" height="690"&gt;&lt;/a&gt;&lt;br&gt;
The problem with method chaining is that, we simply can't use it everywhere. If the class wasn't designed like that we're stuck and out in the cold.&lt;/p&gt;

&lt;p&gt;It doesn't work very well with generator methods, &lt;code&gt;async/await&lt;/code&gt; and function/method calls outside the object, like we saw here:&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%2Ftvqw9ueu0rekkal0wofw.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%2Ftvqw9ueu0rekkal0wofw.png" alt="Image description" width="700" height="661"&gt;&lt;/a&gt;&lt;br&gt;
But all this and more work with the pipeline operator; even object literals and the &lt;code&gt;async&lt;/code&gt; &lt;code&gt;import&lt;/code&gt; function.&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%2F8seg48mg80xctrvg2yod.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%2F8seg48mg80xctrvg2yod.png" alt="Image description" width="700" height="491"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Could have been F# pipes
&lt;/h2&gt;

&lt;p&gt;We would have been using the pipeline operator very similarly to F# pipes, with the above turning out like this instead:&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%2Fyu6y4exm3osgvsa8n7hw.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%2Fyu6y4exm3osgvsa8n7hw.png" alt="Image description" width="700" height="620"&gt;&lt;/a&gt;&lt;br&gt;
There was an alternative design. But you can already see how this makes for an inferior alternative: Only single-function arguments are allowed and the operation is more verbose. Unless the operation is already a single-argument function call.&lt;/p&gt;

&lt;p&gt;Its weird handling of &lt;code&gt;async/await&lt;/code&gt; was also a key reason why it got rejected -- along with memory usage concerns. So, forget about F# pipes in JS!&lt;/p&gt;

&lt;h2&gt;
  
  
  Use the pipeline operator right now
&lt;/h2&gt;

&lt;p&gt;Yes you can — with Babel.&lt;/p&gt;

&lt;p&gt;Babel has a nice habit of implementing features before they're officially integrated in the language; it did this for &lt;a href="https://www.codingbeautydev.com/blog/es13-javascript-features" rel="noopener noreferrer"&gt;top-level await&lt;/a&gt;, optional chaining, and many others. The pipeline operator couldn't be an exception.&lt;/p&gt;

&lt;p&gt;Just use the &lt;code&gt;@babel/plugin-proposal-pipeline-operator&lt;/code&gt; &lt;a href="https://babeljs.io/docs/usage#plugins--presets" rel="noopener noreferrer"&gt;plugin&lt;/a&gt; and you're good to.&lt;/p&gt;

&lt;p&gt;It's optional of course — but not for long.&lt;/p&gt;

&lt;p&gt;Prettier the code formatter is already prepared.&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%2F63hx8acuorhulft9b08o.gif" 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%2F63hx8acuorhulft9b08o.gif" alt="Image description" width="800" height="499"&gt;&lt;/a&gt;&lt;br&gt;
Even though we can't say the same about VS Code or Node.js:&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%2Fv7kibhtck37zac08yhhf.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%2Fv7kibhtck37zac08yhhf.png" alt="Image description" width="700" height="354"&gt;&lt;/a&gt;&lt;br&gt;
Right now there's even speculation that &lt;code&gt;%&lt;/code&gt; won't be the final symbol passed around in the pipeline; let's watch and see how it all plays out.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final thoughts
&lt;/h2&gt;

&lt;p&gt;It's always great to see new and exciting features come to the language. With the JavaScript pipeline operator, you'll cleanse your code of temporary variables and cryptic nesting, greatly boosting code readability, efficiency, and quality.&lt;/p&gt;

&lt;h2&gt;
  
  
  Every Crazy Thing JavaScript Does
&lt;/h2&gt;

&lt;p&gt;Just when you thought you knew all the quirks. Avoid painful bugs and save valuable time with Every Crazy Thing JavaScript Does, a captivating guide to the subtle caveats and lesser-known parts of JavaScript.&lt;/p&gt;

&lt;p&gt;Get a free copy &lt;a href="https://cbdev.link/d3c4eb" rel="noopener noreferrer"&gt;here&lt;/a&gt; today.&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%2F3qxkflmt4wtj45mlzfsn.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%2F3qxkflmt4wtj45mlzfsn.png" alt="Image description" width="350" height="547"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>softwaredevelopment</category>
    </item>
    <item>
      <title>React 19 is here! Let's learn it!</title>
      <dc:creator>Afzal Imdad</dc:creator>
      <pubDate>Thu, 24 Oct 2024 07:42:11 +0000</pubDate>
      <link>https://dev.to/afzalimdad9/react-19-is-here-lets-learn-it-1k87</link>
      <guid>https://dev.to/afzalimdad9/react-19-is-here-lets-learn-it-1k87</guid>
      <description>&lt;p&gt;In February this year, React announced the release of version 19, finally updating a version number that had been static for two years (&lt;a href="https://medium.com/stackademic/react-19-is-coming-whats-new-79e2d4b948e4" rel="noopener noreferrer"&gt;React 19 is Coming, What's New?&lt;/a&gt;). Andrew Clark, a member of the React team, confirmed that the new version would be released in March or April.&lt;/p&gt;

&lt;p&gt;As they say, "deadlines are the first productivity driver." Here we are at the end of April, and the new version, 19.0.0-Beta, has just been released right on schedule.&lt;/p&gt;

&lt;p&gt;Although it's only a Beta version, it has already generated considerable excitement within the community:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Dan commented: "they did what."&lt;/li&gt;
&lt;li&gt;Andrew Clark commented: "React 19: Never forwardRef again."&lt;/li&gt;
&lt;li&gt;Josh W. Comeau commented: "Lots of nice quality-of-life improvements here!"&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The only disappointment is, as confirmed by React member Lauren, that the React Compiler has been delayed again. It was originally named "React Forget," a fitting title given its delays.&lt;/p&gt;

&lt;p&gt;The features of the 19.0.0-Beta release include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;An Actions feature&lt;/li&gt;
&lt;li&gt;Three new hooks&lt;/li&gt;
&lt;li&gt;A new API&lt;/li&gt;
&lt;li&gt;Simplified usage of ref and context&lt;/li&gt;
&lt;li&gt;Various supportive updates and enhanced server-side capabilities&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let's delve into each of these.&lt;/p&gt;

&lt;p&gt;Follow me:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Github: &lt;a href="https://github.com/afzalimdad9" rel="noopener noreferrer"&gt;https://github.com/afzalimdad9&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Medium: &lt;a href="https://medium.com/@afzalimdad9" rel="noopener noreferrer"&gt;https://medium.com/@afzalimdad9&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Actions
&lt;/h2&gt;

&lt;p&gt;Actions are not a specific API but a general term for methods that simplify data handling in requests. A valid Actions setup should simplify asynchronous operations, allowing developers to focus more on business logic rather than state management.&lt;/p&gt;

&lt;p&gt;Here's an example to illustrate the role of Actions. Suppose we have a form where users can update their name. Previously, we might use &lt;code&gt;useState&lt;/code&gt; to manually manage form state, error state, and submission status. The code might look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function UpdateName() {
  const [name, setName] = useState("");
  const [error, setError] = useState(null);
  const [isPending, setIsPending] = useState(false);
  const handleSubmit = async () =&amp;gt; {
    setIsPending(true);
    const error = await updateName(name);
    setIsPending(false);
    if (error) {
      setError(error);
      return;
    }
    redirect("/path");
  };
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;input value={name} onChange={(event) =&amp;gt; setName(event.target.value)} /&amp;gt;
      &amp;lt;button onClick={handleSubmit} disabled={isPending}&amp;gt;
        Update
      &amp;lt;/button&amp;gt;
      {error &amp;amp;&amp;amp; &amp;lt;p&amp;gt;{error}&amp;lt;/p&amp;gt;}
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With React 19's Actions, this situation is optimized. We can now use the &lt;code&gt;useTransition&lt;/code&gt; hook to handle form submissions, which automatically manages the pending state, making our code much cleaner:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function UpdateName() {
  const [name, setName] = useState("");
  const [error, setError] = useState(null);
  const [isPending, startTransition] = useTransition();
  const handleSubmit = async () =&amp;gt; {
    startTransition(async () =&amp;gt; {
      const error = await updateName(name);
      if (error) {
        setError(error);
        return;
      }
      redirect("/path");
    });
  };
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;input value={name} onChange={(event) =&amp;gt; setName(event.target.value)} /&amp;gt;
      &amp;lt;button onClick={handleSubmit} disabled={isPending}&amp;gt;
        Update
      &amp;lt;/button&amp;gt;
      {error &amp;amp;&amp;amp; &amp;lt;p&amp;gt;{error}&amp;lt;/p&amp;gt;}
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the &lt;code&gt;handleSubmit&lt;/code&gt; function, the logic for the asynchronous request is encapsulated within the callback passed to &lt;code&gt;startTransition&lt;/code&gt;. When &lt;code&gt;startTransition&lt;/code&gt; is invoked, React immediately sets &lt;code&gt;isPending&lt;/code&gt; to true, indicating that the transition (request) is underway. React then performs the &lt;code&gt;startTransition&lt;/code&gt; callback asynchronously in the background. Once the request is complete, React automatically switches &lt;code&gt;isPending&lt;/code&gt; back to false.&lt;/p&gt;

&lt;p&gt;This functionality binds &lt;code&gt;isPending&lt;/code&gt; to the &lt;code&gt;disabled&lt;/code&gt; attribute of the submit button, so the button automatically becomes disabled during the request, preventing double submissions.&lt;/p&gt;

&lt;p&gt;Summarizing React's conventions for Actions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Naming Convention:&lt;/strong&gt; Functions using asynchronous transitions can be referred to as "Actions."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Pending State:&lt;/strong&gt; Actions automatically manage the pending state of data submissions. When a request is initiated, the pending state is automatically activated, and it resets once the final state updates. This ensures users receive feedback while data is submitted and the pending state is cleared after the request completes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optimistic Updates:&lt;/strong&gt; Actions support optimistic updates, displaying the correct submission result to users while the request is pending. If the request ultimately fails, the optimistic update automatically reverts to its original state.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Error Handling:&lt;/strong&gt; Actions include built-in error handling. When a request fails, you can use error boundaries to display error messages.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Form Support:&lt;/strong&gt;  elements now support passing functions to &lt;code&gt;action&lt;/code&gt; and &lt;code&gt;formAction&lt;/code&gt; attributes. By passing a function to the &lt;code&gt;action&lt;/code&gt; attribute, you can handle form submissions with Actions, automatically resetting the form after submission. This simplifies the process of handling forms, making it more intuitive and efficient.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Three New Hooks
&lt;/h2&gt;

&lt;p&gt;Why discuss Actions first? Because based on Actions, React 19 introduces three new hooks, each designed to simplify the complex handling of state by developers.&lt;/p&gt;

&lt;h2&gt;
  
  
  useOptimistic
&lt;/h2&gt;

&lt;p&gt;The main purpose of &lt;code&gt;useOptimistic&lt;/code&gt; is to allow us to assume success in asynchronous operations and update the state accordingly while waiting for the actual results.&lt;/p&gt;

&lt;p&gt;Here's a basic usage example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useOptimistic } from 'react';
function AppContainer() {
 const [optimisticState, addOptimistic] = useOptimistic(
 state,
 // updateFn
 (currentState, optimisticValue) =&amp;gt; {
 // merge and return new state
 // with optimistic value
 }
 );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this setup:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;state:&lt;/strong&gt; Initial state and the state returned when no operations are in progress.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;updateFn(currentState, optimisticValue):&lt;/strong&gt; A pure function that takes the current state and the optimistic value passed by &lt;code&gt;addOptimistic&lt;/code&gt;, returning the merged optimistic state.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;optimisticState:&lt;/strong&gt; The optimistic state. If no operations are in progress, it equals state; otherwise, it equals the result of &lt;code&gt;updateFn&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;addOptimistic:&lt;/strong&gt; A function for triggering optimistic updates, accepting an &lt;code&gt;optimisticValue&lt;/code&gt; of any type and passing it to &lt;code&gt;updateFn&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;useOptimistic&lt;/code&gt; has a wide range of applications, such as form submissions, liking, bookmarking, deleting, and other scenarios that require immediate feedback.&lt;/p&gt;

&lt;p&gt;Here's an example of optimistic updating for data deletion:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState } from 'react';
import { useOptimistic } from 'react';
function AppContainer() {
    // Default data
  const [state, setState] = useState([
    { id: 1, name: 'Item 1' },
    { id: 2, name: 'Item 2' },
    { id: 3, name: 'Item 3' },
  ]);
    // Define the update function, which updates the state based on the current state and the optimistic value (the ID of the item to be deleted)
  const updateFn = (currentState, optimisticId) =&amp;gt; {
    return currentState.filter(item =&amp;gt; item.id !== optimisticId);
  };
  const [optimisticState, addOptimistic] = useOptimistic(state, updateFn);
    // Delete item
  const deleteItem = async (itemId) =&amp;gt; {
    // Optimistically update the UI first
    addOptimistic(itemId);
    // Simulate API request delay
    setTimeout(() =&amp;gt; {
      // Assume this is the API delete call, update the actual state after completion
      setItems(currentItems =&amp;gt; currentItems.filter(item =&amp;gt; item.id !== itemId));
    }, 2000);
  };
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;Optimistically Deleting Items&amp;lt;/h1&amp;gt;
      &amp;lt;ul&amp;gt;
        {optimisticState.map(item =&amp;gt; (
          &amp;lt;li key={item.id}&amp;gt;
            {item.name} &amp;lt;button onClick={() =&amp;gt; deleteItem(item.id)}&amp;gt;Delete&amp;lt;/button&amp;gt;
          &amp;lt;/li&amp;gt;
        ))}
      &amp;lt;/ul&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
export default AppContainer;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  useActionState
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;useActionState&lt;/code&gt;, formerly known as &lt;code&gt;useFormState&lt;/code&gt;, has a new name in version 19, and its return parameters have changed (oddly, React has not yet updated the &lt;code&gt;useActionState&lt;/code&gt; documentation, do they think developers don't read documentation? 🐶).&lt;/p&gt;

&lt;p&gt;Here is the latest basic usage of &lt;code&gt;useActionState&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [state, action, pending] = useActionState(fn, initialState, permalink?);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The return parameters include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;state:&lt;/strong&gt; Represents the current state. At the first render, it equals the initial state &lt;code&gt;initialState&lt;/code&gt;. After an operation, it will be the most recent result.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;action:&lt;/strong&gt; This is a function used to perform operations. When this function is called, it will trigger the execution of &lt;code&gt;fn&lt;/code&gt; and update the state.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;pending:&lt;/strong&gt; This is a new parameter, a &lt;code&gt;boolean&lt;/code&gt; value indicating whether an operation is currently being performed. If an operation is in progress, it is &lt;code&gt;true&lt;/code&gt;; otherwise, it is &lt;code&gt;false&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The parameters are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;fn:&lt;/strong&gt; This is a function that is triggered when the action is called, subsequently returning a new value.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;initialState:&lt;/strong&gt; This is the initial value, set to null if there is no initial value.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;permalink:&lt;/strong&gt; This is an optional string parameter, typically used in conjunction with server actions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here's an example of using &lt;code&gt;useActionState&lt;/code&gt; with form action to implement name update functionality. If the update fails, an error&lt;br&gt;
is displayed on the page; if successful, the page redirects to the updated page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useActionState } from 'react';
function ChangeName({ name, setName }) {
  // Using useActionState to create a state associated with form operations
  const [error, submitAction, isPending] = useActionState(
    // First parameter: Form operation function
    async (previousState, formData) =&amp;gt; {
      // Define the logic for form operations here
      // This function will be called upon form submission
      // It receives two parameters:
      // - previousState: The previous state, initially null, then the return value of the last operation
      // - formData: A form data object, can retrieve form fields using formData.get("name")
      const error = await updateName(formData.get("name"));
      // If there is an error during the operation, return the error message
      if (error) {
        return error;
      }
      // If the operation is successful, perform a redirection
      redirect("/path");
    }, 
    // Second parameter: Initial state, set here as null since the initial state is not crucial
    null
  }
  // Return the form along with related state and actions
  return (
    &amp;lt;form action={submitAction}&amp;gt;
      &amp;lt;input type="text" name="name" defaultValue={name} /&amp;gt;
      &amp;lt;button type="submit" disabled={isPending}&amp;gt;
        Submit
      &amp;lt;/button&amp;gt;
      {/* Display error messages if any */}
      {error &amp;amp;&amp;amp; &amp;lt;p&amp;gt;{error}&amp;lt;/p&amp;gt;}
    &amp;lt;/form&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  useFormStatus
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;useFormStatus&lt;/code&gt; is used to retrieve status information about form submissions. Its basic usage is as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { pending, data, method, action } = useFormStatus();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;pending:&lt;/strong&gt; A boolean value indicating whether the parent &lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt; is currently submitting. If true, the form is in the process of being submitted; otherwise, it is false.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;data:&lt;/strong&gt; An object implementing the FormData interface, containing data from the parent &lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt; that is currently being submitted. If there is no ongoing submission or no parent &lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt;, it is &lt;code&gt;null&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;method:&lt;/strong&gt; A string value indicating the HTTP method used by the parent &lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt;, which can be either get or post.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;action:&lt;/strong&gt; A reference to the function passed to the parent &lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt;'s action attribute. If there is no parent &lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt;, this property is &lt;code&gt;null&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, developers can retrieve form status using &lt;code&gt;useFormStatus&lt;/code&gt; in a form action:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useFormStatus } from "react-dom";
import action from './actions';
function Submit() {
  const status = useFormStatus();
  return &amp;lt;button disabled={status.pending}&amp;gt;Submit&amp;lt;/button&amp;gt;
}
export default function App() {
  return (
    &amp;lt;form action={action}&amp;gt;
      &amp;lt;Submit /&amp;gt;
    &amp;lt;/form&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This approach may feel both familiar and new. If it reminds you of context, you're on the right track. You can consider &lt;code&gt;useFormStatus&lt;/code&gt; as a replacement for some of the capabilities of the context provider, but with a more streamlined syntax.&lt;/p&gt;

&lt;p&gt;It's important to note two things about using &lt;code&gt;useFormStatus&lt;/code&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The &lt;code&gt;useFormStatus&lt;/code&gt; Hook must be called within components that are rendered inside a &lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;useFormStatus&lt;/code&gt; only returns the status information of the parent &lt;code&gt;&amp;lt;form&amp;gt;&lt;/code&gt;, not any other  in the same component or its child components.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  A New API - use
&lt;/h2&gt;

&lt;p&gt;Previously categorized among hooks, the use has now been documented under APIs in React 19, thus becoming a new API.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;use&lt;/code&gt; is used to read values from resources within a component, where the resource could be a Promise or a context.&lt;/p&gt;

&lt;p&gt;Here's how it typically works:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { use } from 'react';
function MessageComponent({ messagePromise }) {
  const message = use(messagePromise);
  const theme = use(ThemeContext);
  // …
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;use&lt;/code&gt; is mainly intended for higher-level frameworks like Next.js. For instance, it's recommended to use &lt;code&gt;async&lt;/code&gt;…&lt;code&gt;await&lt;/code&gt; instead of use if data fetching occurs in server components in Next.js. If fetching happens in client components, it's suggested to create a Promise in server components and pass it to client components as props.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;use&lt;/code&gt; can also be used alongside Suspense boundaries. If a component calling &lt;code&gt;use&lt;/code&gt; is wrapped in a Suspense boundary, the specified fallback will be displayed. Once the Promise resolves, the fallback is replaced by the returned data. If the &lt;code&gt;Promise&lt;/code&gt; is rejected, the nearest error boundary's fallback will be displayed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Simplified ref and context Usage
&lt;/h2&gt;

&lt;p&gt;If you primarily utilize React's client-side capabilities, the changes discussed in this section will likely be of most interest to you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ref Discards forwardRef
&lt;/h2&gt;

&lt;p&gt;Remember the dread of being dominated by &lt;code&gt;forwardRef&lt;/code&gt;? With React 19, we can finally discard &lt;code&gt;forwardRef&lt;/code&gt;. From now on, refs can be passed as props.&lt;/p&gt;

&lt;p&gt;For example, suppose we have a functional component &lt;code&gt;TextInput&lt;/code&gt;, a simple input box that accepts a &lt;code&gt;placeholder&lt;/code&gt; attribute for placeholder text. Now, we want to obtain a reference to the input box in the parent component to focus on it when necessary. Here's how you could write it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useRef } from 'react';
// Define a function component TextInput
function TextInput({ placeholder, ref }) {
  return &amp;lt;input placeholder={placeholder} ref={ref} /&amp;gt;;
}
// Parent component
function ParentComponent() {
  // Create a ref to store the input box's reference
  const inputRef = useRef(null);
  // In some event handler, obtain the input box's reference and focus on it
  const focusInput = () =&amp;gt; {
    inputRef.current.focus();
  };
  return (
    &amp;lt;div&amp;gt;
      {/* 
        Pass the inputRef to the TextInput component,
        allowing the ref to be used internally within the TextInput
      */}
      &amp;lt;TextInput placeholder="Enter your name" ref={inputRef} /&amp;gt;
      &amp;lt;button onClick={focusInput}&amp;gt;Focus Input&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}
export default ParentComponent;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Isn't this mentally less burdensome than using forwardRef?&lt;/p&gt;

&lt;h2&gt;
  
  
  Context as Provider
&lt;/h2&gt;

&lt;p&gt;Starting in React 19, developers can directly use &lt;code&gt;&amp;lt;Context&amp;gt;&lt;/code&gt; as a provider, rather than using &lt;code&gt;&amp;lt;Context.Provider&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Suppose we have a &lt;code&gt;ThemeContext&lt;/code&gt; used to manage theme information. In React 19, we can use &lt;code&gt;&amp;lt;ThemeContext&amp;gt;&lt;/code&gt; as a provider like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { createContext } from 'react';
// Create a theme context
const ThemeContext = createContext('');
// App component as the theme provider
function App({ children }) {
  return (
    &amp;lt;ThemeContext value="dark"&amp;gt;
      {children}
    &amp;lt;/ThemeContext&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the future, &lt;code&gt;Context.Provider&lt;/code&gt; will be deprecated and removed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Other Updates
&lt;/h2&gt;

&lt;p&gt;This release also includes various supportive features and enhancements to server-side capabilities that are less commonly used in pure client-side React development, hence they are summarized briefly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Server components and server &lt;code&gt;actions&lt;/code&gt; are becoming stable features. These concepts are well-known to those familiar with Next.js/Remix but are not typically used by those who do not use these frameworks.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;useDeferredValue&lt;/code&gt; has been updated to include a second parameter, optionally used to specify an initial value. The new usage of &lt;code&gt;useDeferredValue&lt;/code&gt; is now: &lt;code&gt;const value = useDeferredValue(deferredValue, initialValue?);&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Support for writing document metadata directly in React code, i.e., writing &lt;code&gt;&amp;lt;title&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;link&amp;gt;&lt;/code&gt;, and &lt;code&gt;&amp;lt;meta&amp;gt;&lt;/code&gt; tags in page components will automatically add them to the application's &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function BlogPost({post}) {
  return (
    &amp;lt;article&amp;gt;
      &amp;lt;h1&amp;gt;{post.title}&amp;lt;/h1&amp;gt;
      &amp;lt;title&amp;gt;{post.title}&amp;lt;/title&amp;gt;
      &amp;lt;meta name="author" content="Josh" /&amp;gt;
      &amp;lt;link rel="author" href="&amp;lt;https://twitter.com/joshcstory/&amp;gt;" /&amp;gt;
      &amp;lt;meta name="keywords" content={post.keywords} /&amp;gt;
      &amp;lt;p&amp;gt;
        Eee equals em-see-squared...
      &amp;lt;/p&amp;gt;
    &amp;lt;/article&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Support for writing stylesheets directly in React code, i.e., &lt;code&gt;&amp;lt;link rel="stylesheet" href="…"&amp;gt;&lt;/code&gt; tags written in page components will automatically be added to the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Support for writing &lt;code&gt;&amp;lt;script async="" src="…"&amp;gt;&lt;/code&gt; tags, which will also automatically be added to the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Support for preloading resources, which will also automatically be added to the &lt;code&gt;&amp;lt;head&amp;gt;&lt;/code&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { prefetchDNS, preconnect, preload, preinit } from 'react-dom'
function MyComponent() {
  preinit('https://.../path/to/some/script.js', {as: 'script' }) // loads and executes this script eagerly
  preload('https://.../path/to/font.woff', { as: 'font' }) // preloads this font
  preload('https://.../path/to/stylesheet.css', { as: 'style' }) // preloads this stylesheet
  prefetchDNS('https://...') // when you may not actually request anything from this host
  preconnect('https://...') // when you will request something but aren't sure what
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;p&gt;To conclude, let me quote Huang Xuan: "Probably the single most critical principle I've learned from React is to be fearless in defining new conceptual abstractions and never compromise on the accuracy and composability of these definitions."&lt;/p&gt;

&lt;h2&gt;
  
  
  About Me
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Full-stack engineer, Next.js open-source craftsman, AI advent proponent.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This year, I am committed to the development of open-source projects in the Next.js and Node.js domains and to sharing knowledge in these fields.&lt;/p&gt;

&lt;p&gt;Follow me:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Github: &lt;a href="https://github.com/afzalimdad9" rel="noopener noreferrer"&gt;https://github.com/afzalimdad9&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Medium: &lt;a href="https://medium.com/@afzalimdad9" rel="noopener noreferrer"&gt;https://medium.com/@afzalimdad9&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>javascript</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Next-Auth in App Router of Next.js</title>
      <dc:creator>Afzal Imdad</dc:creator>
      <pubDate>Tue, 20 Aug 2024 15:32:17 +0000</pubDate>
      <link>https://dev.to/afzalimdad9/next-auth-in-app-router-of-nextjs-1112</link>
      <guid>https://dev.to/afzalimdad9/next-auth-in-app-router-of-nextjs-1112</guid>
      <description>&lt;p&gt;Next.js has recently released a stable version of App Router enriched with in-built support for layouts, templates, routing, loading, and error handling.&lt;/p&gt;

&lt;p&gt;The current version of Next-Auth documentation is published with examples of the Page Router of Next.js. This document share approach to setting up Next.js with the Next-Auth App Router.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is covered in this document?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Setup of Next.js app with app router.&lt;/li&gt;
&lt;li&gt;Install Next-Auth.&lt;/li&gt;
&lt;li&gt;Configuration of Github Provider.&lt;/li&gt;
&lt;li&gt;Add Handler for Next-Auth&lt;/li&gt;
&lt;li&gt;Sign in and Sign out using next-auth.&lt;/li&gt;
&lt;li&gt;Use session in the Server Components&lt;/li&gt;
&lt;li&gt;Use of session in the Client Components.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Set up the Next.js app with the App router.
&lt;/h2&gt;

&lt;p&gt;Follow this document to create a basic next.js app with an app router.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzsba3gbrxfnzd8i7bjrk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzsba3gbrxfnzd8i7bjrk.png" alt="Image description" width="700" height="1009"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next.js app with App router.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Next-Auth
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install next-auth
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Configuration of Github Provider
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://docs.github.com/en/apps/creating-github-apps/registering-a-github-app/registering-a-github-app" rel="noopener noreferrer"&gt;Create a GitHub App&lt;/a&gt; first, providing you a client Id and Secret. Add a file auth.js in the lib folder.&lt;/p&gt;

&lt;p&gt;Note: Generate a secret to add as NEXTAUTH_SECRET, it must be added in the auth options.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;openssl rand -base64 32

// output
// mQ46qpFwfE1BHuqMC+qlm19qBAD9fVPgh28werwe3ASFlAfnKjM=
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;next. config.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/** @type {import('next').NextConfig} */
const nextConfig = {
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: 'i.imgur.com',
      },
    ],
  },
  env: {
    GITHUB_APP_CLIENT_ID: '919b87qa4sdfs1qdc44f53baf9',
    GITHUB_APP_CLIENT_SECRET: '2aeq98df3f8cwqerc2d03a8360e993c115ba8d5f71de9',
    NEXTAUTH_SECRET: 'mQ46qpFwfE1BHuqMC+qlm19qBAD9fVPgh28werwe3ASFlAfnKjM=',
  },
};

module.exports = nextConfig;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { NextAuthOptions } from 'next-auth';
import GithubProvider from 'next-auth/providers/github';
export const authOptions: NextAuthOptions = {
  // Secret for Next-auth, without this JWT encryption/decryption won't work
  secret: process.env.NEXTAUTH_SECRET,

  // Configure one or more authentication providers
  providers: [
    GithubProvider({
      clientId: process.env.GITHUB_APP_CLIENT_ID as string,
      clientSecret: process.env.GITHUB_APP_CLIENT_SECRET as string,
    }),
  ],
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Add Handler for Next-Auth
&lt;/h2&gt;

&lt;p&gt;Create a file &lt;code&gt;route.js&lt;/code&gt; in the folder &lt;code&gt;/app/auth/[…nextauth]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpaatrwhfqtjwwcpf9egb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpaatrwhfqtjwwcpf9egb.png" alt="Image description" width="654" height="116"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next-Auth Handler&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import NextAuth from 'next-auth';
import { authOptions } from '@/app/lib/auth';

const handler = NextAuth(authOptions);
export { handler as GET, handler as POST };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Sign in and Sign out using next-auth
&lt;/h2&gt;

&lt;p&gt;All requests to any of these paths &lt;code&gt;/api/auth/*&lt;/code&gt; (&lt;code&gt;signIn&lt;/code&gt;, &lt;code&gt;callback&lt;/code&gt;, &lt;code&gt;signOut&lt;/code&gt;, etc.) will be handled by NextAuth.js.&lt;/p&gt;

&lt;p&gt;Once you click the button, log in, and authorize the app, it will get a cookie in the session.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffs2qhfvv0h0zmchzm1m6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ffs2qhfvv0h0zmchzm1m6.png" alt="Image description" width="700" height="418"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next-Auth default Sign in page&lt;br&gt;
After successful sign-in.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4epholdna1rbr8hwv3h1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4epholdna1rbr8hwv3h1.png" alt="Image description" width="700" height="312"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next-Auth token&lt;/p&gt;
&lt;h2&gt;
  
  
  Sign Out
&lt;/h2&gt;

&lt;p&gt;use this link &lt;code&gt;/api/auth/signout&lt;/code&gt; to sign out.&lt;/p&gt;
&lt;h2&gt;
  
  
  Session in API routes.
&lt;/h2&gt;

&lt;p&gt;API route handlers are considered server components. It can be a static or dynamic handler but these are always on the server side.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { authOptions } from '@/app/lib/auth';
import { getServerSession } from 'next-auth';
import { NextResponse } from 'next/server';

export async function GET(request: Request) {
  const session = await getServerSession(authOptions);
  console.log(session);
  return NextResponse.json({
    id: 1,
  });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  user: {
    name: 'Rohit Kumar Khatri',
    email: 'er.rohitkumar@outlook.com',
    image: 'https://avatars.githubusercontent.com/u/34018015?v=4'
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Session in Server Components
&lt;/h2&gt;

&lt;p&gt;It is also similar in all server components. Use the same function as mentioned above.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;await getServerSession(authOptions);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Session in Client Components
&lt;/h2&gt;

&lt;p&gt;First, add Session Provider in the Root Layout&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'use client';

import { SessionProvider } from 'next-auth/react';
import { ReactNode } from 'react';

export default function NextAuthProvider({
  children,
}: {
  children: ReactNode;
}) {
  return &amp;lt;SessionProvider&amp;gt;{children}&amp;lt;/SessionProvider&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useSelectedLayoutSegments } from 'next/navigation';
import './globals.css';
import { Inter } from 'next/font/google';
import Footer from '@/app/components/Footer';
import Navbar from '@/app/components/Navbar';
import NextAuthProvider from '@/app/context/NextAuthProvider';
import { ReactNode } from 'react';
const inter = Inter({ subsets: ['latin'] });

export default function RootLayout({ children }: { children: ReactNode }) {
  return (
    &amp;lt;html lang="en"&amp;gt;
      &amp;lt;body className={`inter.className`}&amp;gt;
        &amp;lt;NextAuthProvider&amp;gt;
          &amp;lt;div className="w-10/12 m-auto text-center bg-white flex flex-col min-h-screen"&amp;gt;
            &amp;lt;div&amp;gt;
              &amp;lt;Navbar /&amp;gt;
            &amp;lt;/div&amp;gt;
            &amp;lt;div className="grow"&amp;gt;{children}&amp;lt;/div&amp;gt;
            &amp;lt;Footer /&amp;gt;
          &amp;lt;/div&amp;gt;
        &amp;lt;/NextAuthProvider&amp;gt;
      &amp;lt;/body&amp;gt;
    &amp;lt;/html&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now use session in any client component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'use client';

import { useSession } from 'next-auth/react';

export default function ClientComponent() {
  const { data: session, status } = useSession();
  return (
    &amp;lt;div&amp;gt;
      ClientComponent {status}{' '}
      {status === 'authenticated' &amp;amp;&amp;amp; session.user?.name}
    &amp;lt;/div&amp;gt;
  );
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>nextjs</category>
      <category>nextauth</category>
      <category>react</category>
      <category>github</category>
    </item>
    <item>
      <title>Why NextJS Sucks</title>
      <dc:creator>Afzal Imdad</dc:creator>
      <pubDate>Tue, 20 Aug 2024 13:44:54 +0000</pubDate>
      <link>https://dev.to/afzalimdad9/why-nextjs-sucks-1bk8</link>
      <guid>https://dev.to/afzalimdad9/why-nextjs-sucks-1bk8</guid>
      <description>&lt;p&gt;I’ve used NextJS for static websites because the experience with amplify hosting is so insanely easy. The fact that I go on the AWS console and connect a github repo and it just works, and runs with lambda, and is super cheap (unless I get DDOS’d)… that’s just too good to say no to in some cases.&lt;/p&gt;

&lt;p&gt;Even though server side rendering hasn’t been required in years in order for google to index and find your content, the developer experience for toy websites is too good to pass up.&lt;/p&gt;

&lt;p&gt;But for a complex SaaS project, I see very few benefits and some serious downsides of NextJS.&lt;/p&gt;

&lt;h2&gt;
  
  
  NodeJS sucks for SSR
&lt;/h2&gt;

&lt;p&gt;𝐑𝐞𝐚𝐜𝐭 𝐫𝐞𝐧𝐝𝐞𝐫𝐢𝐧𝐠 𝐨𝐧 𝐭𝐡𝐞 𝐬𝐞𝐫𝐯𝐞𝐫 𝐚𝐝𝐝𝐬 𝐚 𝐝𝐢𝐦𝐞𝐧𝐬𝐢𝐨𝐧 𝐨𝐟 𝐜𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲 𝐭𝐨 𝐭𝐡𝐞 𝐚𝐩𝐩𝐥𝐢𝐜𝐚𝐭𝐢𝐨𝐧 𝐛𝐞𝐜𝐚𝐮𝐬𝐞 𝐲𝐨𝐮’𝐫𝐞 𝐦𝐚𝐤𝐢𝐧𝐠 𝐍𝐨𝐝𝐞𝐉𝐒 𝐝𝐨 𝐬𝐨𝐦𝐞𝐭𝐡𝐢𝐧𝐠 𝐢𝐭’𝐬 𝐫𝐞𝐚𝐥𝐥𝐲 𝐛𝐚𝐝 𝐚𝐭 𝐝𝐨𝐢𝐧𝐠.&lt;/p&gt;

&lt;p&gt;NodeJs is single threaded. In the ideal case that it’s designed for, requests should be I/O bound. A complex page requiring much SSR will hamstring the ability to serve concurrent requests. Here is a talk by a former coworker of mine on his experience optimizing server side rendering through large demand spikes.&lt;/p&gt;

&lt;p&gt;Now, of course, most apps (including yours) are not going to have the same kind of spikes that Walmart has on black Friday. But you always gotta think about what you’re gaining in exchange of what you're giving up. From what I recall, my friend’s Walmart situation ended up boiling down to NodeJS getting hung up on page rendering for too long, then the operating system’s http request queue would expand too large, because they weren’t configured for load shedding, and the servers would become unresponsive as described in that load shedding article.&lt;/p&gt;

&lt;p&gt;The autoscaling infrastructure would come to the rescue and constantly spin up new servers, but they spent millions of dollars on that, and still experienced availability loss (users getting a broken experience and having to reload). In order to fix it my friend ended up basically having to inject setTimeouts all over the place when rendering the app.&lt;/p&gt;

&lt;p&gt;Now of course there’s ways to avoid all of this such as static site pregeneration, or hosting on serverless. This is part of the reason why serverless is a popular choice for NextJS. But my favorite way of avoiding this particular bit of complexity is just not server-rendering react in nodejs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Security takes a back seat to coolness
&lt;/h2&gt;

&lt;p&gt;Many nextJS features require allowing the browser to inject inline scripts. Nextjs’s implementation of suspense, and also usage of the appDir feature (which you basically always use), using next/font, and anything you put in your rootLayout all gets injected into the app as inline scripts.&lt;/p&gt;

&lt;p&gt;Open up any nextJS website and you'll see a bunch of inline scripts like the screenshot below, from one of my NextJS pages:&lt;/p&gt;

&lt;p&gt;Those are a bunch of inline scripts. Inline scripts are bad, because the only actually reliable way to prevent reflected XSS attacks is with content security policy headers that prevent the execution of inline scripts. A strong CSP policy is the golden standard for XSS prevention. And the main thing you need to do from a CSP standpoint is to avoid inline scripts.&lt;/p&gt;

&lt;p&gt;If you just instruct the browser to not execute inline scripts, stored XSS is impossible. But if you use any of the NextJS features that require inline scripts, you cannot have a CSP policy to forbid inline scripts. Because of that, you have to settle for something worse, which is allowing only inline scripts that match a certain nonce (computed randomly at load time).&lt;/p&gt;

&lt;p&gt;In order to do that with nextJS, you have to write a significant amount of code and jump through hoops (see docs on how to do it if you want your head to spin). Fun side effect of this is, even if you put a CDN in front of your NextJS cluster, there won't be any edge location caching because the nonce has to be different for every session (if it's not, it defeats the purpose of the nonce and you might as well just allow inline scripts).&lt;/p&gt;

&lt;h2&gt;
  
  
  NextJS doesn’t respect your time
&lt;/h2&gt;

&lt;p&gt;Their API is incredibly unstable and they break it all the time. Basically every 6 months. The upgrade from 13 to 14 was hard.&lt;/p&gt;

&lt;h2&gt;
  
  
  The hosting infrastructure is much worse
&lt;/h2&gt;

&lt;p&gt;If you host a SPA with a CDN, you can serve 30 million customers a month for a few bucks. If you use NextJS instead, you have a couple of choices:&lt;/p&gt;

&lt;p&gt;Go serverless and be vulnerable to insanely massive bills from a simple naive DDOS&lt;br&gt;
Use ECS/EC2 and then have the potential to lose availability because you scale up too slow during a demand spike (related to point 1 above)&lt;br&gt;
Both choices suck. Both choices will cost you a lot more.&lt;/p&gt;

&lt;p&gt;In addition, you give up the globally distributed nature of a CDN, which caches files near your users. It also handles caching (based on e-tags) between your user and the edge location. It’s a LOT to give up and I’m convinced that many people who think this is a good idea just don’t know wtf a CDN even is, or all it does for you. They’re like the developer in the hero picture of this article.&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>react</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Why NextJS Sucks</title>
      <dc:creator>Afzal Imdad</dc:creator>
      <pubDate>Tue, 20 Aug 2024 13:44:54 +0000</pubDate>
      <link>https://dev.to/afzalimdad9/why-nextjs-sucks-1iom</link>
      <guid>https://dev.to/afzalimdad9/why-nextjs-sucks-1iom</guid>
      <description>&lt;p&gt;I’ve used NextJS for static websites because the experience with amplify hosting is so insanely easy. The fact that I go on the AWS console and connect a github repo and it just works, and runs with lambda, and is super cheap (unless I get DDOS’d)… that’s just too good to say no to in some cases.&lt;/p&gt;

&lt;p&gt;Even though server side rendering hasn’t been required in years in order for google to index and find your content, the developer experience for toy websites is too good to pass up.&lt;/p&gt;

&lt;p&gt;But for a complex SaaS project, I see very few benefits and some serious downsides of NextJS.&lt;/p&gt;

&lt;h2&gt;
  
  
  NodeJS sucks for SSR
&lt;/h2&gt;

&lt;p&gt;𝐑𝐞𝐚𝐜𝐭 𝐫𝐞𝐧𝐝𝐞𝐫𝐢𝐧𝐠 𝐨𝐧 𝐭𝐡𝐞 𝐬𝐞𝐫𝐯𝐞𝐫 𝐚𝐝𝐝𝐬 𝐚 𝐝𝐢𝐦𝐞𝐧𝐬𝐢𝐨𝐧 𝐨𝐟 𝐜𝐨𝐦𝐩𝐥𝐞𝐱𝐢𝐭𝐲 𝐭𝐨 𝐭𝐡𝐞 𝐚𝐩𝐩𝐥𝐢𝐜𝐚𝐭𝐢𝐨𝐧 𝐛𝐞𝐜𝐚𝐮𝐬𝐞 𝐲𝐨𝐮’𝐫𝐞 𝐦𝐚𝐤𝐢𝐧𝐠 𝐍𝐨𝐝𝐞𝐉𝐒 𝐝𝐨 𝐬𝐨𝐦𝐞𝐭𝐡𝐢𝐧𝐠 𝐢𝐭’𝐬 𝐫𝐞𝐚𝐥𝐥𝐲 𝐛𝐚𝐝 𝐚𝐭 𝐝𝐨𝐢𝐧𝐠.&lt;/p&gt;

&lt;p&gt;NodeJs is single threaded. In the ideal case that it’s designed for, requests should be I/O bound. A complex page requiring much SSR will hamstring the ability to serve concurrent requests. Here is a talk by a former coworker of mine on his experience optimizing server side rendering through large demand spikes.&lt;/p&gt;

&lt;p&gt;Now, of course, most apps (including yours) are not going to have the same kind of spikes that Walmart has on black Friday. But you always gotta think about what you’re gaining in exchange of what you're giving up. From what I recall, my friend’s Walmart situation ended up boiling down to NodeJS getting hung up on page rendering for too long, then the operating system’s http request queue would expand too large, because they weren’t configured for load shedding, and the servers would become unresponsive as described in that load shedding article.&lt;/p&gt;

&lt;p&gt;The autoscaling infrastructure would come to the rescue and constantly spin up new servers, but they spent millions of dollars on that, and still experienced availability loss (users getting a broken experience and having to reload). In order to fix it my friend ended up basically having to inject setTimeouts all over the place when rendering the app.&lt;/p&gt;

&lt;p&gt;Now of course there’s ways to avoid all of this such as static site pregeneration, or hosting on serverless. This is part of the reason why serverless is a popular choice for NextJS. But my favorite way of avoiding this particular bit of complexity is just not server-rendering react in nodejs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Security takes a back seat to coolness
&lt;/h2&gt;

&lt;p&gt;Many nextJS features require allowing the browser to inject inline scripts. Nextjs’s implementation of suspense, and also usage of the appDir feature (which you basically always use), using next/font, and anything you put in your rootLayout all gets injected into the app as inline scripts.&lt;/p&gt;

&lt;p&gt;Open up any nextJS website and you'll see a bunch of inline scripts like the screenshot below, from one of my NextJS pages:&lt;/p&gt;

&lt;p&gt;Those are a bunch of inline scripts. Inline scripts are bad, because the only actually reliable way to prevent reflected XSS attacks is with content security policy headers that prevent the execution of inline scripts. A strong CSP policy is the golden standard for XSS prevention. And the main thing you need to do from a CSP standpoint is to avoid inline scripts.&lt;/p&gt;

&lt;p&gt;If you just instruct the browser to not execute inline scripts, stored XSS is impossible. But if you use any of the NextJS features that require inline scripts, you cannot have a CSP policy to forbid inline scripts. Because of that, you have to settle for something worse, which is allowing only inline scripts that match a certain nonce (computed randomly at load time).&lt;/p&gt;

&lt;p&gt;In order to do that with nextJS, you have to write a significant amount of code and jump through hoops (see docs on how to do it if you want your head to spin). Fun side effect of this is, even if you put a CDN in front of your NextJS cluster, there won't be any edge location caching because the nonce has to be different for every session (if it's not, it defeats the purpose of the nonce and you might as well just allow inline scripts).&lt;/p&gt;

&lt;h2&gt;
  
  
  NextJS doesn’t respect your time
&lt;/h2&gt;

&lt;p&gt;Their API is incredibly unstable and they break it all the time. Basically every 6 months. The upgrade from 13 to 14 was hard.&lt;/p&gt;

&lt;h2&gt;
  
  
  The hosting infrastructure is much worse
&lt;/h2&gt;

&lt;p&gt;If you host a SPA with a CDN, you can serve 30 million customers a month for a few bucks. If you use NextJS instead, you have a couple of choices:&lt;/p&gt;

&lt;p&gt;Go serverless and be vulnerable to insanely massive bills from a simple naive DDOS&lt;br&gt;
Use ECS/EC2 and then have the potential to lose availability because you scale up too slow during a demand spike (related to point 1 above)&lt;br&gt;
Both choices suck. Both choices will cost you a lot more.&lt;/p&gt;

&lt;p&gt;In addition, you give up the globally distributed nature of a CDN, which caches files near your users. It also handles caching (based on e-tags) between your user and the edge location. It’s a LOT to give up and I’m convinced that many people who think this is a good idea just don’t know wtf a CDN even is, or all it does for you. They’re like the developer in the hero picture of this article.&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>react</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>10 GitHub repositories to become a better JavaScript Developer</title>
      <dc:creator>Afzal Imdad</dc:creator>
      <pubDate>Sun, 18 Aug 2024 13:36:00 +0000</pubDate>
      <link>https://dev.to/afzalimdad9/10-github-repositories-to-become-a-better-javascript-developer-5haa</link>
      <guid>https://dev.to/afzalimdad9/10-github-repositories-to-become-a-better-javascript-developer-5haa</guid>
      <description>&lt;p&gt;With the introduction of libraries and Frameworks like ReactJS, VueJS, Angular, SvelteJS and much more and the runtime environments like Node.js and Deno the demand for JavaScript Developers has exploded. From seed startups to the big tech companies, everyone is using JavaScript in one or the other form.&lt;/p&gt;

&lt;p&gt;Be it a library like ReactJS or complex Frameworks like Angular or runtime environments like Node.js and Deno. They all have one thing in common that they can be used to write JavaScript code in a more structured, robust and scalable manner which can be easy to maintain, debug and scale .&lt;/p&gt;

&lt;p&gt;With that being said it becomes more important for you as a JavaScript Developer to level up your skills with the best practices and concepts regarding it.&lt;/p&gt;

&lt;p&gt;In this post I've included 10 such GitHub repositories which will help you to become a better JavaScript Developer and will also help you to follow best practices, clear your concepts and write scalable and clean code.&lt;/p&gt;

&lt;h1&gt;
  
  
  1. &lt;a href="https://github.com/airbnb/javascript" rel="noopener noreferrer"&gt;JavaScript Style Guide&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;GitHub🌟: 111K+&lt;/p&gt;

&lt;p&gt;This repository includes style guides for JavaScript, React, CSS-in-JavaScript,CSS &amp;amp; SaSS and Ruby. It is having the code snippets with good and bad practices followed the explanations and references which will help you to write more robust,clean and error free code.&lt;/p&gt;

&lt;h1&gt;
  
  
  2. &lt;a href="https://github.com/goldbergyoni/nodebestpractices" rel="noopener noreferrer"&gt;Node Best Practices&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;GitHub🌟: 68K+&lt;/p&gt;

&lt;p&gt;This repository is a summary and curation of the top-ranked content on Node.js best practices. It has the largest compilation and it is growing every week. Currently more than 80 best practices, style guides and architectural tips are presented.&lt;/p&gt;

&lt;h1&gt;
  
  
  3. [JavaScript Algorithms
&lt;/h1&gt;

&lt;p&gt;](&lt;a href="https://github.com/trekhleb/javascript-algorithms" rel="noopener noreferrer"&gt;https://github.com/trekhleb/javascript-algorithms&lt;/a&gt;)&lt;br&gt;
GitHub🌟: 113K+&lt;/p&gt;

&lt;p&gt;This repository contains JavaScript based examples of many popular algorithms and data structures.&lt;br&gt;
Each algorithm and data structure has its own separate README with related explanations and links for further reading (including ones to YouTube videos).&lt;/p&gt;

&lt;h1&gt;
  
  
  4. &lt;a href="https://github.com/lydiahallie/javascript-questions" rel="noopener noreferrer"&gt;JavaScript Questions&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;GitHub🌟: 35K+&lt;/p&gt;

&lt;p&gt;This repository contains a long list of (advanced) JavaScript questions along with their explanations and gets frequently updated.&lt;/p&gt;

&lt;h1&gt;
  
  
  5. &lt;a href="https://github.com/leonardomso/33-js-concepts" rel="noopener noreferrer"&gt;33 JS Concepts&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;GitHub🌟: 41K+&lt;/p&gt;

&lt;p&gt;This repository is a collection of articles and books on the 33 JavaScript Concepts which every JavaScript Developer should know in order to have an in-depth knowledge of the language and its working.&lt;/p&gt;

&lt;h1&gt;
  
  
  6. &lt;a href="https://github.com/ryanmcdermott/clean-code-javascript" rel="noopener noreferrer"&gt;Clean Code JavaScript&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;GitHub🌟: 53K+&lt;/p&gt;

&lt;p&gt;This repository consists of the software engineering principles, from Robert C. Martin's book Clean Code, adapted for JavaScript. It's a guide for producing readable, reusable and refactorable software in JavaScript.&lt;/p&gt;

&lt;h1&gt;
  
  
  7. &lt;a href="https://github.com/getify/You-Dont-Know-JS" rel="noopener noreferrer"&gt;You Don't Know JS&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;GitHub🌟: 142K+&lt;/p&gt;

&lt;p&gt;This is a series of books diving deep into the core mechanisms of the JavaScript language. The 2nd edition of the series is currently in progress, while the first edition is available here&lt;/p&gt;

&lt;h1&gt;
  
  
  8. &lt;a href="https://github.com/sorrycc/awesome-javascript" rel="noopener noreferrer"&gt;Awesome JavaScript&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;GitHub🌟: 24K+&lt;/p&gt;

&lt;p&gt;A collection of awesome browser-side JavaScript libraries and resources. This repository contains a list of variety of frameworks, template engines, articles and post, documentations, reactive &amp;amp; functional programming and much more which will increase your resourcefulness and might also help you to choose the tech stack for your next projects.&lt;/p&gt;

&lt;h1&gt;
  
  
  9. &lt;a href="https://github.com/30-seconds/30-seconds-of-code" rel="noopener noreferrer"&gt;30 seconds of Code&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;GitHub🌟: 79K+&lt;/p&gt;

&lt;p&gt;This repository contains a huge collection of short JavaScript code snippets which can be super useful while working on your JavaScript projects thus increasing your efficiency and knowledge.&lt;/p&gt;

&lt;h1&gt;
  
  
  10. &lt;a href="https://github.com/elsewhencode/project-guidelines" rel="noopener noreferrer"&gt;Project Guidelines&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;GitHub🌟: 24K+&lt;/p&gt;

&lt;p&gt;This repository contains a set of best practices for JavaScript projects which will develop your skills to follow the best practices this skill is super useful and important for any developer and will definitely help you to stand apart from the other developers. Following the best practices in your JavaScript projects will definitely increase your chance of being accepted for a job position.&lt;/p&gt;

&lt;h1&gt;
  
  
  Bonus
&lt;/h1&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://github.com/pawelborkar/awesome-repos" rel="noopener noreferrer"&gt;Awesome Repos&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;Awesome Repos has a number of resourceful repositories packed in just one place. All you have to do is just visit this repository. The repository is still growing and welcomes PRs.&lt;/p&gt;

&lt;h1&gt;
  
  
  &lt;a href="https://github.com/Vishal-raj-1/Awesome-JavaScript-Projects" rel="noopener noreferrer"&gt;Awesome JavaScript Projects&lt;/a&gt;
&lt;/h1&gt;

&lt;p&gt;If you are a beginner or new to JavaScript and want to improve your JavaScript skills by building projects then this repository can be super helpful for you. It contains a collection of projects written in vanilla JavaScript (with NO FRAMEWORKS &amp;amp; LIBRARIES INVOLVED).&lt;/p&gt;

&lt;h1&gt;
  
  
  Vote Of Thanks
&lt;/h1&gt;

&lt;p&gt;Thank you so much for reading this post and I hope you find these repositories as useful as I do and will help you to become better JavaScript developer. Feel Free to give any suggestions and if you like my work you can follow me on medium&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>productivity</category>
      <category>beginners</category>
      <category>github</category>
    </item>
    <item>
      <title>Integrating Capacitor with Next.js: A Step-by-Step Guide</title>
      <dc:creator>Afzal Imdad</dc:creator>
      <pubDate>Sat, 27 Jul 2024 14:34:19 +0000</pubDate>
      <link>https://dev.to/afzalimdad9/integrating-capacitor-with-nextjs-a-step-by-step-guide-50d3</link>
      <guid>https://dev.to/afzalimdad9/integrating-capacitor-with-nextjs-a-step-by-step-guide-50d3</guid>
      <description>&lt;p&gt;In this guide, we’ll walk through how to integrate Capacitor with a Next.js project to build cross-platform mobile apps. Capacitor is a powerful tool that helps turn web applications into native mobile experiences.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Prerequisites&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Before you start, ensure you have the following installed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Node.js and npm&lt;/li&gt;
&lt;li&gt;Next.js&lt;/li&gt;
&lt;li&gt;Android Studio (for Android development)&lt;/li&gt;
&lt;li&gt;Xcode (for iOS development, macOS only)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Step 1: Set Up Next.js Project&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;First, set up your Next.js project if you haven’t already:&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
cd your-next-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Step 2: Install Capacitor&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Next, install Capacitor core and CLI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install @capacitor/core
npm install -D @capacitor/cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initialize Capacitor in your project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx cap init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Follow the prompts to configure your app. For example:&lt;/p&gt;

&lt;p&gt;appId: &lt;code&gt;com.example.app&lt;/code&gt;&lt;br&gt;
appName: &lt;code&gt;example&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Step 3: Configure Capacitor&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Create or update the capacitor.config.ts file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import type { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = {
  appId: 'com.example.app',
  appName: 'example',
  webDir: 'out', // Ensure this matches your Next.js output directory
};
export default config;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Step 4: Install Platform Plugins&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Install the Capacitor platform plugins for Android and iOS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install @capacitor/android @capacitor/ios 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Step 5: Add Platforms&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Add the Android and iOS platforms to your project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx cap add android
npx cap add ios
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Step 6: Configure Next.js for Static Export&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Update your &lt;code&gt;next.config.mjs&lt;/code&gt; to enable static exports and disable image optimization:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  images: {
    unoptimized: true,
  },
  output: 'export',
};
export default nextConfig;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Step 7: Build and Export Your Project&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Build and export your Next.js project:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After a successful build, if the folder and file structure looks like this, the specific file names do not matter. It means the build was successful&lt;/p&gt;

&lt;p&gt;After a successful build, if the folder and file structure looks like this, the specific file names do not matter. It means the build was successful.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Step 8: Sync Capacitor&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Sync the Capacitor configuration and assets:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx cap sync
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Step 9: Open and Run the Android Project&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Open your Android project in Android Studio:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx cap open android
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run your app on an Android device or emulator directly from Android Studio.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Step 10: Open and Run the iOS Project&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;For macOS users, open your iOS project in Xcode:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx cap open ios
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run your app on an iOS device or simulator from Xcode.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Step 11:Generate Apk&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Before generate apk file you must have to create keyStore:&lt;/p&gt;

&lt;p&gt;keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000&lt;br&gt;
Enter keystore password: 123456&lt;br&gt;
Enter key return password for : 123456&lt;br&gt;
What is your first and last name?&lt;br&gt;

What is the name of your organizational unit?&lt;br&gt;

What is the name of your organization?&lt;br&gt;

What is the name of your City or Locality?&lt;br&gt;

What is the name of your State or Province?&lt;br&gt;

What is the two-letter country code for this unit?&lt;br&gt;

Is CN=your name, OU=your organizational unit, O=your organization, L=your city, ST=your state, C=your country correct?&lt;/p&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;Step 12:Change the file Directory&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;move &lt;code&gt;my-release-key.keystore&lt;/code&gt; file into Android folder&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx cap build android --keystorepath my-release-key.keystore --keystorepass 123456 --keystorealias alias_name --keystorealiaspass 123456 --androidreleasetype APK
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Step 13:Build Apk&lt;/strong&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx cap build android
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Step 14:Build Apk Directory&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;android&amp;gt;app&amp;gt;build&amp;gt;apk&amp;gt;release&lt;/code&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>programming</category>
      <category>ionic</category>
    </item>
    <item>
      <title>10 Expert Performance Tips Every Senior JS React Developer Should Know</title>
      <dc:creator>Afzal Imdad</dc:creator>
      <pubDate>Sat, 22 Jun 2024 18:17:46 +0000</pubDate>
      <link>https://dev.to/afzalimdad9/10-expert-performance-tips-every-senior-js-react-developer-should-know-4hl8</link>
      <guid>https://dev.to/afzalimdad9/10-expert-performance-tips-every-senior-js-react-developer-should-know-4hl8</guid>
      <description>&lt;p&gt;Elevate your React development skills with 10 advanced performance tips tailored for senior JavaScript developers. Learn how to optimize your code and enhance the efficiency of your React applications. Master the techniques that will set you apart in the competitive world of web development.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0qey3z5hg5o6sku49eet.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0qey3z5hg5o6sku49eet.png" alt="Image description" width="700" height="394"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Use useMemo for Expensive Calculations
&lt;/h2&gt;

&lt;p&gt;When performing expensive calculations or data transformations, use the &lt;code&gt;useMemo&lt;/code&gt; hook to memoize the result and prevent unnecessary re-calculations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useMemo } from 'react';

const MyComponent = ({ data }) =&amp;gt; {
  const transformedData = useMemo(() =&amp;gt; {
    // Perform expensive data transformation here
    return data.map(item =&amp;gt; item * 2);
  }, [data]);
  return (
    &amp;lt;div&amp;gt;
      {/* Use transformedData here */}
    &amp;lt;/div&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Use useCallback for Memoized Functions
&lt;/h2&gt;

&lt;p&gt;When passing callback functions as props, use the &lt;code&gt;useCallback&lt;/code&gt; hook to memoize the function and prevent unnecessary re-renders of child components.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useCallback } from 'react';

const ParentComponent = () =&amp;gt; {
  const handleButtonClick = useCallback(() =&amp;gt; {
    // Handle button click here
  }, []);
  return (
    &amp;lt;ChildComponent onClick={handleButtonClick} /&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Use React.memo for Performance Optimization
&lt;/h2&gt;

&lt;p&gt;To optimize functional components, use the &lt;code&gt;React.memo&lt;/code&gt; higher-order component to memoize the component and prevent re-rendering if the props haven't changed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';

const MyComponent = React.memo(({ prop1, prop2 }) =&amp;gt; {
  // Render component here
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Use Virtualized Lists for Efficient Rendering
&lt;/h2&gt;

&lt;p&gt;For long lists, use a virtualized list library like &lt;code&gt;react-window&lt;/code&gt; or &lt;code&gt;react-virtualized&lt;/code&gt; to only render visible items, thus improving rendering performance.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';
import { FixedSizeList } from 'react-window';

const MyListComponent = ({ data }) =&amp;gt; {
  const renderRow = ({ index, style }) =&amp;gt; {
    const item = data[index];
    return (
      &amp;lt;div style={style}&amp;gt;{item}&amp;lt;/div&amp;gt;
    );
  };
  return (
    &amp;lt;FixedSizeList
      height={300}
      width={300}
      itemSize={50}
      itemCount={data.length}
    &amp;gt;
      {renderRow}
    &amp;lt;/FixedSizeList&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  5. Use Code Splitting for Lazy Loading
&lt;/h2&gt;

&lt;p&gt;Split your code into smaller chunks and load them lazily using dynamic imports and React's &lt;code&gt;lazy&lt;/code&gt; and &lt;code&gt;Suspense&lt;/code&gt; components. This improves initial load time and only loads necessary code when needed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { lazy, Suspense } from 'react';

const LazyComponent = lazy(() =&amp;gt; import('./LazyComponent'));
const App = () =&amp;gt; {
  return (
    &amp;lt;Suspense fallback={&amp;lt;div&amp;gt;Loading...&amp;lt;/div&amp;gt;}&amp;gt;
      &amp;lt;LazyComponent /&amp;gt;
    &amp;lt;/Suspense&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  6. Use Memoization for Expensive Calculations
&lt;/h2&gt;

&lt;p&gt;Memoization involves caching the results of expensive function calls and returning the cached result when the same inputs occur again, saving unnecessary computations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const memoizedExpensiveFunction = useMemo(() =&amp;gt; {
  // Expensive computation here
}, [input]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  7. Optimize Rendering with React.Fragment
&lt;/h2&gt;

&lt;p&gt;When rendering multiple elements without a container element, use &lt;code&gt;React.Fragment&lt;/code&gt; or the shorthand syntax &lt;code&gt;&amp;lt;&amp;gt;...&amp;lt;/&amp;gt;&lt;/code&gt; to avoid excess DOM nodes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from 'react';

const MyComponent = () =&amp;gt; {
  return (
    &amp;lt;&amp;gt;
      &amp;lt;div&amp;gt;Element 1&amp;lt;/div&amp;gt;
      &amp;lt;div&amp;gt;Element 2&amp;lt;/div&amp;gt;
    &amp;lt;/&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  8. Use Function Components with Hooks
&lt;/h2&gt;

&lt;p&gt;Use function components with hooks instead of class-based components as they offer simpler and more performant code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState } from 'react';

const MyComponent = () =&amp;gt; {
  const [count, setCount] = useState(0);
  const handleIncrement = () =&amp;gt; {
    setCount(count + 1);
  };
  return (
    &amp;lt;div&amp;gt;
      &amp;lt;button onClick={handleIncrement}&amp;gt;Increment&amp;lt;/button&amp;gt;
      &amp;lt;p&amp;gt;Count: {count}&amp;lt;/p&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  9. Avoid Inline Function Definitions
&lt;/h2&gt;

&lt;p&gt;Avoid defining functions inline within render methods as they create a new reference on each render, leading to unnecessary re-renders of child components.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useCallback } from 'react';
const ParentComponent = () =&amp;gt; {
  const handleButtonClick = useCallback(() =&amp;gt; {
    // Handle button click here
  }, []);
  return (
    &amp;lt;ChildComponent onClick={handleButtonClick} /&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  10. Use &lt;code&gt;React.PureComponent&lt;/code&gt; or &lt;code&gt;React.memo&lt;/code&gt; for Performance Optimization
&lt;/h2&gt;

&lt;p&gt;Use &lt;code&gt;React.PureComponent&lt;/code&gt; or &lt;code&gt;React.memo&lt;/code&gt; to prevent unnecessary re-rendering of components by performing shallow prop comparisons.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { PureComponent } from 'react';
class MyComponent extends PureComponent {
  render() {
    // Render component here
  }
}
export default MyComponent;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These performance tips can help improve the efficiency and responsiveness of your ReactJS applications. Utilizing functional architecture, memoization, and code-splitting techniques can greatly enhance the overall performance of your React components.&lt;/p&gt;

&lt;p&gt;Don't be shy to clap, consider clap if you find this useful. If you want you can clap multiple times also :P, just try :D&lt;/p&gt;

&lt;p&gt;Thank you for reading until the end. Before you go:&lt;br&gt;
Please consider clapping and following the writer! 👏&lt;/p&gt;

</description>
      <category>react</category>
      <category>frontend</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Cookie consent in NextJs</title>
      <dc:creator>Afzal Imdad</dc:creator>
      <pubDate>Mon, 10 Jun 2024 04:27:39 +0000</pubDate>
      <link>https://dev.to/afzalimdad9/cookie-consent-in-nextjs-4gnn</link>
      <guid>https://dev.to/afzalimdad9/cookie-consent-in-nextjs-4gnn</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu88fo5xgv29rnaaishwg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu88fo5xgv29rnaaishwg.png" alt="Image description" width="720" height="408"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This article discusses how to add cookie consent to a NextJs app using &lt;code&gt;cookies-next&lt;/code&gt; package.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Install the required packages:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;To install the package, type one of the following commands based on your package manager&lt;/p&gt;

&lt;p&gt;For npm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install cookies-next
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For yarn:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add cookies-next
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Cookie consent implementation:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;When there is no cookie present, the cookie consent popup should be shown.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;cookies-next&lt;/code&gt; package has &lt;code&gt;hasCookie&lt;/code&gt;, &lt;code&gt;setCookie&lt;/code&gt; functions with which the cookies can be accessed and managed. Here is how its managed in a React component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [showConsent, setShowConsent] = React.useState(true);
React.useEffect(() =&amp;gt; {
  setShowConsent(hasCookie("localConsent"));
}, []);
const acceptCookie = () =&amp;gt; {
  setShowConsent(true);
  setCookie("localConsent", "true", {});
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is a full example of how a cookie consent component works in Next.js. Add the component to your &lt;code&gt;pages/index.js&lt;/code&gt; to be visible.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from "react";
import { hasCookie, setCookie } from "cookies-next";

const CookieConsent = (props) =&amp;gt; {
  const [showConsent, setShowConsent] = React.useState(true);

  React.useEffect(() =&amp;gt; {
    setShowConsent(hasCookie("localConsent"));
  }, []);

  const acceptCookie = () =&amp;gt; {
    setShowConsent(true);
    setCookie("localConsent", "true", {});
  };

  if (showConsent) {
    return null;
  }

  return (
    &amp;lt;div className="fixed inset-0 bg-slate-700 bg-opacity-70"&amp;gt;
      &amp;lt;div className="fixed bottom-0 left-0 right-0 flex items-center justify-between px-4 py-8 bg-gray-100"&amp;gt;
        &amp;lt;span className="text-dark text-base mr-16"&amp;gt;
          This website uses cookies to improve user experience. By using our website you consent to all cookies in accordance with our Cookie Policy.
        &amp;lt;/span&amp;gt;
        &amp;lt;button className="bg-green-500 py-2 px-8 rounded text-white" onClick={() =&amp;gt; acceptCookie()}&amp;gt;
          Accept
        &amp;lt;/button&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

export default CookieConsent;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: The above example uses tailwindcss. To know more, &lt;a href="https://tailwindcss.com/docs/guides/nextjs" rel="noopener noreferrer"&gt;refer here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqd5lae72ag4o6cc3d1kg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqd5lae72ag4o6cc3d1kg.png" alt="Output" width="720" height="594"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Be Amazed!
&lt;/h2&gt;

&lt;p&gt;Hooray! We have successfully added cookie consent in Next.js.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>nextjs</category>
      <category>programming</category>
    </item>
    <item>
      <title>Stop Using TypeScript Interfaces</title>
      <dc:creator>Afzal Imdad</dc:creator>
      <pubDate>Sun, 09 Jun 2024 07:40:26 +0000</pubDate>
      <link>https://dev.to/afzalimdad9/stop-using-typescript-interfaces-1lc2</link>
      <guid>https://dev.to/afzalimdad9/stop-using-typescript-interfaces-1lc2</guid>
      <description>&lt;h2&gt;
  
  
  Why You Should Use Types Instead
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftgfhiafk0sp30u93xi39.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftgfhiafk0sp30u93xi39.png" alt="This image has been generated by AI" width="720" height="720"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Join our &lt;a href="https://discord.com/invite/C2PXBMqpuV" rel="noopener noreferrer"&gt;Vibrant Discord Community&lt;/a&gt; for exclusive information and insightful discussions&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Types and Interfaces&lt;/strong&gt; are profound features used inside every TypeScript program.&lt;/p&gt;

&lt;p&gt;However, since types and interfaces are quite similar in function, it begs the question: &lt;em&gt;&lt;strong&gt;Which is better?&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Today, we will evaluate types and interfaces, then reach a conclusion as to why you should use types over interfaces in most scenarios.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So without further ado… Lets dive right in.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;So What Are The Differences?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Let’s analyze this &lt;code&gt;Person&lt;/code&gt; &lt;strong&gt;type&lt;/strong&gt; and &lt;strong&gt;interface&lt;/strong&gt; definition:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;type Person = {
  name: string
  age: number
}
interface Person {
  name: string
  age: number
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is clear types and interfaces have similar syntax, with the key difference being that the type uses &lt;code&gt;=&lt;/code&gt; to define the shape of an object unlike the interface.&lt;/p&gt;

&lt;p&gt;However, there is much more to it than this.&lt;/p&gt;

&lt;p&gt;Let’s dig deeper to explore and evaluate types and interfaces together.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Extensibility&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;In terms of extensibility, many argue interfaces are obvious winners since interfaces may extend other interfaces using &lt;code&gt;extends&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Extensibility Example
interface Person extends Job {
  name: string
  age: number
}
interface Job {
  job: string
}
// Properties of Person &amp;amp; Job used.
const person: Person = {
  name: "John",
  age: 25,
  job: "Full-Stack Web Developer",
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here the &lt;code&gt;Person&lt;/code&gt; interface &lt;code&gt;extends&lt;/code&gt; &lt;code&gt;Job&lt;/code&gt;, and as a result the properties of the &lt;code&gt;Job&lt;/code&gt; interface merge into &lt;code&gt;Person&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;On the other hand, types also offer extensibility by leveraging the &lt;strong&gt;union&lt;/strong&gt; &lt;code&gt;|&lt;/code&gt; or &lt;strong&gt;intersection&lt;/strong&gt; &lt;code&gt;&amp;amp;&lt;/code&gt; operators to merge existing types.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Interfaces cannot express this behavior directly.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// ✅ Works 
type Person = {
  name: string
  age: number
} &amp;amp; { job: string }
// ❌ Does not work 
interface Person {
  name: string
  age: number
} &amp;amp; { job: string }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  &lt;strong&gt;Implementation&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Interfaces in TypeScript are compatible with Object Oriented Programming (OOP) like in other languages, e.g. &lt;strong&gt;Java&lt;/strong&gt; or &lt;strong&gt;C#&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This means interfaces can be implemented in classes using &lt;code&gt;implements&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let’s now define &lt;code&gt;Person&lt;/code&gt; as a &lt;code&gt;class&lt;/code&gt;, and implement a new interface called &lt;code&gt;Work&lt;/code&gt; and satisfy the contract between them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Implementation Example
interface Work {
  doWork: () =&amp;gt; void
}
class Person implements Work {
  name: string
  age: number
  constructor(name: string, age: number) {
    this.name = name
    this.age = age
  }
  // doWork method implemented to satisfy the `Work` interface.
  doWork() {
    console.log("Working...")
  }
}
const person = new Person("John", 25)
person.doWork()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Therefore if you use OOP frequently, interfaces will be more applicable than types, as types cannot be directly implemented by classes.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Performance&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;When it comes to performance, we are talking about the performance of &lt;strong&gt;“type-checking”&lt;/strong&gt; done by the TypeScript compiler, which decreases exponentially as your codebase increases in size.&lt;/p&gt;

&lt;p&gt;This is why we benchmark which of types or interfaces are superior in terms of type-checking performance.&lt;/p&gt;

&lt;p&gt;Here is a video where &lt;a href="https://www.mattpocock.com/" rel="noopener noreferrer"&gt;Matt Pocock&lt;/a&gt; explains the differences between types and interfaces, and why there is actually &lt;strong&gt;ZERO&lt;/strong&gt; difference in type-checking performance between types and interfaces.&lt;/p&gt;

&lt;p&gt;Types vs Interfaces: 0 Performance Difference&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Why Interfaces Could be Harmful&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Interfaces in TypeScript have a unique feature called &lt;a href="https://www.typescriptlang.org/docs/handbook/declaration-merging.html" rel="noopener noreferrer"&gt;Declaration Merging&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Declaration merging is when the TypeScript compiler merges &lt;strong&gt;two or more&lt;/strong&gt; interfaces with identical names into &lt;strong&gt;one&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Initial Person Interface
interface Person {
  name: string
  age: number
}
// Refining the Person interface using "Declaration Merging"
interface Person {
  gender: string
}
// Using the "Merged" interface to define a new "person"
const person: Person = { name: "John", age: 25, gender: "Male" }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the one hand, this feature allows for convenient refinement and extension of existing interfaces without changing other dependencies.&lt;/p&gt;

&lt;p&gt;Here is an example of me re-declaring the &lt;code&gt;@auth/core/types&lt;/code&gt; module and refining the &lt;code&gt;Session&lt;/code&gt; interface.&lt;/p&gt;

&lt;p&gt;Refining the &lt;a class="mentioned-user" href="https://dev.to/auth"&gt;@auth&lt;/a&gt;/core interface&lt;/p&gt;

&lt;p&gt;This is an example of &lt;strong&gt;declaration merging&lt;/strong&gt; because I refine the original interface with a new &lt;code&gt;id: string&lt;/code&gt; attribute.&lt;/p&gt;

&lt;p&gt;This is a &lt;strong&gt;justifiable&lt;/strong&gt; use case for interfaces because it allows developers to extend library interfaces with ease.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Types do not permit this since they are immutable after creation.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;On the other hand, declaration merging can have detrimental and surprising effects on your codebase for these two main reasons:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Order of Precedence:&lt;/strong&gt; Later declarations always take precedence of prior ones. If not careful, this could lead to unexpected issues when declaration merging occurs in many parts of your program.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Unsafe Merging with Classes:&lt;/strong&gt; Since the TypeScript compiler doesn’t check for property initialization, this could lead to unexpected runtime errors.&lt;br&gt;
Types do not have this problem, and hence are more straightforward and safe to use as a result.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

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

&lt;p&gt;Unless specific interface behaviour is necessary, e.g. extensible refinement or implementation using OOP, your best bet is to stick with &lt;strong&gt;types&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Types are flexible, straightforward, and avoid pitfalls associated with &lt;strong&gt;declaration merging&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Types are also identical in performance compared to interfaces, providing you another reason to select types over interfaces in your codebase.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
      <category>typescript</category>
    </item>
    <item>
      <title>CSS Art: June</title>
      <dc:creator>Afzal Imdad</dc:creator>
      <pubDate>Sat, 08 Jun 2024 04:52:22 +0000</pubDate>
      <link>https://dev.to/afzalimdad9/css-art-june-1fog</link>
      <guid>https://dev.to/afzalimdad9/css-art-june-1fog</guid>
      <description>&lt;p&gt;&lt;em&gt;This is a submission for &lt;a href="https://dev.to/challenges/frontend-2024-05-29"&gt;Frontend Challenge v24.04.17&lt;/a&gt;, CSS Art: June.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Inspiration
&lt;/h2&gt;

&lt;p&gt;For this CSS Art project themed around June, I focused on representing the vibrant and sunny aspects of the month, particularly the summer solstice. June is often associated with clear blue skies, warm sunshine, and blooming nature. This piece aims to capture the essence of summer with a bright, cheerful scene.&lt;/p&gt;

&lt;h2&gt;
  
  
  Demo
&lt;/h2&gt;

&lt;p&gt;You can view the live demo and edit the code on &lt;a href="https://codepen.io/afzalimdad9/pen/ExzvgrM" rel="noopener noreferrer"&gt;Codepen&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
&amp;lt;meta charset="UTF-8"&amp;gt;
&amp;lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&amp;gt;
&amp;lt;title&amp;gt;CSS Art - June&amp;lt;/title&amp;gt;
&amp;lt;style&amp;gt;
  body {
    margin: 0;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(to top, #87CEEB, #ffffff);
  }
  .scene {
    position: relative;
    width: 300px;
    height: 300px;
  }
  .sun {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 100px;
    height: 100px;
    background: radial-gradient(circle, #FFD700, #FFA500);
    border-radius: 50%;
  }
  .grass {
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 100px;
    background: linear-gradient(to top, #32CD32, #7CFC00);
    border-top-left-radius: 50%;
    border-top-right-radius: 50%;
  }
  .flower {
    position: absolute;
    width: 20px;
    height: 20px;
    background: pink;
    border-radius: 50%;
    box-shadow: 0 0 0 10px white, 0 0 0 20px pink;
  }
  .flower:nth-child(2) {
    top: 220px;
    left: 50px;
  }
  .flower:nth-child(3) {
    top: 200px;
    left: 150px;
  }
  .flower:nth-child(4) {
    top: 230px;
    left: 250px;
  }
  .butterfly {
    position: absolute;
    width: 20px;
    height: 20px;
    background: orange;
    border-radius: 50%;
    box-shadow: 10px 10px 0 orange, -10px 10px 0 orange;
  }
  .butterfly:nth-child(5) {
    top: 50px;
    left: 100px;
  }
  .butterfly:nth-child(6) {
    top: 80px;
    left: 200px;
  }
&amp;lt;/style&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
  &amp;lt;div class="scene"&amp;gt;
    &amp;lt;div class="sun"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div class="grass"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div class="flower"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div class="flower"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div class="flower"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div class="butterfly"&amp;gt;&amp;lt;/div&amp;gt;
    &amp;lt;div class="butterfly"&amp;gt;&amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Journey
&lt;/h2&gt;

&lt;p&gt;The process of creating this CSS Art was a delightful experience. I started by brainstorming the key elements that symbolize June: the sun, clear skies, green grass, flowers, and butterflies. Using pure CSS, I experimented with gradients, positioning, and box shadows to bring these elements to life.&lt;/p&gt;

&lt;h2&gt;
  
  
  Key Learnings:
&lt;/h2&gt;

&lt;p&gt;Gradients and Positioning: Learned to effectively use gradients for the background and different elements.&lt;br&gt;
Box Shadows: Used box shadows creatively to simulate petals and butterfly wings.&lt;/p&gt;

&lt;p&gt;Positioning: Improved my understanding of absolute positioning for placing elements precisely.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'm Proud Of:
&lt;/h2&gt;

&lt;p&gt;I am particularly proud of how the sun and the overall scene came together, creating a warm and inviting representation of June. The butterflies add a dynamic touch, making the scene feel more alive.&lt;/p&gt;

&lt;h2&gt;
  
  
  Future Improvements:
&lt;/h2&gt;

&lt;p&gt;I hope to further refine my skills by adding more complex animations and interactivity to future CSS Art projects, such as making the butterflies flutter or adding a gentle sway to the flowers.&lt;/p&gt;

&lt;p&gt;Thank you for considering my submission!&lt;/p&gt;

</description>
      <category>frontendchallenge</category>
      <category>devchallenge</category>
      <category>css</category>
    </item>
  </channel>
</rss>
