<?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>Forem: Gaël Thomas</title>
    <description>The latest articles on Forem by Gaël Thomas (@gaelgthomas).</description>
    <link>https://forem.com/gaelgthomas</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%2F190354%2F7de5ae02-6b53-4ac1-88ea-6ec53721a7b6.png</url>
      <title>Forem: Gaël Thomas</title>
      <link>https://forem.com/gaelgthomas</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/gaelgthomas"/>
    <language>en</language>
    <item>
      <title>7 Tips To Become a Better Programmer</title>
      <dc:creator>Gaël Thomas</dc:creator>
      <pubDate>Sat, 26 Aug 2023 13:52:07 +0000</pubDate>
      <link>https://forem.com/gaelgthomas/7-tips-to-become-a-better-programmer-2j0k</link>
      <guid>https://forem.com/gaelgthomas/7-tips-to-become-a-better-programmer-2j0k</guid>
      <description>&lt;p&gt;Becoming a better programmer is a journey of continuous learning and growth. Here are 7 tips to help you level up your coding skills and thrive in the tech world:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Practice Consistently&lt;/strong&gt;&lt;br&gt;
Set aside regular time for coding practice. Consistency is critical to improving your skills. If you practice one hour daily, it's 30 hours of training at the end of the month and maybe one or a few projects built.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Learn by Doing&lt;/strong&gt;&lt;br&gt;
Apply what you learn by building projects. Hands-on experience solidifies concepts. When you tackle a new idea, build a mini-project using it (e.g., I'm learning CSS, I'll make a stylized version of my CV).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Read Code&lt;/strong&gt;&lt;br&gt;
Study other people's code, whether open-source projects or tutorials. It's always good to understand different coding styles and patterns. Everyone has a different approach to solving a problem, which will help you learn more.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Embrace Challenges&lt;/strong&gt;&lt;br&gt;
Don't shy away from complex problems. Tackling challenges helps you develop problem-solving skills. From my experience, I learned the most when I struggled. The main reason is that I spent a long time investigating the issue, which taught me many other concepts to solve my problem.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Use Version Control&lt;/strong&gt;&lt;br&gt;
Git and platforms like GitHub are essential. Learning version control helps you collaborate effectively. That's also a base skill when you want to work in a company. Everyone collaborates using these tools, and it's an efficient way to share code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Stay Curious&lt;/strong&gt;&lt;br&gt;
Technology evolves quickly. Stay curious and keep exploring new languages, frameworks, and tools. Don't become obsessed by jumping on each new framework, but be aware of them. There are many YouTube channels, podcasts, and blogs that can help you to do that.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Seek Feedback&lt;/strong&gt;&lt;br&gt;
Share your code and projects for feedback. Constructive criticism helps you improve faster. That's also a mechanism enabled by Git with the review process (used in Open-Source and companies).&lt;/p&gt;

&lt;p&gt;Anything to add? 🚀👇&lt;/p&gt;




&lt;p&gt;&lt;a href="https://twitter.com/gaelgthomas"&gt;Join me on Twitter&lt;/a&gt; for daily content to help you unlock your Web Development skills! 🚀 Let's learn &amp;amp; grow together! 📚&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
      <category>career</category>
    </item>
    <item>
      <title>5 Not-So-Typical React Libraries for an Outstanding Project</title>
      <dc:creator>Gaël Thomas</dc:creator>
      <pubDate>Fri, 04 Aug 2023 01:35:39 +0000</pubDate>
      <link>https://forem.com/gaelgthomas/5-not-so-typical-react-libraries-for-an-outstanding-project-49da</link>
      <guid>https://forem.com/gaelgthomas/5-not-so-typical-react-libraries-for-an-outstanding-project-49da</guid>
      <description>&lt;p&gt;Hello, fellow web developers! 🚀&lt;/p&gt;

&lt;p&gt;It's easy to get swamped with the vast sea of React libraries. While the React ecosystem has many UI component libraries (and don't get me wrong, they're great!), sometimes we want to find something different. That's why I gathered these five libraries.&lt;/p&gt;

&lt;p&gt;And the best part? You can combine these libraries and build a project out of them. Dive in with me!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; For readability purposes, I split each library into three succinct sections: what is it, main functionality, a use-case example, and the link.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  SlateJS
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is it?
&lt;/h3&gt;

&lt;p&gt;SlateJS is your tool to craft delightful, rich text editors without a sweat.&lt;/p&gt;

&lt;h3&gt;
  
  
  Functionality
&lt;/h3&gt;

&lt;p&gt;Build complex editors with custom formatting, embeds, and more.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use-case example
&lt;/h3&gt;

&lt;p&gt;Are you starting an online blog platform? With SlateJS, you can give your users an intuitive, customized text editor that makes crafting and editing blog posts more straightforward.&lt;/p&gt;

&lt;h3&gt;
  
  
  Links
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Website:&lt;/strong&gt; &lt;a href="https://www.slatejs.org/examples/richtext"&gt;https://www.slatejs.org/examples/richtext&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/ianstormtaylor/slate"&gt;https://github.com/ianstormtaylor/slate&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%2Fw5v0ejx3sf8inj6roi4r.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%2Fw5v0ejx3sf8inj6roi4r.png" alt="Slate JS GitHub page" width="800" height="872"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  React-PDF
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is it?
&lt;/h3&gt;

&lt;p&gt;React-PDF is a lifesaver in rendering and styling PDFs right in the browser.&lt;/p&gt;

&lt;h3&gt;
  
  
  Functionality
&lt;/h3&gt;

&lt;p&gt;Directly render PDFs in-browser without any backend. But it also allows you to generate PDFs from your backend using Node.js.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use-case example
&lt;/h3&gt;

&lt;p&gt;Are you creating an e-commerce site? React-PDF can help you generate stylish invoices or reports for each order, all on-the-fly and without a backend service.&lt;/p&gt;

&lt;p&gt;Want a visual overview of React-PDF? Check out this overview video I created on Twitter (X 👀), where I share daily web dev magic! 🎩🪄&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1684173469842567169-798" src="https://platform.twitter.com/embed/Tweet.html?id=1684173469842567169"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1684173469842567169-798');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1684173469842567169&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;h3&gt;
  
  
  Links
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Website:&lt;/strong&gt; &lt;a href="https://react-pdf.org/"&gt;https://react-pdf.org/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/diegomura/react-pdf"&gt;https://github.com/diegomura/react-pdf&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  React-i18next
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is it?
&lt;/h3&gt;

&lt;p&gt;React-i18next is the library to add international vibes to your app.&lt;/p&gt;

&lt;h3&gt;
  
  
  Functionality
&lt;/h3&gt;

&lt;p&gt;Efficiently localize and cater to different languages. It'll enable you to translate each text making your website available in the wording of your choice.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use-case example
&lt;/h3&gt;

&lt;p&gt;Are you planning to launch a globally accessible educational platform? With React-i18next, provide lessons in multiple languages and make learning inclusive for everyone, everywhere.&lt;/p&gt;

&lt;h3&gt;
  
  
  Links
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Website:&lt;/strong&gt; &lt;a href="https://react.i18next.com/"&gt;https://react.i18next.com/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/i18next/react-i18next"&gt;https://github.com/i18next/react-i18next&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%2Fdle44gpnm0e8md0xvshf.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%2Fdle44gpnm0e8md0xvshf.png" alt="React-i18next documentation page" width="800" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Framer Motion
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is it?
&lt;/h3&gt;

&lt;p&gt;Framer Motion helps you to bring fancy animations to your UI.&lt;/p&gt;

&lt;h3&gt;
  
  
  Functionality
&lt;/h3&gt;

&lt;p&gt;Craft fluid animations and transitions for a dynamic user experience.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use-case example
&lt;/h3&gt;

&lt;p&gt;Are you building an interactive portfolio? Impress your visitors with Framer Motion's elegant animations as they navigate your projects and experiences.&lt;/p&gt;

&lt;h3&gt;
  
  
  Links
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Website:&lt;/strong&gt; &lt;a href="https://www.framer.com/motion/"&gt;https://www.framer.com/motion/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/framer/motion"&gt;https://github.com/framer/motion&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%2Fq23lzi3iari1j2h6na2e.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%2Fq23lzi3iari1j2h6na2e.png" alt="Framer Motion documentation page" width="800" height="496"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Mantine
&lt;/h2&gt;

&lt;h3&gt;
  
  
  What is it?
&lt;/h3&gt;

&lt;p&gt;Mantine is like having a Swiss army knife with high-quality components and hooks for your React apps.&lt;/p&gt;

&lt;h3&gt;
  
  
  Functionality
&lt;/h3&gt;

&lt;p&gt;Fast-track development with top-notch components without sacrificing style.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use-case example
&lt;/h3&gt;

&lt;p&gt;Are you designing a startup's landing page? Use Mantine to whip up a stylish, functional site in record time.&lt;/p&gt;

&lt;h3&gt;
  
  
  Links
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Website:&lt;/strong&gt; &lt;a href="https://mantine.dev/"&gt;https://mantine.dev/&lt;/a&gt; and &lt;a href="https://ui.mantine.dev/"&gt;https://ui.mantine.dev/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;GitHub:&lt;/strong&gt; &lt;a href="https://github.com/mantinedev/mantine"&gt;https://github.com/mantinedev/mantine&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%2Fl71g2h1220p86hmx86jn.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%2Fl71g2h1220p86hmx86jn.png" alt="Mantine home page" width="800" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping Up 😄
&lt;/h2&gt;

&lt;p&gt;There you have it! Five libraries to supercharge your next React project. If you found this useful or want to chat, swing by my Twitter (I mean X 👀)!&lt;/p&gt;

&lt;p&gt;I drop web development content daily and share my experience as a remote software engineer traveling in Asia. Let's ride the waves of web development together!&lt;/p&gt;

&lt;p&gt;➡️ &lt;a href="https://twitter.com/gaelgthomas"&gt;https://twitter.com/gaelgthomas&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;I hope this article inspires your React journey and also your next project. ✨ Happy coding! 🚀&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
      <category>frontend</category>
    </item>
    <item>
      <title>Step up Your VSCode Game With These 10 Must-Have Extensions</title>
      <dc:creator>Gaël Thomas</dc:creator>
      <pubDate>Mon, 06 Feb 2023 17:00:46 +0000</pubDate>
      <link>https://forem.com/gaelgthomas/step-up-your-vscode-game-with-these-10-must-have-extensions-1ik5</link>
      <guid>https://forem.com/gaelgthomas/step-up-your-vscode-game-with-these-10-must-have-extensions-1ik5</guid>
      <description>&lt;p&gt;Are you looking to take your VSCode game to the next level? Look no further! In this article, we will explore 10 must-have extensions that will enhance your workflow, productivity and make your coding experience even more enjoyable.&lt;/p&gt;

&lt;p&gt;Let's use this article as a place where everyone can discover powerful extensions. Feel free to share your favorite extensions in the comments below, and let's expand our VSCode toolkit together!&lt;/p&gt;

&lt;h2&gt;
  
  
  Project Manager 📁
&lt;/h2&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%2F0l60yf1qgag7f6xj3sgh.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%2F0l60yf1qgag7f6xj3sgh.png" width="800" height="100"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Are you tired of constantly searching for your projects in different folders or repositories? If yes, this extension is for you!&lt;/p&gt;

&lt;p&gt;Project Manager allows you to always keep track of your projects. With it, you can easily access and organize your projects, no matter where they are on your computer.&lt;/p&gt;

&lt;p&gt;It comes with many features, such as the possibility to add tags to your repositories.&lt;/p&gt;

&lt;p&gt;➡️ &lt;a href="https://marketplace.visualstudio.com/items?itemName=alefragnani.project-manager" rel="noopener noreferrer"&gt;Download the "Project Manager" extension&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  GitLens — Git supercharged 🔎
&lt;/h2&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%2Fabocyb0kiywsmwz6dnd1.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%2Fabocyb0kiywsmwz6dnd1.png" width="800" height="118"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Even if I use an external application to manage my Git repository, I like using GitLens because it brings Git insights right inside VSCode.&lt;/p&gt;

&lt;p&gt;One of my favorite features is the ability to visualize code authorship. When working on a repository with other developers, GitLens makes it easy to see who wrote what and when which saves me time. And, if I need to compare a branch with another one, GitLens makes it a breeze.&lt;/p&gt;

&lt;p&gt;But this extension has even more features than that, and I'm sure you'll love them!&lt;/p&gt;

&lt;p&gt;➡️ &lt;a href="https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens" rel="noopener noreferrer"&gt;Download the "GitLens" extension&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Colorize 🎨
&lt;/h2&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%2Fzxc5h0n5ogjd0coosuyy.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%2Fzxc5h0n5ogjd0coosuyy.png" width="800" height="100"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This extension makes colors more visual in your code by generating a colored background for each of them. I like to use it because it makes my IDE more colorful and easy to read.&lt;/p&gt;

&lt;p&gt;Below, here's a demonstration coming from the extension page.&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%2Fpw7yiulwzavh0amjbqvr.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%2Fpw7yiulwzavh0amjbqvr.png" width="800" height="465"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;➡️ &lt;a href="https://marketplace.visualstudio.com/items?itemName=kamikillerto.vscode-colorize" rel="noopener noreferrer"&gt;Download the "Colorize" extension&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Better Comments 💬
&lt;/h2&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%2Fbsep24bcudk9jpvhmqr0.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%2Fbsep24bcudk9jpvhmqr0.png" width="800" height="100"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Writing clear and concise comments in your code is essential as a developer. But sometimes, more than plain text comments are needed to communicate effectively with your team or future self. That's where the Better Comments extension comes in.&lt;/p&gt;

&lt;p&gt;I mainly use Better comments to make my TODO comments stand out, but you can use it with many other annotations. For example, if you're adding an alert, making a query, creating a TODO, or highlighting important information.&lt;/p&gt;

&lt;p&gt;Here's an example coming from their extension page.&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%2Ffmepjiv41f4z7dtm6uuf.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%2Ffmepjiv41f4z7dtm6uuf.png" width="800" height="726"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;➡️ &lt;a href="https://marketplace.visualstudio.com/items?itemName=aaron-bond.better-comments" rel="noopener noreferrer"&gt;Download the "Better Comments" extension&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Code Spell Checker ✅
&lt;/h2&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%2Fjvkih3g80rm0t0fnqy6x.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%2Fjvkih3g80rm0t0fnqy6x.png" width="800" height="100"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Do you want to ensure your code is always pretty and grammatically correct? I have an extension for you!&lt;/p&gt;

&lt;p&gt;Code Spell Checker is a spellchecker for coders. It'll help you to catch spelling errors by highlighting them in your code.&lt;/p&gt;

&lt;p&gt;➡️ &lt;a href="https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker" rel="noopener noreferrer"&gt;Download the "Code Spell Checker" extension&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Live Server 🎙️
&lt;/h2&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%2Frafcnsxdplv6pgbyx6fw.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%2Frafcnsxdplv6pgbyx6fw.png" width="800" height="99"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In a few words, this extension allows you to launch a local development server with a live reload feature for static and dynamic pages.&lt;/p&gt;

&lt;p&gt;For example, let's say you're working on a static website project; you can launch a server that will listen to the changes you make to the page and auto-reload accordingly (e.g., a portfolio, a simple HTML page, etc.).&lt;/p&gt;

&lt;p&gt;It can also be helpful if you want to do some tests on a simple web codebase.&lt;/p&gt;

&lt;p&gt;➡️ &lt;a href="https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer" rel="noopener noreferrer"&gt;Download the "Live Server" extension&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Prettier - Code formatter ✍️
&lt;/h2&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%2Fm1yqw4e70p4xo80s89sq.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%2Fm1yqw4e70p4xo80s89sq.png" width="800" height="100"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As per its name, Prettier is a code formatter. If you're like me and like to have your code auto-formatted whenever you save your changes, this extension is for you!&lt;/p&gt;

&lt;p&gt;It'll ensure that all code conforms to a consistent style.&lt;/p&gt;

&lt;p&gt;➡️ &lt;a href="https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode" rel="noopener noreferrer"&gt;Download the "Prettier" extension&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  ESLint 📘
&lt;/h2&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%2Fdxqrveehtx0abqcx723w.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%2Fdxqrveehtx0abqcx723w.png" width="800" height="100"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This one is well-known and used by most projects in JavaScript! ✨&lt;/p&gt;

&lt;p&gt;ESLint is a static code analysis tool. It helps you to catch potential errors and enforce consistent code styles in your projects. It ensures that your code adheres to a set of coding standards and improves the maintainability of your codebase.&lt;/p&gt;

&lt;p&gt;Additionally, it'll help you catch common mistakes and potential problems early on.&lt;/p&gt;

&lt;p&gt;Something handy is this tool is highly customizable. Indeed, you can configure it to match your specific coding style and the requirements of your project. For example, you can make your project follow the &lt;a href="https://www.npmjs.com/package/eslint-config-airbnb" rel="noopener noreferrer"&gt;Airbnb style using ESLint&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;➡️ &lt;a href="https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint" rel="noopener noreferrer"&gt;Download the "ESLint" extension&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Import Cost 💰
&lt;/h2&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%2Fz3yac0pyb6wu9g83csxb.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%2Fz3yac0pyb6wu9g83csxb.png" width="800" height="100"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here's what you can find on the Import Cost extension page: "This extension will display inline in the editor the size of the imported package.".&lt;/p&gt;

&lt;p&gt;I love using it because it's a small package that can make you more conscious about the libraries you are importing. Also, it helps to catch non-optimized imports (e.g., with Lodash).&lt;/p&gt;

&lt;p&gt;➡️ &lt;a href="https://marketplace.visualstudio.com/items?itemName=wix.vscode-import-cost" rel="noopener noreferrer"&gt;Download the "Import Cost" extension&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Auto Rename Tag 🔖
&lt;/h2&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%2Fwuasmi2zhfyi3dnm8bix.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%2Fwuasmi2zhfyi3dnm8bix.png" width="800" height="99"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This handy extension can effortlessly keep your HTML/XML tags in perfect harmony. It's like having a tag-renaming ninja right at your fingertips!&lt;/p&gt;

&lt;p&gt;You won't have this kind of compilation problem anymore:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Fix my tag!&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- Without Auto Rename Tag --&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
      You need to edit the tag twice
    &lt;span class="nt"&gt;&amp;lt;/span&amp;gt;&lt;/span&gt;

    &lt;span class="c"&gt;&amp;lt;!-- With Auto Rename Tag --&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
      You need to edit the tag once
    &lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;➡️ &lt;a href="https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-rename-tag" rel="noopener noreferrer"&gt;Download the "Auto Rename Tag" extension&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus: Bracket Pair Colorizer 🖌️
&lt;/h2&gt;

&lt;p&gt;I could not have finished this article without a bonus! 🎁&lt;/p&gt;

&lt;p&gt;Previous Bracket Pair Colorizer was an extension, but in a recent release, VSCode integrated this as a setting in the IDE. If like me, you're coding in JavaScript, you probably got lost in the indentation of parenthesis and brackets.&lt;/p&gt;

&lt;p&gt;Thanks to this, you'll not meet the issue anymore. Indeed, this setting will highlight your parenthesis and brackets by pair. Here's an example from the Bracket Pair Colorized page:&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%2Fon9quvgmzec0tm0ti0ph.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%2Fon9quvgmzec0tm0ti0ph.png" width="800" height="155"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, the first &lt;code&gt;{}&lt;/code&gt; are pink, and the second &lt;code&gt;{}&lt;/code&gt; are blue. It becomes even more helpful in more complex operations.&lt;/p&gt;

&lt;p&gt;If you want to enable this option, you need to add these instructions in your VSCode &lt;code&gt;settings.json&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"editor.bracketPairColorization.enabled"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"editor.guides.bracketPairs"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"active"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  That’s a Wrap!
&lt;/h2&gt;

&lt;p&gt;I hope this article has introduced you to some new and useful extensions you can add to your VSCode setup. If you have any favorites that aren't on this list, please share them in the comments section! 👀&lt;/p&gt;

&lt;p&gt;As we kick off the new year, I want to share one of my new goals with you. My focus for this year is to be consistent and deliver daily educational content on my Twitter that can help you unlock your web development skills. 🚀 From tips to tutorials, I'll share everything I know to help you grow and succeed in your coding journey. 📚&lt;/p&gt;

&lt;p&gt;If you're looking for a supportive place, I invite you to &lt;a href="https://twitter.com/gaelgthomas" rel="noopener noreferrer"&gt;join me on Twitter&lt;/a&gt;. Let's learn and grow together! 🤝📬&lt;/p&gt;

</description>
      <category>devto</category>
      <category>announcement</category>
      <category>opensource</category>
      <category>community</category>
    </item>
    <item>
      <title>10 GitHub Repositories You Should Know as a JavaScript Developer</title>
      <dc:creator>Gaël Thomas</dc:creator>
      <pubDate>Fri, 27 Jan 2023 17:55:53 +0000</pubDate>
      <link>https://forem.com/gaelgthomas/10-github-repositories-you-should-know-as-a-javascript-developer-2ji6</link>
      <guid>https://forem.com/gaelgthomas/10-github-repositories-you-should-know-as-a-javascript-developer-2ji6</guid>
      <description>&lt;p&gt;As a developer, we all want to improve our programming skills. Today, I'll share not 5, not 7, but 10 GitHub repositories that can help you grow as a JavaScript developer!&lt;/p&gt;

&lt;p&gt;Grab your favorite tea, and let's start to navigate these resources.&lt;/p&gt;

&lt;h2&gt;
  
  
  Node Best Practices
&lt;/h2&gt;

&lt;p&gt;Node JS is one of the most used technologies in the industry. The repository below regroups an up-to-date list of best practices for you to follow.&lt;/p&gt;

&lt;p&gt;Each best practice is supported with an example, and the repository is translated into +7 languages. You don't have any excuse for not checking it!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;+81.7k ⭐ ️=&amp;gt;&lt;/strong&gt; &lt;a href="https://github.com/goldbergyoni/nodebestpractices"&gt;https://github.com/goldbergyoni/nodebestpractices&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  JavaScript Algorithms
&lt;/h2&gt;

&lt;p&gt;I heard you need to implement an algorithm in JavaScript? This repository is for you.&lt;/p&gt;

&lt;p&gt;It provides an extensive list of algorithms and data structures in JavaScript with explanations and examples. The content is classified by experience: B (beginners) and A (advanced).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;+151k ⭐ ️=&amp;gt;&lt;/strong&gt; &lt;a href="https://github.com/trekhleb/javascript-algorithms"&gt;https://github.com/trekhleb/javascript-algorithms&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  33 JS Concepts
&lt;/h2&gt;

&lt;p&gt;The repository describes: "33 JavaScript concepts every developer should know". References, videos, articles, or books back these concepts.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;+51.8k ⭐ ️=&amp;gt;&lt;/strong&gt; &lt;a href="https://github.com/leonardomso/33-js-concepts"&gt;https://github.com/leonardomso/33-js-concepts&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  You Don't Know JS (Yet)
&lt;/h2&gt;

&lt;p&gt;I don't know if I still have to share about this repository. Can we call this article a JavaScript repository list without including it?&lt;/p&gt;

&lt;p&gt;This repository is an initiative by Kyle Simpson (aka Getify), author of the "You Don't Know JS (Yet)" book series. These books dive deep into the core mechanisms of the JavaScript language.&lt;/p&gt;

&lt;p&gt;The author shares the numeric version of these books in the repository for free.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You can buy the books to support the author and have a paperback version.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;+159k ⭐ ️=&amp;gt;&lt;/strong&gt; &lt;a href="https://github.com/getify/You-Dont-Know-JS"&gt;https://github.com/getify/You-Dont-Know-JS&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Clean Code JavaScript
&lt;/h2&gt;

&lt;p&gt;The programming world has a famous book called "Clean Code". This repository is an adaption of these clean code concepts but for JavaScript.&lt;/p&gt;

&lt;p&gt;The presentation is straightforward:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;a practice (sometimes with a short description)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;a bad example&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;a good example&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;+73k ⭐ ️=&amp;gt;&lt;/strong&gt; &lt;a href="https://github.com/ryanmcdermott/clean-code-javascript"&gt;https://github.com/ryanmcdermott/clean-code-javascript&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Awesome NodeJS
&lt;/h2&gt;

&lt;p&gt;This GitHub repository curates a list of tools, packages, tutorials, articles, videos, and even more for your next Node project.&lt;/p&gt;

&lt;p&gt;All packages are categorized: logging, parsing, compression, etc. You should find the answer to most of your problems here!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;+46.9k ⭐ ️=&amp;gt;&lt;/strong&gt; &lt;a href="https://github.com/sindresorhus/awesome-nodejs"&gt;https://github.com/sindresorhus/awesome-nodejs&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  30 Days Of JavaScript
&lt;/h2&gt;

&lt;p&gt;Do you want to learn JavaScript in "30" days? There you go!&lt;/p&gt;

&lt;p&gt;This repository's concept guides you step-by-step in your JavaScript journey. Indeed, you'll have one notion per day for 30 days.&lt;/p&gt;

&lt;p&gt;Each day, you'll have resources, exercises, and sometimes projects.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; As mentioned in the repository, even if the repository name is "30 days", it may take way more time. The key to learning successfully is to do it at your own pace.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;+27.8k ⭐ =&amp;gt;&lt;/strong&gt; &lt;a href="https://github.com/Asabeneh/30-Days-Of-JavaScript"&gt;https://github.com/Asabeneh/30-Days-Of-JavaScript&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Modern JS Cheatsheet
&lt;/h2&gt;

&lt;p&gt;For this repository, here's the author's description:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"This document is a cheatsheet for JavaScript you will frequently encounter in modern projects and most contemporary sample code.This guide is not intended to teach you JavaScript from the ground up, but to help developers with basic knowledge who may struggle to get familiar with modern codebases (or let's say to learn React for instance) because of the JavaScript concepts used.Besides, I will sometimes provide personal tips that may be debatable but will take care to mention that it's a personal recommendation when I do so."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Definitely the kind of repository you can bookmark and refer to later when you feel the need.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;+23.5k ⭐ =&amp;gt;&lt;/strong&gt; &lt;a href="https://github.com/mbeaudru/modern-js-cheatsheet"&gt;https://github.com/mbeaudru/modern-js-cheatsheet&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  JavaScript Testing Best Practices
&lt;/h2&gt;

&lt;p&gt;An updated comprehensive list of best practices to write tests in JavaScript and Node JS.&lt;/p&gt;

&lt;p&gt;Indeed, writing good tests is an essential skill for a developer. Thanks to this repository, I hope you'll find many tips about that topics and improve your testing strategy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;+19.1k ⭐ =&amp;gt;&lt;/strong&gt; &lt;a href="https://github.com/goldbergyoni/javascript-testing-best-practices"&gt;https://github.com/goldbergyoni/javascript-testing-best-practices&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  ES6 Cheatsheet
&lt;/h2&gt;

&lt;p&gt;Similarly to the modern JS cheatsheet presented earlier, here's a repository containing tips, tricks, best practices, and code snippets in JavaScript.&lt;/p&gt;

&lt;p&gt;Feel free to bookmark it and refer to it when you need it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;+12.9k ⭐ =&amp;gt;&lt;/strong&gt; &lt;a href="https://github.com/DrkSephy/es6-cheatsheet"&gt;https://github.com/DrkSephy/es6-cheatsheet&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Do you know some others?
&lt;/h2&gt;

&lt;p&gt;I hope you enjoyed this list and will benefit your career as a JavaScript developer! If you know some others, let me know on Twitter 😉.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PS:&lt;/strong&gt; I wrote this article from a Bangkok coffee ☕️🙏.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://twitter.com/gaelgthomas"&gt;Join me on Twitter&lt;/a&gt; for daily doses of educational content to help you Unlock your Web Development skills! 🚀 From tips to tutorials, let's learn &amp;amp; grow together! 📚 DMs are open, let's connect! 🤝📬&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>react</category>
      <category>node</category>
    </item>
    <item>
      <title>Get Yesterday Date in JavaScript</title>
      <dc:creator>Gaël Thomas</dc:creator>
      <pubDate>Thu, 29 Dec 2022 13:19:40 +0000</pubDate>
      <link>https://forem.com/gaelgthomas/get-yesterday-date-in-javascript-1841</link>
      <guid>https://forem.com/gaelgthomas/get-yesterday-date-in-javascript-1841</guid>
      <description>&lt;p&gt;Learn to remove one day-to-date in JavaScript using the native date object.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Get Yesterday Date in JavaScript?
&lt;/h2&gt;

&lt;p&gt;The best way to get yesterday’s date in JavaScript is by using the Date object. On an existing &lt;code&gt;Date&lt;/code&gt;, you can use the &lt;code&gt;getDate&lt;/code&gt; function to get the day (between 1 and 31), subtract 1 to this number, then use &lt;code&gt;setDate&lt;/code&gt; to update the date. Here's a short example: &lt;code&gt;date.setDate(date.getDate() - 1)&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using the JavaScript Date Object
&lt;/h2&gt;

&lt;p&gt;In JavaScript, you’ll often manipulate &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date"&gt;the Date object&lt;/a&gt; to do diverse operations (e.g., subtract days from a date, format a date, etc.).&lt;/p&gt;

&lt;p&gt;If you want to get yesterday’s date in JavaScript, you can use a combination of these two &lt;code&gt;Date&lt;/code&gt; functions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;yourDate.getDate()&lt;/code&gt;: get the day of the month (you'll get a number between 1 and 31)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;yourDate.setDate()&lt;/code&gt;: update the day of the date to the number passed as a parameter&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In practice, let’s say you have this date: &lt;code&gt;15/11/2022&lt;/code&gt;. The &lt;code&gt;getDate()&lt;/code&gt; function will return &lt;code&gt;15&lt;/code&gt;. Then you can subtract one day to this number &lt;code&gt;15 - 1 = 14&lt;/code&gt;. Finally, use &lt;code&gt;setDate()&lt;/code&gt; to update the day of the month for your current date object.&lt;/p&gt;

&lt;p&gt;Here’s a commented example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Create a date&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;todayDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;// Before subtracting 1 day&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;todayDate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="c1"&gt;// Output: "Tue Nov 15 2022 13:37:12 GMT+0100 (Central European Standard Time)"&lt;/span&gt;

&lt;span class="c1"&gt;// Subtract one day to the current date&lt;/span&gt;
&lt;span class="nx"&gt;todayDate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setDate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;todayDate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getDate&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// After removing 1 day&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;todayDate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="c1"&gt;// Output: "Mon Nov 14 2022 13:37:12 GMT+0100 (Central European Standard Time)"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now that you know how to subtract days from a date, you can learn &lt;a href="https://herewecode.io/blog/add-one-day-to-date-javascript/"&gt;how to add one day to date in JavaScript&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus: Create a Function to Get Yesterday Date
&lt;/h2&gt;

&lt;p&gt;Now you know how to remove days to a date, let’s make your code fancy!&lt;/p&gt;

&lt;p&gt;One way to do that is to create a function that takes a date as a parameter, subtracts one day, and returns it.&lt;/p&gt;

&lt;p&gt;Following what we did in the last part, here’s how:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Create a function to make the logic generic&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;removeOneDayToDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setDate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getDate&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;date&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Get the current date&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;date&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;// Before removing 1 day&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="c1"&gt;// Output: "Tue Nov 15 2022 13:37:12 GMT+0100 (Central European Standard Time)"&lt;/span&gt;

&lt;span class="c1"&gt;// Call `removeOneDayToDate` with the current date&lt;/span&gt;
&lt;span class="c1"&gt;// and assign the result to a new variable called `yesterdayDate`&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;yesterdayDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;removeOneDayToDate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// After subtracting 1 day&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;yesterdayDate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="c1"&gt;// Output: "Mon Nov 14 2022 13:37:12 GMT+0100 (Central European Standard Time)"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;Thanks for reading. Let’s connect!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;➡️ I help you grow into Web Development, and I share my journey as a Nomad Software Engineer. &lt;a href="https://twitter.com/gaelgthomas"&gt;Join me on Twitter for more.&lt;/a&gt; 🚀🎒&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>Add One Day to Date in JavaScript</title>
      <dc:creator>Gaël Thomas</dc:creator>
      <pubDate>Wed, 21 Dec 2022 21:13:31 +0000</pubDate>
      <link>https://forem.com/gaelgthomas/add-one-day-to-date-in-javascript-45n2</link>
      <guid>https://forem.com/gaelgthomas/add-one-day-to-date-in-javascript-45n2</guid>
      <description>&lt;p&gt;Learn how to add one day to date in JavaScript using the native date object.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Add 1 Day to Date in JavaScript?
&lt;/h2&gt;

&lt;p&gt;The best way to add 1 day to a JavaScript date is by using the &lt;code&gt;Date&lt;/code&gt; object. On an existing &lt;code&gt;Date&lt;/code&gt;, you can use the &lt;code&gt;getDate&lt;/code&gt; function to get the day (between 1 and 31), add 1 to this number, then use &lt;code&gt;setDate&lt;/code&gt; to update the date. Here's a short example: &lt;code&gt;date.setDate(date.getDate() + 1)&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using the JavaScript Date Object
&lt;/h2&gt;

&lt;p&gt;In JavaScript, you’ll often manipulate &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date"&gt;the Date object&lt;/a&gt; to do diverse operations (e.g., add days to a date, format a date, etc.).&lt;/p&gt;

&lt;p&gt;If you want to add one day to date, you can use a combination of these two Date functions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;yourDate.getDate()&lt;/code&gt;: get the day of the month (you'll get a number between 1 and 31)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;yourDate.setDate()&lt;/code&gt;: update the day of the date to the number passed as a parameter&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In practice, let’s say you have this date: &lt;code&gt;05/12/2022&lt;/code&gt;. The &lt;code&gt;getDate()&lt;/code&gt; function will return &lt;code&gt;5&lt;/code&gt;. Then you can add one day to this number &lt;code&gt;5 + 1 = 6&lt;/code&gt;. Finally, use &lt;code&gt;setDate()&lt;/code&gt; to update the day of the month for your current date object.&lt;/p&gt;

&lt;p&gt;Here’s a commented example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Create a date&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;todayDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;// Before adding 1 day&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;todayDate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="c1"&gt;// Output: "Wed Dec 21 2022 18:19:23 GMT+0100 (Central European Standard Time)"&lt;/span&gt;

&lt;span class="c1"&gt;// Add one day to the current date&lt;/span&gt;
&lt;span class="nx"&gt;todayDate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setDate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;todayDate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getDate&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// After adding 1 day&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;todayDate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="c1"&gt;// Output: "Thu Dec 22 2022 18:19:23 GMT+0100 (Central European Standard Time)"Bonus: Create a Function to One Day to Date&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you know how to add days to a date, let’s make your code fancy!&lt;/p&gt;

&lt;p&gt;One way to do that is to create a function that takes a date as a parameter, adds one day, and returns it.&lt;/p&gt;

&lt;p&gt;Following what we did in the last part, here’s how:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Create a function to make the logic generic&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;addOneDayToDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setDate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getDate&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;date&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Get the current date&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;date&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="c1"&gt;// Before adding 1 day&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="c1"&gt;// Output: "Wed Dec 21 2022 18:24:38 GMT+0100 (Central European Standard Time)"&lt;/span&gt;

&lt;span class="c1"&gt;// Call `addOneDayToDate` with the current date&lt;/span&gt;
&lt;span class="c1"&gt;// and assign the result to a new variable called `tomorrowDate`&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;tomorrowDate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;addOneDayToDate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;date&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// After adding 1 day&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;tomorrowDate&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;span class="c1"&gt;// Output: "Thu Dec 22 2022 18:24:38 GMT+0100 (Central European Standard Time)"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;Thanks for reading. Let’s connect!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;➡️ I help you grow into Web Development, and I share my journey as a Nomad Software Engineer. &lt;a href="https://twitter.com/gaelgthomas"&gt;Join me on Twitter for more.&lt;/a&gt; 🚀🎒&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>React Router — Redirect to an External URL</title>
      <dc:creator>Gaël Thomas</dc:creator>
      <pubDate>Sat, 24 Sep 2022 10:57:43 +0000</pubDate>
      <link>https://forem.com/gaelgthomas/react-router-redirect-to-an-external-url-173</link>
      <guid>https://forem.com/gaelgthomas/react-router-redirect-to-an-external-url-173</guid>
      <description>&lt;p&gt;Discover how to use React Router to link to an external URL, thanks to the Link component or an HTML anchor tag (&lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt;).&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Add an External Link With React Router?
&lt;/h2&gt;

&lt;p&gt;You can use the &lt;code&gt;Link&lt;/code&gt; component or an HTML anchor tag if you want to redirect to an external link with React Router. Using the &lt;code&gt;&amp;lt;Link&amp;gt;&lt;/code&gt; component, you can do it thanks to the &lt;code&gt;pathname&lt;/code&gt; and &lt;code&gt;target&lt;/code&gt; parameters. It will redirect the user to the specified URL.&lt;/p&gt;

&lt;h2&gt;
  
  
  Using React Router
&lt;/h2&gt;

&lt;p&gt;In React, &lt;a href="https://reactrouter.com/en/main" rel="noopener noreferrer"&gt;React Router&lt;/a&gt; is the most used library to manage your application routing (multi-pages application). Thanks to a set of functions and components provided by them, you can build a lot of features.&lt;/p&gt;

&lt;p&gt;If you use this library to redirect to an external URL, you can use the &lt;code&gt;&amp;lt;Link /&amp;gt;&lt;/code&gt; component with the &lt;code&gt;pathname&lt;/code&gt; and &lt;code&gt;target&lt;/code&gt; property.&lt;/p&gt;

&lt;p&gt;Let’s discover how to open &lt;a href="https://herewecode.io/" rel="noopener noreferrer"&gt;the HereWeCode homepage&lt;/a&gt; in a new tab:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;BrowserRouter&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Switch&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Route&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Link&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-router-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./styles.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Switch&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Home&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Switch&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Home&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt; &lt;span class="na"&gt;to&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;pathname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://herewecode.io/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;target&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"_blank"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Click to open HereWeCode (new tab)&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Link&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;As you can see above, when you pass an external URL to the React Router &lt;code&gt;Link&lt;/code&gt; component and combine it with a &lt;code&gt;target="_blank"&lt;/code&gt; property, the link will open a new tab with the URL of your choice.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Unfortunately, it's impossible to open an external URL in the same tab using React Router. If you don't provide the target property, the router will append the URL to your current website URL (e.g., &lt;code&gt;https://my-website.com/https://herewecode.io/&lt;/code&gt;). In the next section, I'll show you how to open an external link in the current tab.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fe4zk5g2ggg4ym7mblll5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fe4zk5g2ggg4ym7mblll5.png" alt="React Router link to external URL"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Using an Anchor Tag (&lt;a&gt;)
&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;If you want to open an external link to the current tab, the most straightforward way is to use the native anchor tag in HTML (&lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Here’s how to do it:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;a&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"https://herewecode.io/"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          Click to open HereWeCode (current tab)
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;a&lt;/span&gt; &lt;span class="na"&gt;href&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"https://herewecode.io/"&lt;/span&gt; &lt;span class="na"&gt;target&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"_blank"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          Click to open HereWeCode (new tab)
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;a&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;As you notice, we pass the external link to the &lt;code&gt;href&lt;/code&gt; property. If no &lt;code&gt;target="_blank"&lt;/code&gt; property is given, the link will open in the current tab; otherwise, in a new tab.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fd96iw9omcijufxiog808.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fd96iw9omcijufxiog808.png" alt="React anchor tag example to redirect to external URL"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to learn more about React, here’s an article on &lt;a href="https://herewecode.io/blog/react-router-link-to-external-url/" rel="noopener noreferrer"&gt;how to get URL params in React&lt;/a&gt; (with React Router V5/V6 and without).&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Thanks for reading. Let’s connect!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;➡️ I help you grow into Web Development, and I share my journey as a Nomad Software Engineer. &lt;a href="https://twitter.com/gaelgthomas" rel="noopener noreferrer"&gt;Join me on Twitter for more.&lt;/a&gt; 🚀🎒&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Get URL Params in React</title>
      <dc:creator>Gaël Thomas</dc:creator>
      <pubDate>Mon, 19 Sep 2022 17:44:59 +0000</pubDate>
      <link>https://forem.com/gaelgthomas/get-url-params-in-react-2m8f</link>
      <guid>https://forem.com/gaelgthomas/get-url-params-in-react-2m8f</guid>
      <description>&lt;p&gt;This article will show you three ways to get URL params in React (with React Router V5, V6, and without).&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Get URL Parameters in React?
&lt;/h2&gt;

&lt;p&gt;The best way to get URL parameters in React is to use the library “React Router”. Thanks to a set of functions, it helps you manage your application’s routes. But, if you have a simple application without routing, you can use the built-in &lt;code&gt;URLSearchParams&lt;/code&gt; interface to fetch the query parameters.&lt;/p&gt;

&lt;h2&gt;
  
  
  URL structure
&lt;/h2&gt;

&lt;p&gt;Before deep-diving into how to get URL params in your React application, let’s quickly go through the URL parts.&lt;/p&gt;

&lt;p&gt;Let’s use this URL as an example: "&lt;a href="https://my-website.com?type=cat&amp;amp;name=oscar" rel="noopener noreferrer"&gt;https://my-website.com?type=cat&amp;amp;name=oscar&lt;/a&gt;". The different URL parts are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Protocol:&lt;/strong&gt; "https://"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Domain name:&lt;/strong&gt; "mywebsite.com"&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Query parameter 1:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;name:&lt;/strong&gt; "type"&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;value:&lt;/strong&gt; "cat"&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Query parameter 2:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;name:&lt;/strong&gt; "name"&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;value:&lt;/strong&gt; "oscar"&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;In the following sections, you’ll discover how to fetch the query parameters type and name.&lt;/p&gt;

&lt;h2&gt;
  
  
  With URLSearchParams
&lt;/h2&gt;

&lt;p&gt;In this first example, we get the React URL params for a simple application without any routers. It means what you’ll discover below can work for all your React projects without any additional libraries (nothing to install).&lt;/p&gt;

&lt;p&gt;To make it work, we need to use &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Window" rel="noopener noreferrer"&gt;your browser’s Window interface&lt;/a&gt; and &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams" rel="noopener noreferrer"&gt;the URLSearchParams interface&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here’s a working example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;queryParameters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;URLSearchParams&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;search&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;queryParameters&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;queryParameters&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Type: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;type&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Name: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;As you can see above, we initialize a &lt;code&gt;queryParameters&lt;/code&gt; variable by creating a new &lt;code&gt;URLSearchParams&lt;/code&gt; instance with the current &lt;code&gt;window.location.search&lt;/code&gt; as a parameter.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;URLSearchParams&lt;/code&gt; extracts the queries from the parameter passed at construction (&lt;code&gt;window.location.search&lt;/code&gt;) and provides a set of functionalities (&lt;code&gt;get&lt;/code&gt;, &lt;code&gt;getAll&lt;/code&gt;, &lt;code&gt;has&lt;/code&gt;, etc.).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;window.location.search&lt;/code&gt; corresponds to the query parameters part of your URL (&lt;code&gt;?type=cat&amp;amp;name=oscar&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the rendering part of our application, we display the two React URL params, &lt;code&gt;type&lt;/code&gt;, and &lt;code&gt;name&lt;/code&gt;, thanks to the &lt;code&gt;get()&lt;/code&gt; function from the URLSearchParams object.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.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%2Fxui18fhk9afw4cjuadx3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.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%2Fxui18fhk9afw4cjuadx3.png" alt="Expected output with displayed URL params"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  With React Router V6
&lt;/h2&gt;

&lt;p&gt;If you have a more complex application in React with many pages, you’re probably using &lt;a href="https://reactrouter.com/en/main" rel="noopener noreferrer"&gt;React Router&lt;/a&gt; to manage your routes. This library is the most popular solution and has many features to manage your website URLs.&lt;/p&gt;

&lt;p&gt;In this section, we’ll focus on version 6 of React Router. If you’re still using version 5, you can scroll down to the next section because the solution differs.&lt;/p&gt;

&lt;p&gt;Below, you can find an example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;Routes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Route&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;useSearchParams&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;BrowserRouter&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-router-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;BrowserRouter&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Routes&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt; &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Home&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Routes&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;BrowserRouter&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Home&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;queryParameters&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useSearchParams&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Type: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;queryParameters&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Name: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;queryParameters&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;In this version of React Router, all the &lt;code&gt;window&lt;/code&gt; and &lt;code&gt;URLSearchParams&lt;/code&gt; code have been wrapped into a custom hook called &lt;code&gt;useSearchParams&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You don’t have to worry about doing the implementation by yourself, and you can focus on calling the hook and extracting the query parameters from it (&lt;code&gt;const [queryParameters] = useSearchParams()&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Then, you can fetch the URL parameter values in the same way as in the previous example.&lt;/p&gt;

&lt;h2&gt;
  
  
  With React Router V5
&lt;/h2&gt;

&lt;p&gt;In this last section of the article, I’ll show you how to deal with URL params with React Router V5. As mentioned before, the code will slightly differ between the V5 and V6.&lt;/p&gt;

&lt;p&gt;Here’s how to get the URL params with React Router V5:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;BrowserRouter&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nx"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Switch&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;Route&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;useLocation&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-router-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;App&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Switch&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Home&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Switch&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Router&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Home&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;location&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useLocation&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;queryParameters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;URLSearchParams&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;search&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Type: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;queryParameters&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Name: &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;queryParameters&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;


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

&lt;/div&gt;

&lt;p&gt;As you can see above, this last example is a mix of the first approach with &lt;code&gt;window&lt;/code&gt; and &lt;code&gt;URLSearchParams&lt;/code&gt; and the second approach with React Router only.&lt;/p&gt;

&lt;p&gt;To succeed in getting the URL params with the V5, you need to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;get the current location object using useLocation.&lt;/li&gt;
&lt;li&gt;extract the query parameters from your URL with &lt;code&gt;location.search&lt;/code&gt; (&lt;code&gt;?type=cat&amp;amp;name=oscar&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;pass the URL query params to &lt;code&gt;URLSearchParams&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; You may have noticed that the output of &lt;code&gt;location.search&lt;/code&gt; is the same as &lt;code&gt;window.location.search&lt;/code&gt;. It's because both are coming from the Window interface (&lt;code&gt;window.location&lt;/code&gt;), and, more precisely, the Location interface.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;&lt;strong&gt;Thanks for reading. Let’s connect!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;➡️ I help you grow into Web Development, and I share my journey as a Nomad Software Engineer. &lt;a href="https://twitter.com/gaelgthomas" rel="noopener noreferrer"&gt;Join me on Twitter for more.&lt;/a&gt; 🚀🎒&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Array to String Without Commas in JavaScript</title>
      <dc:creator>Gaël Thomas</dc:creator>
      <pubDate>Sun, 18 Sep 2022 11:06:32 +0000</pubDate>
      <link>https://forem.com/gaelgthomas/array-to-string-without-commas-in-javascript-4mg6</link>
      <guid>https://forem.com/gaelgthomas/array-to-string-without-commas-in-javascript-4mg6</guid>
      <description>&lt;p&gt;In this article, you’ll discover how to convert an array to a string without commas. By no commas, I mean no separator between your array elements (words) or a separator different than a comma.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Convert Array to String Without Commas
&lt;/h2&gt;

&lt;p&gt;In JavaScript, all arrays have a built-in method called &lt;code&gt;join()&lt;/code&gt;. You can use it to convert an array to a string without commas. You can call the join method with an empty string as a parameter (&lt;code&gt;join("")&lt;/code&gt;). The method will return a string with all the array elements concatenated.&lt;/p&gt;

&lt;h2&gt;
  
  
  Concrete Example: Join Array to String
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Without Commas
&lt;/h3&gt;

&lt;p&gt;As mentioned in the above paragraph, you can use &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join"&gt;the join method&lt;/a&gt; to create a string without commas from your array.&lt;/p&gt;

&lt;p&gt;This method works on an &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array"&gt;Array&lt;/a&gt; and takes up to one parameter:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;no parameter:&lt;/strong&gt; your array will be joined with commas (&lt;code&gt;["hello", "world"].join()&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;with parameter:&lt;/strong&gt; your array will be joined with the string provided as a parameter (&lt;code&gt;["hello", "world"].join("-")&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let me give you an example without commas:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;helloMagicWorldArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Magic&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;World&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;helloMagicWorldString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;helloMagicWorldArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;helloMagicWorldString&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// Output: "HelloMagicWorld"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  With Separator
&lt;/h3&gt;

&lt;p&gt;I suppose you start the get the idea! If you want to join your array with something different than commas, you can pass the separator of your choice.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;helloMagicWorldArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Magic&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;World&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;helloMagicWorldArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="c1"&gt;// Output: "Hello/Magic/World"&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;helloMagicWorldArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt; - &lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="c1"&gt;// Output: "Hello - Magic - World"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to go further, you can learn how to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://herewecode.io/blog/filter-array-javascript/"&gt;filter an array in JavaScript&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://herewecode.io/blog/replace-item-array-javascript/"&gt;replace item in array with JavaScript&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://herewecode.io/blog/remove-null-values-from-array-javascript/"&gt;remove null values from an array in JavaScript&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Thanks for reading. Let’s connect!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;➡️ I help you grow into Web Development, and I share my journey as a Nomad Software Engineer. &lt;a href="https://twitter.com/gaelgthomas"&gt;Join me on Twitter for more.&lt;/a&gt; 🚀🎒&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Remove Null Values From Array in JavaScript</title>
      <dc:creator>Gaël Thomas</dc:creator>
      <pubDate>Sat, 17 Sep 2022 10:22:36 +0000</pubDate>
      <link>https://forem.com/gaelgthomas/remove-null-values-from-array-in-javascript-4g5a</link>
      <guid>https://forem.com/gaelgthomas/remove-null-values-from-array-in-javascript-4g5a</guid>
      <description>&lt;p&gt;Here’s how you can remove null values from an array in JavaScript. I will show you two methods, the first one with pure JavaScript and the array filter method and the second one with Lodash.&lt;/p&gt;

&lt;h2&gt;
  
  
  Remove Null Values from Array With Pure JavaScript
&lt;/h2&gt;

&lt;p&gt;I recommend this method over the one with Lodash because you don’t have to use an external library. All you have to do is use the &lt;code&gt;Array.prototype.filter()&lt;/code&gt; implemented in JavaScript. This built-in method creates a &lt;a href="https://developer.mozilla.org/en-US/docs/Glossary/Shallow_copy"&gt;shallow copy&lt;/a&gt; of your array based on the filter condition you provide.&lt;/p&gt;

&lt;p&gt;Here’s how it’s working:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;whatIsLife&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Life&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;is&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;beautiful&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;thisIsLife&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;whatIsLife&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;thisIsLife&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// Output: ["Life", "is", "beautiful", "!"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see above, our &lt;code&gt;whatIsLife&lt;/code&gt; array contains &lt;code&gt;null&lt;/code&gt; values. By using the filter method, we specify that we want to keep only elements that are different than &lt;code&gt;null&lt;/code&gt; (yes, because life is beautiful!).&lt;/p&gt;

&lt;p&gt;If you print the new &lt;code&gt;thisIsLife&lt;/code&gt; array, you'll have an array with non-null values.&lt;/p&gt;

&lt;p&gt;Here’s a shortened version of the above example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;whatIsLife&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Life&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;is&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;beautiful&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="c1"&gt;// Returning `element` will only return values if they&lt;/span&gt;
&lt;span class="c1"&gt;// are non-null&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;thisIsLife&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;whatIsLife&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;thisIsLife&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// Output: ["Life", "is", "beautiful", "!"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  With Lodash
&lt;/h2&gt;

&lt;p&gt;Even if I recommend the first method, it’s always interesting to discover other ways of removing null values from an array. This time, let’s learn how to do it with &lt;a href="https://www.npmjs.com/package/lodash"&gt;Lodash&lt;/a&gt;, a JavaScript library.&lt;/p&gt;

&lt;p&gt;You’ll notice the syntax will differ a little, but the function we’ll use is the same as the one built-in in JavaScript. Indeed, the Lodash function is called &lt;code&gt;filter&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;It’s time for an example!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;_&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;lodash&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;whatIsLife&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Life&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;is&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;beautiful&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;thisIsLife&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;_&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;filter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;whatIsLife&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;thisIsLife&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;// Output: ["Life", "is", "beautiful", "!"]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you know how to remove null values in a JavaScript array, you can learn how to &lt;a href="https://herewecode.io/blog/remove-element-array-javascript/"&gt;remove an element from an array&lt;/a&gt;.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Thanks for reading. Let's connect!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;➡️ I help you grow into Web Development, and I share my journey as a Nomad Software Engineer. &lt;a href="https://twitter.com/gaelgthomas"&gt;Join me on Twitter for more.&lt;/a&gt; 🚀🎒&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>How to Update a Package With NPM</title>
      <dc:creator>Gaël Thomas</dc:creator>
      <pubDate>Sun, 27 Feb 2022 17:03:16 +0000</pubDate>
      <link>https://forem.com/gaelgthomas/how-to-update-a-package-with-npm-2hp8</link>
      <guid>https://forem.com/gaelgthomas/how-to-update-a-package-with-npm-2hp8</guid>
      <description>&lt;p&gt;A short tutorial about how to update one package with NPM.&lt;/p&gt;




&lt;p&gt;Nowadays, most JavaScript projects use dependencies. They can be delivered through different package managers, but in this article, we'll focus on NPM.&lt;/p&gt;

&lt;p&gt;As a computer, it's essential to keep your project dependencies up to date. It's needed to get the latest security fixes, bugs fixes, improvements, and features.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to know if an NPM package is outdated
&lt;/h2&gt;

&lt;p&gt;Before going further in the update process, you'll need to figure out if your NPM package is outdated or not.&lt;br&gt;
To know about that, there are two possibilities:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;keep yourself updated about the package news and changelog (ex: read about a React major update)&lt;/li&gt;
&lt;li&gt;use the &lt;code&gt;npm outdated&lt;/code&gt; command in your project root repository&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's use the &lt;code&gt;npm outdated&lt;/code&gt; command in the project of your choice. If there are packages to update, the output should look as below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Package                          Current   Wanted    Latest    Location                      Depended by
react-i18next                    11.15.3   11.15.5   11.15.5   node_modules/react-i18next    my-repo
tailwindcss                      3.0.12    3.0.23    3.0.23    node_modules/tailwindcss      my-repo
&lt;span class="o"&gt;[&lt;/span&gt;...]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you don't see anything, good news! It means that your project is up to date.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to update one package with NPM
&lt;/h2&gt;

&lt;p&gt;Now that you know more about which package needs to be updated in your project. Let's pick one of them and update it.&lt;/p&gt;

&lt;p&gt;Based on the list in the previous part, I'll pick &lt;code&gt;tailwindcss&lt;/code&gt; because I noticed that the current version in my project is 3.0.12, but the wanted is the &lt;code&gt;3.0.23&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To do so, NPM is providing an update command that works as follows: &lt;code&gt;npm update [package_name]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;As an example, in my case, I would do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;npm update tailwindcss
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; When running the &lt;code&gt;npm update&lt;/code&gt; command, the package will update to the "Wanted" version (ref. output of &lt;code&gt;npm outdated&lt;/code&gt;). This security is here to avoid breaking your code with major releases.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Update package to the latest version
&lt;/h3&gt;

&lt;p&gt;This part will teach you to update your package to its latest version and major release. It's a typical case when you need one new feature available in the above version.&lt;/p&gt;

&lt;p&gt;Let's imagine you have an output that looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;Package                          Current   Wanted    Latest    Location                      Depended by
tailwindcss                      2.2.19    2.2.19    3.0.23    node_modules/tailwindcss      my-repo
&lt;span class="o"&gt;[&lt;/span&gt;...]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can notice, the current version of &lt;code&gt;tailwindcss&lt;/code&gt; is &lt;code&gt;2.2.19&lt;/code&gt;, but there is a major update &lt;code&gt;3.0.23&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To update the NPM package to the latest version, you must type &lt;code&gt;npm install tailwindcss@latest&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; Doing a major NPM update may break your code due to significant changes in the corresponding library. I recommend you check your package website. They provide an upgrade guide or helpful information to update your code most of the time. For example, TailwindCSS provided &lt;a href="https://tailwindcss.com/docs/upgrade-guide"&gt;an upgrade guide from V2 to V3&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Wrapping up and recommendation
&lt;/h2&gt;

&lt;p&gt;I hope this article helped you to update one package of your project!&lt;/p&gt;

&lt;p&gt;One last recommendation for your project health, don't forget to test your website and/or run your test suite if you have one. It's essential to check if everything is still working after a package update. 📦🚀&lt;/p&gt;




&lt;p&gt;➡️ I regularly deliver content about web development, personal growth as a developer, and my journey as an aspiring digital nomad and remote software engineer. If you don't want to miss them, I invite you to &lt;a href="https://twitter.com/gaelgthomas"&gt;follow me on Twitter&lt;/a&gt;. 🚀&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to Enable and Disable a Button in JavaScript 🔴🟢</title>
      <dc:creator>Gaël Thomas</dc:creator>
      <pubDate>Wed, 12 Jan 2022 15:34:05 +0000</pubDate>
      <link>https://forem.com/herewecode/how-to-enable-and-disable-a-button-in-javascript-4014</link>
      <guid>https://forem.com/herewecode/how-to-enable-and-disable-a-button-in-javascript-4014</guid>
      <description>&lt;p&gt;Learn how to enable and disable a button in JavaScript.&lt;/p&gt;




&lt;p&gt;While creating user interfaces, you may probably want to make them more dynamic and enable or disable a button programmatically.&lt;/p&gt;

&lt;p&gt;Before starting, you need to know that all HTML buttons have a property &lt;code&gt;disabled&lt;/code&gt;. Thanks to it, you can enable or disable a button.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id-&lt;/span&gt;&lt;span class="err"&gt;"&lt;/span&gt;&lt;span class="na"&gt;mainButton&lt;/span&gt;&lt;span class="err"&gt;"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;I'm an enabled button!&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id-&lt;/span&gt;&lt;span class="err"&gt;"&lt;/span&gt;&lt;span class="na"&gt;mainButton&lt;/span&gt;&lt;span class="err"&gt;"&lt;/span&gt; &lt;span class="na"&gt;disabled&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;I'm a disabled button!&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This article will manipulate the &lt;code&gt;disabled&lt;/code&gt; property using a short JavaScript code.&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%2Fh1yp29fgybcn0a1zywgq.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%2Fh1yp29fgybcn0a1zywgq.png" alt="Disabled button using JavaScript" width="270" height="64"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let me show you how to do that!&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Create a button in your HTML
&lt;/h2&gt;

&lt;p&gt;The first step is to create a button in your HTML with an &lt;code&gt;id&lt;/code&gt; property. It will allow you to select it later in the tutorial.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"mainButton"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Can you click me?&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also &lt;a href="https://herewecode.io/blog/create-button-javascript/"&gt;create this button programmatically in JavaScript&lt;/a&gt; if you prefer!&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Select your button using JavaScript
&lt;/h2&gt;

&lt;p&gt;The first step in your code is to select the button you want to update. You can do it using &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector"&gt;the &lt;code&gt;querySelector&lt;/code&gt; function&lt;/a&gt;, but we will use the &lt;code&gt;getElementById&lt;/code&gt; native function because of its simplicity.&lt;/p&gt;

&lt;p&gt;It will allow you to target an HTML element based on its &lt;code&gt;id&lt;/code&gt; property.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Select the button element in your HTML code&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mainButton&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Disable button in JavaScript
&lt;/h2&gt;

&lt;p&gt;As mentioned previously in this article, all HTML buttons have a &lt;code&gt;disabled&lt;/code&gt; property that you can use to disable or enable a button.&lt;/p&gt;

&lt;p&gt;By default, a button's &lt;code&gt;disabled&lt;/code&gt; property is set to &lt;code&gt;false&lt;/code&gt;. It means that by default, a button is active.&lt;/p&gt;

&lt;p&gt;If you want to disable a button using JavaScript, you can switch this value to &lt;code&gt;true&lt;/code&gt; once you have created and selected the button (steps 1 and 2).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Disable a button in JavaScript&lt;/span&gt;
&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;disabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="c1"&gt;// &amp;lt;- Button is disabled&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  4. Enable button in JavaScript
&lt;/h2&gt;

&lt;p&gt;Now you know how to disable a button, you can enable it by reverting the &lt;code&gt;true&lt;/code&gt; value to &lt;code&gt;false&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Enable a button in JavaScript&lt;/span&gt;
&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;disabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt; &lt;span class="c1"&gt;// &amp;lt;- Button is not disabled&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Bonus: How to Disable a Button in JavaScript Based on Condition
&lt;/h2&gt;

&lt;p&gt;Let's go further and create some code that disables the button only if its text matches a condition.&lt;/p&gt;

&lt;p&gt;Here is what you will need to know:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;create a button in HTML&lt;/li&gt;
&lt;li&gt;disable a button in JavaScript&lt;/li&gt;
&lt;li&gt;write a condition using JavaScript&lt;/li&gt;
&lt;li&gt;get a button text in JavaScript (you will use &lt;a href="https://www.w3schools.com/jsref/prop_node_innertext.asp"&gt;the &lt;code&gt;innerText&lt;/code&gt; property&lt;/a&gt;, but don't worry you will see how to use it below!)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To do so, you can come back to step 1, 2, and 3, except that we disable the button only if the button text is "Can you click me?".&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Select the button element in your HTML code&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mainButton&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// Disable the selected button in JavaScript based on a condition&lt;/span&gt;
&lt;span class="c1"&gt;// If the button text is 'Can you click me?'&lt;/span&gt;
&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Can you click me?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;disabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you execute this code in your browser, the button should be disabled. Now, let's change the condition to another text. For example: &lt;code&gt;button.innerText === "Click here!"&lt;/code&gt;, refresh your browser, and the button should be enabled.&lt;/p&gt;

&lt;h2&gt;
  
  
  Full code to enable and disable a button in JS 👇
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;html&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Enable and Disable a Button in JavaScript&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"mainButton"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Can you click me?&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
      &lt;span class="c1"&gt;// Select the button element in your HTML code&lt;/span&gt;
      &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mainButton&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

      &lt;span class="c1"&gt;// Disable the selected button in JavaScript based on a condition&lt;/span&gt;
      &lt;span class="c1"&gt;// If the button text is 'Can you click me?'&lt;/span&gt;
      &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Can you click me?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;disabled&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;

      &lt;span class="c1"&gt;// If you want to enable the button using JavaScript&lt;/span&gt;
      &lt;span class="c1"&gt;// you can switch back the `disabled` property to `false`&lt;/span&gt;
      &lt;span class="c1"&gt;// button.disabled = false&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;➡️ I'm starting to tweet more consistently. If you want to get more tips and resources about web development, developer tips, and my journey as a Full-stack Engineer -&amp;gt; &lt;a href="https://twitter.com/gaelgthomas/"&gt;Find me on my Twitter 🐦&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>codenewbie</category>
    </item>
  </channel>
</rss>
