<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: codeek</title>
    <description>The latest articles on DEV Community by codeek (@codeek).</description>
    <link>https://dev.to/codeek</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F558313%2F15c20986-66bf-489e-84f6-476d0c00b48e.png</url>
      <title>DEV Community: codeek</title>
      <link>https://dev.to/codeek</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/codeek"/>
    <language>en</language>
    <item>
      <title>🚀 10x your project workflow with Reusable Layouts in React Router V6 with createBrowserRouter and Nested Routes</title>
      <dc:creator>codeek</dc:creator>
      <pubDate>Sun, 19 Jul 2026 09:14:18 +0000</pubDate>
      <link>https://dev.to/codeek/10x-your-project-workflow-with-reusable-layouts-in-react-router-v6-with-createbrowserrouter-and-1o2j</link>
      <guid>https://dev.to/codeek/10x-your-project-workflow-with-reusable-layouts-in-react-router-v6-with-createbrowserrouter-and-1o2j</guid>
      <description>&lt;p&gt;If you've ever copied the same &lt;strong&gt;Navbar&lt;/strong&gt;, &lt;strong&gt;Sidebar&lt;/strong&gt;, or &lt;strong&gt;Footer&lt;/strong&gt; across multiple pages, you're doing extra work.&lt;/p&gt;

&lt;p&gt;React Router's &lt;code&gt;createBrowserRouter&lt;/code&gt;, &lt;code&gt;children&lt;/code&gt;, and &lt;code&gt;Outlet&lt;/code&gt; let you create reusable layouts that automatically wrap multiple pages. Instead of repeating components everywhere, you define them once and let nested routes handle the rest.&lt;/p&gt;

&lt;p&gt;In this guide, we'll build a clean routing structure that scales as your application grows.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Use Nested Routes?
&lt;/h2&gt;

&lt;p&gt;Imagine your application has the following pages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Home&lt;/li&gt;
&lt;li&gt;Login&lt;/li&gt;
&lt;li&gt;Register&lt;/li&gt;
&lt;li&gt;Dashboard&lt;/li&gt;
&lt;li&gt;Profile&lt;/li&gt;
&lt;li&gt;Settings&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The authentication pages shouldn't display the dashboard sidebar.&lt;/p&gt;

&lt;p&gt;The dashboard pages, however, should all share:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Navigation&lt;/li&gt;
&lt;li&gt;Sidebar&lt;/li&gt;
&lt;li&gt;Footer&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Instead of repeating these components inside every page, we'll create a reusable layout.&lt;/p&gt;

&lt;p&gt;React Router supports this through nested routing using the &lt;code&gt;children&lt;/code&gt; property and renders child pages through the &lt;code&gt;Outlet&lt;/code&gt; component.&lt;/p&gt;




&lt;h2&gt;
  
  
  Project Structure
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src
│
├── layouts
│   ├── MainLayout.jsx
│   └── DashboardLayout.jsx
│
├── pages
│   ├── Home.jsx
│   ├── Login.jsx
│   ├── Register.jsx
│   ├── Dashboard.jsx
│   ├── Profile.jsx
│   └── Settings.jsx
│
├── routes
│   └── router.jsx
│
└── main.jsx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 1 — Install React Router
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;react-router-dom
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 2 — Create the Router
&lt;/h2&gt;

&lt;p&gt;React Router recommends creating your router once using &lt;code&gt;createBrowserRouter&lt;/code&gt; and passing it to &lt;code&gt;RouterProvider&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;createBrowserRouter&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="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;router&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createBrowserRouter&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;path&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="na"&gt;element&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;MainLayout&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;,&lt;/span&gt;
    &lt;span class="na"&gt;children&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;element&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;Home&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="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;login&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;element&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;Login&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="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;register&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;element&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;Register&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="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 3 — Create a Layout Component
&lt;/h2&gt;

&lt;p&gt;Instead of rendering pages directly, create a reusable layout.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Outlet&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="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;MainLayout&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Navbar&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;main&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;Outlet&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;main&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;Footer&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;MainLayout&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The magic happens with &lt;code&gt;Outlet&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Whenever one of the child routes matches, React Router renders it exactly where the &lt;code&gt;Outlet&lt;/code&gt; is placed.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 4 — Create a Dashboard Layout
&lt;/h2&gt;

&lt;p&gt;Now let's create a completely different layout.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/dashboard&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;element&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;DashboardLayout&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;,&lt;/span&gt;
  &lt;span class="na"&gt;children&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;element&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;Dashboard&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="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;profile&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;element&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;Profile&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="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;settings&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="na"&gt;element&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;Settings&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="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Dashboard layout:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Outlet&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="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;DashboardLayout&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="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"dashboard"&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;Sidebar&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;section&lt;/span&gt; &lt;span class="na"&gt;className&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"content"&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;Outlet&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;section&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;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;DashboardLayout&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every dashboard page now automatically shares the sidebar.&lt;/p&gt;

&lt;p&gt;No duplicated code.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 5 — Wrap Everything with &lt;code&gt;RouterProvider&lt;/code&gt;
&lt;/h2&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;ReactDOM&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-dom/client&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;RouterProvider&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="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;router&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;./routes/router&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createRoot&lt;/span&gt;&lt;span class="p"&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="s2"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;render&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;RouterProvider&lt;/span&gt; &lt;span class="na"&gt;router&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;router&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;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Final Route Structure
&lt;/h2&gt;



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

├── Home
├── Login
├── Register

/dashboard
├── Dashboard
├── Profile
└── Settings
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Why This Pattern is Better
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;✅ No duplicated Navbar or Sidebar&lt;/li&gt;
&lt;li&gt;✅ Cleaner project structure&lt;/li&gt;
&lt;li&gt;✅ Easier to maintain&lt;/li&gt;
&lt;li&gt;✅ Better scalability&lt;/li&gt;
&lt;li&gt;✅ Perfect for authentication layouts&lt;/li&gt;
&lt;li&gt;✅ Great for admin dashboards&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Key Takeaways
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;code&gt;createBrowserRouter&lt;/code&gt; to define your application's routes.&lt;/li&gt;
&lt;li&gt;Organize related pages with the &lt;code&gt;children&lt;/code&gt; property.&lt;/li&gt;
&lt;li&gt;Wrap shared UI inside layout components.&lt;/li&gt;
&lt;li&gt;Render nested pages using &lt;code&gt;Outlet&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Keep routing scalable and easy to maintain as your application grows.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  🎥 Prefer Learning by Watching?
&lt;/h2&gt;

&lt;p&gt;This article covers the concepts step by step, but if you'd like to see the complete implementation in action—including project setup, nested layouts, authentication routing, and best practices—check out &lt;strong&gt;Episode 6&lt;/strong&gt; of my &lt;strong&gt;React Authentication &amp;amp; Authorization&lt;/strong&gt; series.&lt;/p&gt;

&lt;p&gt;📺 &lt;strong&gt;Watch here:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=n0evocfZls0&amp;amp;list=PL_02r0p8Ku_5-h4teExCf6egkktSQblC4&amp;amp;index=6" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=n0evocfZls0&amp;amp;list=PL_02r0p8Ku_5-h4teExCf6egkktSQblC4&amp;amp;index=6&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The full playlist walks through building a modern authentication system with React Router, protected routes, JWT authentication, authorization, and much more from scratch.&lt;/p&gt;

&lt;p&gt;Happy coding! 🚀&lt;/p&gt;

</description>
      <category>react</category>
      <category>frontend</category>
      <category>frontendchallenge</category>
    </item>
    <item>
      <title>🚀 Deploy a Full Stack React Application (Firebase + Render) — Complete Deployment Guide (2026)</title>
      <dc:creator>codeek</dc:creator>
      <pubDate>Sun, 19 Jul 2026 08:47:21 +0000</pubDate>
      <link>https://dev.to/codeek/deploy-a-full-stack-react-application-firebase-render-complete-deployment-guide-2026-c0l</link>
      <guid>https://dev.to/codeek/deploy-a-full-stack-react-application-firebase-render-complete-deployment-guide-2026-c0l</guid>
      <description>&lt;p&gt;Deploying your application is one of the most exciting parts of web development. After spending hours building features, authentication, payments, and dashboards, it’s finally time to make your application accessible to everyone.&lt;/p&gt;

&lt;p&gt;In this guide, you'll learn how to deploy a modern full-stack application where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;⚛️ React (Vite) is hosted on &lt;strong&gt;Firebase Hosting&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;🚀 Express.js backend is deployed on &lt;strong&gt;Render&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;🗄️ PostgreSQL (Neon/Supabase or any hosted database) remains online&lt;/li&gt;
&lt;li&gt;🔒 Environment variables stay secure&lt;/li&gt;
&lt;li&gt;🌍 Your frontend communicates with your backend in production&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By the end of this tutorial, you'll have a production-ready deployment pipeline suitable for portfolios, personal projects, and even startup MVPs.&lt;/p&gt;




&lt;h2&gt;
  
  
  🏗️ Final Architecture
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Users
   │
   ▼
Firebase Hosting (React)
   │
HTTPS API Requests
   │
   ▼
Render (Express API)
   │
   ▼
Database (Neon/PostgreSQL)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Separating the frontend and backend makes your application easier to scale, maintain, and deploy independently.&lt;/p&gt;




&lt;h2&gt;
  
  
  📋 Prerequisites
&lt;/h2&gt;

&lt;p&gt;Before starting, make sure you have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Node.js installed&lt;/li&gt;
&lt;li&gt;Firebase account&lt;/li&gt;
&lt;li&gt;Render account&lt;/li&gt;
&lt;li&gt;GitHub repository&lt;/li&gt;
&lt;li&gt;Production database (Neon, Supabase, PostgreSQL, etc.)&lt;/li&gt;
&lt;li&gt;React frontend&lt;/li&gt;
&lt;li&gt;Express backend&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example project structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Ecommerce/
│
├── client/
│   ├── src/
│   ├── public/
│   └── package.json
│
└── server/
    ├── controllers/
    ├── routes/
    ├── middleware/
    ├── app.js
    └── package.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  🤔 Why Firebase + Render?
&lt;/h2&gt;

&lt;p&gt;This combination is perfect for modern React applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  🔥 Firebase Hosting
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Global CDN&lt;/li&gt;
&lt;li&gt;HTTPS by default&lt;/li&gt;
&lt;li&gt;Extremely fast&lt;/li&gt;
&lt;li&gt;Easy deployment&lt;/li&gt;
&lt;li&gt;Excellent for React/Vite projects&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🚀 Render
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Free starter tier&lt;/li&gt;
&lt;li&gt;Automatic GitHub deployments&lt;/li&gt;
&lt;li&gt;Environment variable support&lt;/li&gt;
&lt;li&gt;SSL included&lt;/li&gt;
&lt;li&gt;Great Express support&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Step 1 — Prepare Your Backend
&lt;/h2&gt;

&lt;p&gt;Before deployment, make sure your backend works locally.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install
&lt;/span&gt;npm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Visit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;http://localhost:5000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ensure your API responds correctly.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 2 — Configure Environment Variables
&lt;/h2&gt;

&lt;p&gt;Never hardcode secrets.&lt;/p&gt;

&lt;p&gt;Create a &lt;code&gt;.env&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PORT=5000
DATABASE_URL=your_database_url
JWT_SECRET=your_secret
STRIPE_SECRET_KEY=your_key
CLIENT_URL=http://localhost:5173
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Never commit this file.&lt;/p&gt;

&lt;p&gt;Instead, add it to &lt;code&gt;.gitignore&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;.env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 3 — Configure CORS
&lt;/h2&gt;

&lt;p&gt;When the frontend is hosted on Firebase, Express must allow requests from that domain.&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="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;use&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="nf"&gt;cors&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;origin&lt;/span&gt;&lt;span class="p"&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;http://localhost:5173&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;https://your-app.web.app&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;https://your-app.firebaseapp.com&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="na"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Later you'll replace these URLs with your production Firebase domain.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 4 — Push Your Backend to GitHub
&lt;/h2&gt;

&lt;p&gt;Initialize Git if necessary.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Commit your project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git add &lt;span class="nb"&gt;.&lt;/span&gt;
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"Initial deployment"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Push to GitHub.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git push origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 5 — Deploy Express Backend to Render
&lt;/h2&gt;

&lt;p&gt;Login to &lt;strong&gt;Render&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Create:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;New +
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Choose:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Web Service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Connect your GitHub repository.&lt;/p&gt;

&lt;p&gt;Select your backend repository.&lt;/p&gt;

&lt;h3&gt;
  
  
  Build Command
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Start Command
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node app.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;depending on your project.&lt;/p&gt;

&lt;h3&gt;
  
  
  Root Directory
&lt;/h3&gt;

&lt;p&gt;If your backend lives inside:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Set:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Root Directory = server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Environment Variables
&lt;/h3&gt;

&lt;p&gt;Add every variable from your &lt;code&gt;.env&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight properties"&gt;&lt;code&gt;&lt;span class="err"&gt;DATABASE_URL&lt;/span&gt;
&lt;span class="err"&gt;JWT_SECRET&lt;/span&gt;
&lt;span class="err"&gt;STRIPE_SECRET_KEY&lt;/span&gt;
&lt;span class="err"&gt;CLIENT_URL&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Render securely stores these values, so they are never committed to Git.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 6 — Wait for Deployment
&lt;/h2&gt;

&lt;p&gt;Render will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clone your repository&lt;/li&gt;
&lt;li&gt;Install dependencies&lt;/li&gt;
&lt;li&gt;Build the application&lt;/li&gt;
&lt;li&gt;Start the server&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Eventually you'll receive:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://your-api.onrender.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Test it.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://your-api.onrender.com/api/products
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you receive JSON…&lt;/p&gt;

&lt;p&gt;🎉 &lt;strong&gt;Congratulations! Your backend is live.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 7 — Update Frontend API URL
&lt;/h2&gt;

&lt;p&gt;Instead of:&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="nx"&gt;axios&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;http://localhost:5000/api/products&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;p&gt;Use environment variables.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;VITE_API_URL=https://your-api.onrender.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create an Axios instance.&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;axios&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;axios&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="nx"&gt;axios&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;create&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;baseURL&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;meta&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;VITE_API_URL&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;Now your frontend automatically switches between development and production.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 8 — Prepare React for Production
&lt;/h2&gt;

&lt;p&gt;Install Firebase CLI.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; firebase-tools
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Login.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;firebase login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Initialize hosting.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;firebase init hosting
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Choose:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Existing Firebase Project
Hosting
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the public directory enter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dist
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When prompted:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Single Page Application?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Choose:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Yes
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do &lt;strong&gt;not&lt;/strong&gt; overwrite &lt;code&gt;index.html&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 9 — Build React
&lt;/h2&gt;



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

&lt;/div&gt;



&lt;p&gt;This generates:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dist/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your production build is ready.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 10 — Deploy to Firebase
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;firebase deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Firebase provides:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://your-project.web.app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://your-project.firebaseapp.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your React application is now served globally over HTTPS.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 11 — Update Backend CORS
&lt;/h2&gt;

&lt;p&gt;Replace:&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="nx"&gt;origin&lt;/span&gt;&lt;span class="p"&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;http://localhost:5173&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;p&gt;with:&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="nx"&gt;origin&lt;/span&gt;&lt;span class="p"&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;http://localhost:5173&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;https://your-project.web.app&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;https://your-project.firebaseapp.com&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Redeploy your backend.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 12 — Test Everything
&lt;/h2&gt;

&lt;p&gt;Visit your Firebase URL and verify:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ Home page&lt;/li&gt;
&lt;li&gt;✅ Authentication&lt;/li&gt;
&lt;li&gt;✅ Login&lt;/li&gt;
&lt;li&gt;✅ Register&lt;/li&gt;
&lt;li&gt;✅ Products&lt;/li&gt;
&lt;li&gt;✅ Categories&lt;/li&gt;
&lt;li&gt;✅ Cart&lt;/li&gt;
&lt;li&gt;✅ Orders&lt;/li&gt;
&lt;li&gt;✅ Stripe Checkout&lt;/li&gt;
&lt;li&gt;✅ Protected routes&lt;/li&gt;
&lt;li&gt;✅ Logout&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Open Developer Tools.&lt;/p&gt;

&lt;p&gt;There should be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ No CORS errors&lt;/li&gt;
&lt;li&gt;✅ No 404 errors&lt;/li&gt;
&lt;li&gt;✅ Successful API requests&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  💡 Production Tips
&lt;/h1&gt;

&lt;h2&gt;
  
  
  🔒 Use HTTPS Everywhere
&lt;/h2&gt;

&lt;p&gt;Both Firebase and Render provide HTTPS by default.&lt;/p&gt;

&lt;p&gt;Never mix HTTP and HTTPS.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔐 Keep Secrets Secure
&lt;/h2&gt;

&lt;p&gt;Never expose:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;JWT Secret&lt;/li&gt;
&lt;li&gt;Stripe Secret Key&lt;/li&gt;
&lt;li&gt;Database URL&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Only variables beginning with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;VITE_
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;should be exposed to the frontend.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔄 Enable Automatic Deployments
&lt;/h2&gt;

&lt;p&gt;Every push to GitHub can automatically trigger a deployment on Render, making continuous delivery effortless.&lt;/p&gt;




&lt;h1&gt;
  
  
  ❌ Common Deployment Errors
&lt;/h1&gt;

&lt;h2&gt;
  
  
  CORS Error
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;Access-Control-Allow-Origin
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Fix&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Add your Firebase domain to Express CORS.&lt;/p&gt;




&lt;h2&gt;
  
  
  API Not Found
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;404
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check your Axios &lt;code&gt;baseURL&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Blank React Screen
&lt;/h2&gt;

&lt;p&gt;Usually:&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;failed.&lt;/p&gt;

&lt;p&gt;Always build locally first.&lt;/p&gt;




&lt;h2&gt;
  
  
  Environment Variables Missing
&lt;/h2&gt;

&lt;p&gt;Restart your Render service after updating environment variables.&lt;/p&gt;




&lt;h2&gt;
  
  
  Wrong Build Folder
&lt;/h2&gt;

&lt;p&gt;For Vite, use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dist
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;not&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;






&lt;h1&gt;
  
  
  ✅ Deployment Checklist
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;✅ Backend deployed&lt;/li&gt;
&lt;li&gt;✅ Database connected&lt;/li&gt;
&lt;li&gt;✅ Environment variables added&lt;/li&gt;
&lt;li&gt;✅ Firebase Hosting configured&lt;/li&gt;
&lt;li&gt;✅ React built&lt;/li&gt;
&lt;li&gt;✅ Axios uses production URL&lt;/li&gt;
&lt;li&gt;✅ CORS updated&lt;/li&gt;
&lt;li&gt;✅ HTTPS enabled&lt;/li&gt;
&lt;li&gt;✅ Everything tested&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  🎉 Conclusion
&lt;/h1&gt;

&lt;p&gt;Congratulations!&lt;/p&gt;

&lt;p&gt;You now have a fully deployed modern full-stack application with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;⚛️ React hosted on Firebase Hosting&lt;/li&gt;
&lt;li&gt;🚀 Express running on Render&lt;/li&gt;
&lt;li&gt;🗄️ PostgreSQL hosted online&lt;/li&gt;
&lt;li&gt;🔒 Secure environment variables&lt;/li&gt;
&lt;li&gt;🌍 Production-ready frontend/backend communication&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This architecture is simple, scalable, and perfect for portfolios, personal projects, and startup MVPs.&lt;/p&gt;

&lt;p&gt;As your application grows, you can further improve it by adding:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Custom domains&lt;/li&gt;
&lt;li&gt;CI/CD pipelines&lt;/li&gt;
&lt;li&gt;Monitoring&lt;/li&gt;
&lt;li&gt;Logging&lt;/li&gt;
&lt;li&gt;Docker&lt;/li&gt;
&lt;li&gt;Automated testing&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Happy coding! 🚀&lt;/p&gt;




&lt;h1&gt;
  
  
  🎥 Prefer Watching Instead?
&lt;/h1&gt;

&lt;p&gt;This article accompanies &lt;strong&gt;Part 18&lt;/strong&gt; of my &lt;strong&gt;Modern React E-Commerce Series&lt;/strong&gt;, where I walk through the complete deployment process step by step.&lt;/p&gt;

&lt;p&gt;In the video you'll learn:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🚀 Deploy an Express backend to Render&lt;/li&gt;
&lt;li&gt;🔥 Host a React (Vite) frontend on Firebase Hosting&lt;/li&gt;
&lt;li&gt;🌍 Configure production environment variables&lt;/li&gt;
&lt;li&gt;🔐 Handle CORS correctly&lt;/li&gt;
&lt;li&gt;🔄 Connect frontend and backend&lt;/li&gt;
&lt;li&gt;✅ Deploy a real-world full-stack application from start to finish&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you're building along with the series, this lesson completes the journey by taking your application from local development to a live production deployment.&lt;/p&gt;

&lt;p&gt;👉 &lt;strong&gt;Watch Part 18&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=3LMJjIwZDx0&amp;amp;list=PL_02r0p8Ku_6tR8L-n-yj7MW8rrMtswwk&amp;amp;index=18" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=3LMJjIwZDx0&amp;amp;list=PL_02r0p8Ku_6tR8L-n-yj7MW8rrMtswwk&amp;amp;index=18&lt;/a&gt;&lt;/p&gt;




&lt;h1&gt;
  
  
  📚 Continue Learning — Complete React E-Commerce Playlist
&lt;/h1&gt;

&lt;p&gt;If you're interested in building a production-ready e-commerce application from scratch, check out the complete playlist on my YouTube channel &lt;strong&gt;Codeek&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The series covers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;⚛️ Modern React&lt;/li&gt;
&lt;li&gt;🎨 Chakra UI&lt;/li&gt;
&lt;li&gt;🔄 React Query&lt;/li&gt;
&lt;li&gt;📦 Zustand&lt;/li&gt;
&lt;li&gt;💳 Stripe Payments&lt;/li&gt;
&lt;li&gt;🗄️ Express.js Backend&lt;/li&gt;
&lt;li&gt;🐘 PostgreSQL&lt;/li&gt;
&lt;li&gt;🚀 Firebase Hosting&lt;/li&gt;
&lt;li&gt;☁️ Render Deployment&lt;/li&gt;
&lt;li&gt;📁 Project Architecture&lt;/li&gt;
&lt;li&gt;🛒 Complete E-Commerce Development&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whether you're preparing for interviews, building your portfolio, or creating your next startup, this series walks you through every step with practical, real-world examples.&lt;/p&gt;

&lt;p&gt;⭐ If you find the tutorials helpful, consider subscribing to &lt;strong&gt;Codeek&lt;/strong&gt; and sharing the playlist with fellow developers.&lt;/p&gt;

&lt;p&gt;Happy coding! 🚀&lt;/p&gt;

</description>
      <category>node</category>
      <category>react</category>
      <category>webdev</category>
      <category>firebase</category>
    </item>
    <item>
      <title>🚀 Stop Sorting on the Frontend! Implement Server-Side Sorting with Chakra UI Select &amp; React Query</title>
      <dc:creator>codeek</dc:creator>
      <pubDate>Sat, 18 Jul 2026 12:07:34 +0000</pubDate>
      <link>https://dev.to/codeek/stop-sorting-on-the-frontend-implement-server-side-sorting-with-chakra-ui-select-react-query-4pb8</link>
      <guid>https://dev.to/codeek/stop-sorting-on-the-frontend-implement-server-side-sorting-with-chakra-ui-select-react-query-4pb8</guid>
      <description>&lt;h2&gt;
  
  
  🚀 Server-Side Sorting in React with React Query &amp;amp; Chakra UI
&lt;/h2&gt;

&lt;p&gt;Most of the Frontend developers directly jump into the native sort function given by Javascript when it comes to sorting:&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;sortedProducts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;products&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;b&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;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;price&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This works great for small datasets.&lt;/p&gt;

&lt;p&gt;But what happens when your API returns &lt;strong&gt;50,000+ products&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;Every user must download every product before React can sort them. That results in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;❌ Large API responses&lt;/li&gt;
&lt;li&gt;❌ Slow page loads&lt;/li&gt;
&lt;li&gt;❌ High memory usage&lt;/li&gt;
&lt;li&gt;❌ Poor scalability&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A better solution is &lt;strong&gt;server-side sorting&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Instead of sorting in React, send the sorting options to your backend using query parameters and let your database return the data already sorted.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Server-Side Sorting?
&lt;/h2&gt;

&lt;h3&gt;
  
  
  ❌ Frontend Sorting
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /products
        ↓
Returns 50,000 Products
        ↓
React Sorts Everything
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Problems
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Large API responses&lt;/li&gt;
&lt;li&gt;Slow loading&lt;/li&gt;
&lt;li&gt;High memory usage&lt;/li&gt;
&lt;li&gt;Doesn't scale&lt;/li&gt;
&lt;li&gt;More work for the browser&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ✅ Server-Side Sorting
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /products?sortBy=price&amp;amp;order=asc
        ↓
Backend sorts database
        ↓
Returns sorted products
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Benefits
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Faster responses&lt;/li&gt;
&lt;li&gt;Smaller payloads&lt;/li&gt;
&lt;li&gt;Database does the heavy lifting&lt;/li&gt;
&lt;li&gt;Better scalability&lt;/li&gt;
&lt;li&gt;Cleaner frontend&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Step 1 — Install Dependencies
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; @tanstack/react-query axios
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 2 — Create API Function
&lt;/h2&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;axios&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;axios&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getProducts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sortBy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;order&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;axios&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;/products&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="na"&gt;params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;sortBy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nx"&gt;order&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&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;Example request:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /products?sortBy=price&amp;amp;order=desc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 3 — Create React Query Hook
&lt;/h2&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useQuery&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;@tanstack/react-query&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;useProducts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sortBy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;order&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;useQuery&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;queryKey&lt;/span&gt;&lt;span class="p"&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;products&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;sortBy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;order&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="na"&gt;queryFn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;getProducts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sortBy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;order&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each sorting combination gets its own cache automatically.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 4 — Create the Sort Dropdown
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Select&lt;/span&gt;
  &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
  &lt;span class="na"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setSort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;option&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"latest"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Latest&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;option&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;option&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"price-asc"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Price: Low to High&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;option&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;option&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"price-desc"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Price: High to Low&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;option&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;option&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"name-asc"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Name (A-Z)&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;option&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;option&lt;/span&gt; &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"name-desc"&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Name (Z-A)&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;option&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;Select&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 5 — Convert the Selected Option
&lt;/h2&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;sortOptions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;latest&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;sortBy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;createdAt&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;order&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;desc&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;price-asc&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="na"&gt;sortBy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;price&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;order&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;asc&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;price-desc&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="na"&gt;sortBy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;price&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;order&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;desc&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name-asc&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="na"&gt;sortBy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;order&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;asc&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name-desc&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="na"&gt;sortBy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;order&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;desc&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;sortBy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;order&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sortOptions&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 6 — Fetch Sorted Products
&lt;/h2&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="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;isLoading&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useProducts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sortBy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;order&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Flow:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User Selects Sort
        ↓
React State Updates
        ↓
React Query detects new queryKey
        ↓
API Request
        ↓
Backend Sorts Database
        ↓
Updated Products
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 7 — Render Products
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;products&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;product&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ProductCard&lt;/span&gt;
    &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
    &lt;span class="na"&gt;product&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;product&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;))}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;React Query automatically handles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Loading state&lt;/li&gt;
&lt;li&gt;Error state&lt;/li&gt;
&lt;li&gt;Request caching&lt;/li&gt;
&lt;li&gt;Background refetching&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Bonus — Combine Search + Sorting
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /products?search=iphone&amp;amp;sortBy=price&amp;amp;order=asc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;useQuery&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;queryKey&lt;/span&gt;&lt;span class="p"&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;products&lt;/span&gt;&lt;span class="dl"&gt;"&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="nx"&gt;sortBy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;order&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;queryFn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class="nf"&gt;getProducts&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="nx"&gt;sortBy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nx"&gt;order&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}),&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every search and sorting combination is cached independently.&lt;/p&gt;




&lt;h2&gt;
  
  
  Complete Flow
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User Selects Sort
        ↓
Chakra UI Select
        ↓
React State
        ↓
React Query
        ↓
GET /products?sortBy=price&amp;amp;order=asc
        ↓
Backend Database
        ↓
Sorted Products
        ↓
React UI Updates
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






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

&lt;p&gt;Frontend sorting is perfectly fine for small datasets.&lt;/p&gt;

&lt;p&gt;However, for production applications such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ecommerce&lt;/li&gt;
&lt;li&gt;CRM Systems&lt;/li&gt;
&lt;li&gt;Admin Dashboards&lt;/li&gt;
&lt;li&gt;Inventory Management&lt;/li&gt;
&lt;li&gt;SaaS Platforms&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Server-side sorting is the preferred approach because it minimizes data transfer, improves performance, and keeps your frontend lightweight.&lt;/p&gt;

&lt;p&gt;Combined with &lt;strong&gt;TanStack React Query&lt;/strong&gt; and &lt;strong&gt;Chakra UI&lt;/strong&gt;, you can build scalable, production-ready React applications with very little code.&lt;/p&gt;




&lt;h2&gt;
  
  
  🎥 Watch the Full Ecommerce Series
&lt;/h2&gt;

&lt;p&gt;This tutorial is part of my &lt;strong&gt;Modern Ecommerce in React &amp;amp; Modern Stacks (2026)&lt;/strong&gt; series.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📺 Full Playlist&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=Jluy-W9eP-4&amp;amp;list=PL_02r0p8Ku_6tR8L-n-yj7MW8rrMtswwk" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=Jluy-W9eP-4&amp;amp;list=PL_02r0p8Ku_6tR8L-n-yj7MW8rrMtswwk&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🎬 This Episode&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=NUGWQuFeNN8&amp;amp;list=PL_02r0p8Ku_6tR8L-n-yj7MW8rrMtswwk&amp;amp;index=12" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=NUGWQuFeNN8&amp;amp;list=PL_02r0p8Ku_6tR8L-n-yj7MW8rrMtswwk&amp;amp;index=12&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you enjoy practical React tutorials covering &lt;strong&gt;React Query, Chakra UI, Zustand, Stripe, Firebase, Authentication, and Full-Stack Development&lt;/strong&gt;, consider following &lt;strong&gt;Codeek&lt;/strong&gt; for more production-ready React content.&lt;/p&gt;

</description>
      <category>react</category>
      <category>frontend</category>
      <category>frontendchallenge</category>
    </item>
    <item>
      <title>🚀 Stop Filtering on the Frontend, Build Server-Side Search in React using React Query For Performance Optimization</title>
      <dc:creator>codeek</dc:creator>
      <pubDate>Fri, 17 Jul 2026 09:13:30 +0000</pubDate>
      <link>https://dev.to/codeek/stop-filtering-on-the-frontend-build-server-side-search-in-react-using-react-query-for-2p5l</link>
      <guid>https://dev.to/codeek/stop-filtering-on-the-frontend-build-server-side-search-in-react-using-react-query-for-2p5l</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9jhs7mhqc2vwivge61by.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9jhs7mhqc2vwivge61by.png" alt="Searching using React query" width="800" height="533"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Every React Developer Has Done This at Least Once 😅
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;filteredProducts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;products&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;product&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;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;title&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;includes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;search&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It works...&lt;/p&gt;

&lt;p&gt;Until your API returns &lt;strong&gt;10,000+ products&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Now you're downloading thousands of unnecessary records just to search for a single keyword.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;❌ Slower loading&lt;/li&gt;
&lt;li&gt;❌ Wasted bandwidth&lt;/li&gt;
&lt;li&gt;❌ High memory usage&lt;/li&gt;
&lt;li&gt;❌ Doesn't scale&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So what's the better approach?&lt;/p&gt;

&lt;h2&gt;
  
  
  🚀 The Solution: Server-Side Search
&lt;/h2&gt;

&lt;p&gt;Instead of downloading every product and filtering them inside React, let your backend search the database and return &lt;strong&gt;only the matching records&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;When you combine this with &lt;strong&gt;TanStack React Query&lt;/strong&gt;, you also get:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ Automatic caching&lt;/li&gt;
&lt;li&gt;✅ Loading states&lt;/li&gt;
&lt;li&gt;✅ Background refetching&lt;/li&gt;
&lt;li&gt;✅ Request deduplication&lt;/li&gt;
&lt;li&gt;✅ Cleaner server-state management&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this guide, we'll build a production-ready server-side search using React Query.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Server-Side Search?
&lt;/h2&gt;

&lt;p&gt;Imagine an ecommerce application with &lt;strong&gt;100,000 products&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  ❌ Client-Side Search
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Frontend
     ↓
GET /products
     ↓
100,000 products
     ↓
React filters data
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Problems
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Huge API responses&lt;/li&gt;
&lt;li&gt;Slow initial loading&lt;/li&gt;
&lt;li&gt;High memory usage&lt;/li&gt;
&lt;li&gt;Wasted network bandwidth&lt;/li&gt;
&lt;li&gt;Poor scalability&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  ✅ Server-Side Search
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Frontend
     ↓
GET /products?search=iphone
     ↓
Backend searches database
     ↓
Returns only matching products
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Benefits
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Faster responses&lt;/li&gt;
&lt;li&gt;Smaller payloads&lt;/li&gt;
&lt;li&gt;Better scalability&lt;/li&gt;
&lt;li&gt;Lower memory usage&lt;/li&gt;
&lt;li&gt;Better user experience&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Project Structure
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;src
├── api
│     productApi.js
│
├── hooks
│     useProducts.js
│
├── pages
│     ProductPage.jsx
│
└── components
      SearchInput.jsx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keeping your API logic separate from your UI makes applications much easier to maintain as they grow.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 1 — Install React Query
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; @tanstack/react-query axios
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create your Query Client.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;queryClient&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;QueryClient&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;QueryClientProvider&lt;/span&gt; &lt;span class="na"&gt;client&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;queryClient&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;App&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;QueryClientProvider&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Step 2 — Create the API Function
&lt;/h1&gt;

&lt;p&gt;Your backend should support query parameters like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;GET /products?search=iphone
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Create the API function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getProducts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;search&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;axios&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;/products&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="na"&gt;params&lt;/span&gt;&lt;span class="p"&gt;:&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="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="nx"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&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;Instead of filtering on the frontend, we're sending the search value directly to the backend.&lt;/p&gt;




&lt;h1&gt;
  
  
  Step 3 — Create a React Query Hook
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;useProducts&lt;/span&gt; &lt;span class="o"&gt;=&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;useQuery&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;queryKey&lt;/span&gt;&lt;span class="p"&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;products&lt;/span&gt;&lt;span class="dl"&gt;"&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="na"&gt;queryFn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;getProducts&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="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;This is where React Query really shines.&lt;/p&gt;

&lt;p&gt;Every unique search term gets its own cache automatically.&lt;/p&gt;

&lt;p&gt;Searching for:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;iphone
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and later:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;samsung
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;creates two independent cached queries without any extra code.&lt;/p&gt;




&lt;h1&gt;
  
  
  Step 4 — Create Search State
&lt;/h1&gt;



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

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;input&lt;/span&gt;
  &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;search&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
  &lt;span class="na"&gt;onChange&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setSearch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
  &lt;span class="na"&gt;placeholder&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Search products..."&lt;/span&gt;
&lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h1&gt;
  
  
  Step 5 — Fetch Products
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;isLoading&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useProducts&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every time the search changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User Types
      ↓
React State Updates
      ↓
React Query
      ↓
Backend API
      ↓
Updated Products
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No client-side filtering required.&lt;/p&gt;




&lt;h1&gt;
  
  
  Step 6 — Render Products
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nx"&gt;products&lt;/span&gt;&lt;span class="p"&gt;?.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;product&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="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;ProductCard&lt;/span&gt; &lt;span class="na"&gt;key&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;product&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="na"&gt;product&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;product&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;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it.&lt;/p&gt;

&lt;p&gt;React Query automatically handles:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Caching&lt;/li&gt;
&lt;li&gt;Loading states&lt;/li&gt;
&lt;li&gt;Background refetching&lt;/li&gt;
&lt;li&gt;Request deduplication&lt;/li&gt;
&lt;li&gt;Server-state synchronization&lt;/li&gt;
&lt;/ul&gt;




&lt;h1&gt;
  
  
  ⚡ Bonus Improvement: Debounce Search
&lt;/h1&gt;

&lt;p&gt;Without debouncing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;i
ip
iph
ipho
iphon
iphone
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's &lt;strong&gt;6 API requests&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Instead, debounce the search input by &lt;strong&gt;300–500ms&lt;/strong&gt; so the request is only sent after the user pauses typing.&lt;/p&gt;

&lt;p&gt;This significantly reduces unnecessary API calls while keeping the UI responsive.&lt;/p&gt;




&lt;h1&gt;
  
  
  Complete Flow
&lt;/h1&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User Types
      ↓
Search State Updates
      ↓
React Query detects new queryKey
      ↓
Calls Backend API
      ↓
Database searches records
      ↓
Returns matching products
      ↓
React UI updates
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Simple.&lt;/p&gt;

&lt;p&gt;Clean.&lt;/p&gt;

&lt;p&gt;Scalable.&lt;/p&gt;




&lt;h1&gt;
  
  
  Why React Query Makes This Better
&lt;/h1&gt;

&lt;p&gt;Without React Query, you'd have to manually manage:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Loading states&lt;/li&gt;
&lt;li&gt;Error handling&lt;/li&gt;
&lt;li&gt;Caching&lt;/li&gt;
&lt;li&gt;Duplicate requests&lt;/li&gt;
&lt;li&gt;Background refetching&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;React Query gives you all of these features out of the box, making it a perfect companion for server-side search.&lt;/p&gt;




&lt;h1&gt;
  
  
  Final Thoughts
&lt;/h1&gt;

&lt;p&gt;Client-side searching is completely fine for &lt;strong&gt;small datasets&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;However, once you're building applications like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🛒 Ecommerce&lt;/li&gt;
&lt;li&gt;📊 Admin Dashboards&lt;/li&gt;
&lt;li&gt;👥 CRM Systems&lt;/li&gt;
&lt;li&gt;📦 Inventory Management&lt;/li&gt;
&lt;li&gt;🏢 HR Platforms&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;server-side search becomes the professional solution.&lt;/p&gt;

&lt;p&gt;Your frontend stays lightweight, your backend does the heavy lifting, and your users enjoy a much faster experience.&lt;/p&gt;




&lt;h1&gt;
  
  
  🎥 Watch the Full Video Tutorial
&lt;/h1&gt;

&lt;p&gt;This article is part of my &lt;strong&gt;Modern Ecommerce in React &amp;amp; Modern Stacks (2026)&lt;/strong&gt; series.&lt;/p&gt;

&lt;p&gt;▶️ Full Playlist&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=Jluy-W9eP-4&amp;amp;list=PL_02r0p8Ku_6tR8L-n-yj7MW8rrMtswwk&amp;amp;index=1" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=Jluy-W9eP-4&amp;amp;list=PL_02r0p8Ku_6tR8L-n-yj7MW8rrMtswwk&amp;amp;index=1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Episode 11&lt;/strong&gt;, I walk through the complete implementation of server-side search using &lt;strong&gt;React Query&lt;/strong&gt;, &lt;strong&gt;Axios&lt;/strong&gt;, and backend query parameters.&lt;/p&gt;

&lt;p&gt;👉 Watch Episode 11&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=QrA5_bvORZU&amp;amp;list=PL_02r0p8Ku_6tR8L-n-yj7MW8rrMtswwk&amp;amp;index=11" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=QrA5_bvORZU&amp;amp;list=PL_02r0p8Ku_6tR8L-n-yj7MW8rrMtswwk&amp;amp;index=11&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you're following the full series, you'll learn how to build a production-ready ecommerce application from scratch using modern React technologies.&lt;/p&gt;




&lt;p&gt;⭐ &lt;strong&gt;If this article helped you, consider following &lt;em&gt;Codeek&lt;/em&gt; for more tutorials on React, TypeScript, Chakra UI, TanStack Query, Zustand, Stripe, Firebase, and full-stack development.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Happy coding! 🚀&lt;/p&gt;

</description>
      <category>react</category>
      <category>frontend</category>
      <category>webdev</category>
      <category>api</category>
    </item>
    <item>
      <title>🚀React Router Setup Using createBrowserRouter (v6+ Pattern)</title>
      <dc:creator>codeek</dc:creator>
      <pubDate>Wed, 08 Jul 2026 07:38:09 +0000</pubDate>
      <link>https://dev.to/codeek/react-router-setup-using-createbrowserrouter-v6-pattern-fk1</link>
      <guid>https://dev.to/codeek/react-router-setup-using-createbrowserrouter-v6-pattern-fk1</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6gtau1fbnxn69bi09shp.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.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F6gtau1fbnxn69bi09shp.png" alt=" " width="800" height="533"&gt;&lt;/a&gt;&lt;br&gt;
If you're still using &lt;code&gt;BrowserRouter&lt;/code&gt; with &lt;code&gt;Routes&lt;/code&gt;, it's time to move to the modern React Router pattern using &lt;code&gt;createBrowserRouter&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This approach makes your application more scalable and prepares your project for advanced features like nested layouts, loaders, actions, and protected routes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📦 Step 1: Install React Router&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm install react-router-dom&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
📁 Recommended Project Structure&lt;br&gt;
src/&lt;br&gt;
│&lt;br&gt;
├── layouts/&lt;br&gt;
│   └── MainLayout.jsx&lt;br&gt;
│&lt;br&gt;
├── pages/&lt;br&gt;
│   ├── Home.jsx&lt;br&gt;
│   ├── Products.jsx&lt;br&gt;
│   ├── ProductDetails.jsx&lt;br&gt;
│   ├── Cart.jsx&lt;br&gt;
│   └── NotFound.jsx&lt;br&gt;
│&lt;br&gt;
├── routes/&lt;br&gt;
│   └── index.jsx&lt;br&gt;
│&lt;br&gt;
├── App.jsx&lt;br&gt;
└── main.jsx&lt;/p&gt;

&lt;p&gt;Keeping your routes in a dedicated folder makes the application easier to maintain as it grows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;⚡ Step 2: Create Your Router&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create a file:&lt;/p&gt;

&lt;p&gt;src/routes/index.jsx&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;createBrowserRouter&lt;/span&gt;&lt;span class="p"&gt;,&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="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;MainLayout&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;../layouts/MainLayout&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="nx"&gt;Home&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;../pages/Home&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="nx"&gt;Products&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;../pages/Products&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="nx"&gt;ProductDetails&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;../pages/ProductDetails&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="nx"&gt;Cart&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;../pages/Cart&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="nx"&gt;NotFound&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;../pages/NotFound&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;router&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createBrowserRouter&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;path&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="na"&gt;element&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;MainLayout&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;,&lt;/span&gt;
    &lt;span class="na"&gt;children&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;element&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;Home&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="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;products&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;element&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;Products&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="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;products/:id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;element&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;ProductDetails&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="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;cart&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;element&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;Cart&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="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;path&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="na"&gt;element&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;NotFound&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;The router is created once and supplied to your application through RouterProvider, which is the recommended pattern for modern React Router applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🏗 Step 3: Configure main.jsx&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&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="nx"&gt;ReactDOM&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-dom/client&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;RouterProvider&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="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;router&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;./routes&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;ReactDOM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createRoot&lt;/span&gt;&lt;span class="p"&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="s2"&gt;root&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nf"&gt;render&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;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;StrictMode&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;RouterProvider&lt;/span&gt; &lt;span class="na"&gt;router&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;router&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;React&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;StrictMode&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🏠 Step 4: Create a Layout&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight tsx"&gt;&lt;code&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Outlet&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="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;MainLayout&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;header&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Navbar&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;header&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;main&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;Outlet&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;main&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;footer&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;Footer&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;footer&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;MainLayout&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt; is where nested child routes are rendered.&lt;/p&gt;

&lt;p&gt;📍 Route Overview&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;URL&lt;/th&gt;
&lt;th&gt;Component&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Home&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/products&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Products&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/products/:id&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Product Details&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;/cart&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Cart&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;*&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;404 Page&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;💡 Why Use createBrowserRouter?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;✅ Cleaner route configuration&lt;/p&gt;

&lt;p&gt;✅ Supports nested layouts effortlessly&lt;/p&gt;

&lt;p&gt;✅ Built for Data APIs (Loaders &amp;amp; Actions)&lt;/p&gt;

&lt;p&gt;✅ Easier authentication and protected routes&lt;/p&gt;

&lt;p&gt;✅ Better scalability for large React applications&lt;/p&gt;

&lt;p&gt;React Router recommends creating the router outside the React tree and passing it to RouterProvider for modern applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔥 What's Next?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once your router is configured, you can easily add:&lt;/p&gt;

&lt;p&gt;🔐 Protected Routes&lt;br&gt;
👤 Authentication&lt;br&gt;
📦 Nested Layouts&lt;br&gt;
⚡ Loaders &amp;amp; Actions&lt;br&gt;
❌ Error Pages&lt;br&gt;
🔄 Lazy Loading&lt;br&gt;
🌍 Dynamic Routes&lt;br&gt;
🎥 Learn React Router the Practical Way&lt;/p&gt;

&lt;p&gt;If you'd like to see everything built step by step—from installation to nested routes, protected routes, authentication, and real-world project structure—check out this tutorial:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📺 React Router Complete Setup&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=euk5pWCOIyg&amp;amp;list=PL_02r0p8Ku_6tR8L-n-yj7MW8rrMtswwk&amp;amp;index=4" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=euk5pWCOIyg&amp;amp;list=PL_02r0p8Ku_6tR8L-n-yj7MW8rrMtswwk&amp;amp;index=4&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You'll learn:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;✅ Modern React Router setup&lt;br&gt;
✅ createBrowserRouter&lt;br&gt;
✅ Nested Routing&lt;br&gt;
✅ Layouts&lt;br&gt;
✅ Navigation&lt;br&gt;
✅ Best Folder Structure&lt;br&gt;
🛒 Build a Production-Ready Ecommerce Application&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Want to apply React Router in a real project?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Watch the complete Ecommerce series where we build everything from scratch using modern React technologies:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tech Stack&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;⚛️ React&lt;br&gt;
🛣 React Router&lt;br&gt;
🎨 Chakra UI&lt;br&gt;
🐻 Zustand&lt;br&gt;
💳 Stripe Payment Integration&lt;br&gt;
📡 API Integration&lt;br&gt;
🛒 Shopping Cart&lt;br&gt;
🚀 Production Best Practices&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;📺 Full Ecommerce Playlist&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=Jluy-W9eP-4&amp;amp;list=PL_02r0p8Ku_6tR8L-n-yj7MW8rrMtswwk&amp;amp;index=1" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=Jluy-W9eP-4&amp;amp;list=PL_02r0p8Ku_6tR8L-n-yj7MW8rrMtswwk&amp;amp;index=1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you're aiming to build production-ready React applications instead of simple demos, this series is designed to help you understand how these technologies work together in a real-world ecommerce project.&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>frontend</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to Deploy/Host a React App to Firebase in few minutes: A Step-by-Step Guide</title>
      <dc:creator>codeek</dc:creator>
      <pubDate>Mon, 06 Jul 2026 12:56:17 +0000</pubDate>
      <link>https://dev.to/codeek/how-to-deployhost-a-react-app-to-firebase-in-few-minutes-a-step-by-step-guide-30a6</link>
      <guid>https://dev.to/codeek/how-to-deployhost-a-react-app-to-firebase-in-few-minutes-a-step-by-step-guide-30a6</guid>
      <description>&lt;p&gt;Taking a React application live doesn't have to be complicated. If you've built a React app and want a fast, secure, and reliable hosting solution, Firebase Hosting is one of the best options available.&lt;/p&gt;

&lt;p&gt;In this guide, you'll learn how to deploy your React application to production using Firebase Hosting in just a few minutes.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Firebase Hosting?
&lt;/h2&gt;

&lt;p&gt;Firebase Hosting provides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;⚡ Fast global CDN delivery&lt;/li&gt;
&lt;li&gt;🔒 Free SSL certificates&lt;/li&gt;
&lt;li&gt;🌍 Custom domain support&lt;/li&gt;
&lt;li&gt;🚀 Easy deployment with a single command&lt;/li&gt;
&lt;li&gt;🔄 CI/CD integration with GitHub&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Whether you're deploying a personal project, portfolio, SaaS dashboard, or production application, Firebase Hosting offers a simple and scalable solution.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 1: Install Firebase CLI
&lt;/h2&gt;

&lt;p&gt;To interact with Firebase services from your terminal, install the Firebase Command Line Interface globally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; firebase-tools
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After installation, verify that the CLI is available:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;firebase &lt;span class="nt"&gt;--version&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Step 2: Login to Firebase
&lt;/h2&gt;

&lt;p&gt;Authenticate your local machine with your Firebase account:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;firebase login
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You may be asked whether you want to enable anonymous usage reporting.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Allow Firebase to collect CLI usage and error reporting information? (Y/n)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Choose your preferred option.&lt;/p&gt;

&lt;p&gt;A browser window will open automatically. Sign in using the Google account associated with your Firebase project and grant the required permissions.&lt;/p&gt;

&lt;p&gt;Once authenticated successfully, you'll see a confirmation message in your terminal.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 3: Initialize Firebase Hosting
&lt;/h2&gt;

&lt;p&gt;Navigate to your React project directory and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;firebase init hosting
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Firebase CLI will guide you through several configuration steps.&lt;/p&gt;

&lt;h3&gt;
  
  
  Configuration Options
&lt;/h3&gt;

&lt;h4&gt;
  
  
  ✔ Ready to proceed?
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  ✔ Select a Firebase project
&lt;/h4&gt;

&lt;p&gt;Choose:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Use an existing project
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then select your Firebase project from the list.&lt;/p&gt;

&lt;h4&gt;
  
  
  ✔ Public directory
&lt;/h4&gt;

&lt;p&gt;If you're using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Vite → &lt;code&gt;dist&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Create React App → &lt;code&gt;build&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dist
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h4&gt;
  
  
  ✔ Configure as a Single-Page Application?
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Configure as a single-page app (rewrite all urls to /index.html)?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Choose:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is extremely important for React Router applications. It ensures that refreshing routes such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/products
/profile
/settings
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;won't result in a 404 error.&lt;/p&gt;

&lt;h4&gt;
  
  
  ✔ GitHub Actions Setup
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Set up automatic builds and deploys with GitHub?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Choose:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;N
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;unless you want to configure CI/CD immediately.&lt;/p&gt;

&lt;h4&gt;
  
  
  ✔ Overwrite Existing Files?
&lt;/h4&gt;

&lt;p&gt;If Firebase asks to overwrite existing files such as &lt;code&gt;index.html&lt;/code&gt;, select:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;N
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This prevents accidental replacement of your application files.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 4: Build Your React Application
&lt;/h2&gt;

&lt;p&gt;Before deploying, create a production build.&lt;/p&gt;

&lt;h3&gt;
  
  
  Vite
&lt;/h3&gt;



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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Create React App
&lt;/h3&gt;



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

&lt;/div&gt;



&lt;p&gt;This generates the optimized production assets inside your configured output directory.&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 5: Deploy to Firebase Hosting
&lt;/h2&gt;

&lt;p&gt;Now deploy your application:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;firebase deploy &lt;span class="nt"&gt;--only&lt;/span&gt; hosting
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Firebase will:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Upload your production build&lt;/li&gt;
&lt;li&gt;Configure hosting infrastructure&lt;/li&gt;
&lt;li&gt;Generate a public URL&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Example output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;✔ Deploy complete!

Hosting URL:
https://your-project.web.app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open the URL in your browser and your React application is now live 🎉&lt;/p&gt;




&lt;h2&gt;
  
  
  Common React Router Fix
&lt;/h2&gt;

&lt;p&gt;If you're using React Router, always answer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Configure as a single-page app?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Y
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Firebase will automatically create the required rewrite rules:&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;"hosting"&lt;/span&gt;&lt;span class="p"&gt;:&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;span class="nl"&gt;"rewrites"&lt;/span&gt;&lt;span class="p"&gt;:&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;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"source"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"**"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"destination"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/index.html"&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;span class="p"&gt;]&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;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;p&gt;This prevents route refreshes from returning 404 errors.&lt;/p&gt;




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

&lt;p&gt;Firebase Hosting is one of the easiest ways to deploy a React application. The setup takes only a few minutes, and you get global hosting, SSL, and excellent performance out of the box.&lt;/p&gt;

&lt;p&gt;The complete deployment workflow is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; firebase-tools
firebase login
firebase init hosting
npm run build
firebase deploy &lt;span class="nt"&gt;--only&lt;/span&gt; hosting
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it! Your React application is now live and accessible worldwide.&lt;/p&gt;

&lt;p&gt;Happy Coding! 🚀&lt;/p&gt;




&lt;h3&gt;
  
  
  🎥 Prefer a Video Tutorial?
&lt;/h3&gt;

&lt;p&gt;Watch the full deployment tutorial here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=1av63EJzyhg" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=1av63EJzyhg&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;If you enjoy React, TypeScript, and Full-Stack Development content, follow &lt;a href="https://www.youtube.com/@codeek0" rel="noopener noreferrer"&gt;Codeek&lt;/a&gt; on YouTube and Medium for more production-grade tutorials, courses, and real-world engineering practices.&lt;/p&gt;

</description>
      <category>react</category>
      <category>firebase</category>
      <category>web</category>
      <category>devops</category>
    </item>
    <item>
      <title>How Enterprise React Apps Handle JWT Token Refresh Automatically</title>
      <dc:creator>codeek</dc:creator>
      <pubDate>Mon, 06 Jul 2026 07:38:35 +0000</pubDate>
      <link>https://dev.to/codeek/build-a-production-ready-e-commerce-application-with-react-modern-frontend-technologies-3c15</link>
      <guid>https://dev.to/codeek/build-a-production-ready-e-commerce-application-with-react-modern-frontend-technologies-3c15</guid>
      <description>&lt;p&gt;Access Token &amp;amp; Refresh Token Authentication in React (Axios + React Query)&lt;/p&gt;

&lt;p&gt;Authentication is one of the most critical parts of modern web applications. In enterprise applications, simply storing a JWT and sending it with every request isn't enough. We need a secure mechanism that provides a seamless user experience while protecting user sessions.&lt;/p&gt;

&lt;p&gt;This is where Access Tokens and Refresh Tokens come into play.&lt;/p&gt;

&lt;p&gt;In this article, we'll understand how a production-ready authentication flow works using React, Axios, and React Query.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why Do We Need Two Tokens?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A common question developers ask is:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"Why not just use one JWT token?"&lt;/em&gt;&lt;br&gt;
&lt;strong&gt;&lt;em&gt;The answer is security.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Imagine your access token is stolen. If it never expires, an attacker could access your APIs indefinitely.&lt;/p&gt;

&lt;p&gt;Instead, enterprise applications separate authentication into two different tokens:&lt;/p&gt;

&lt;p&gt;Access Token&lt;br&gt;
Refresh Token&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Access Token&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;An Access Token is a short-lived JWT that is sent with every protected API request.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Characteristics&lt;/strong&gt;&lt;br&gt;
✅ Sent with every API request&lt;br&gt;
✅ Usually expires within 5–15 minutes&lt;br&gt;
✅ Stored only in memory (recommended) or a secure cookie&lt;br&gt;
✅ Contains user identity and permissions&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;&lt;br&gt;
Authorization: Bearer eyJhbGciOi...&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Refresh Token&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A Refresh Token has a completely different responsibility.&lt;/p&gt;

&lt;p&gt;Instead of accessing APIs, it is used only to obtain a new Access Token after the current one expires.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Characteristics&lt;/strong&gt;&lt;br&gt;
✅ Long-lived (days or weeks)&lt;br&gt;
✅ Never sent with every request&lt;br&gt;
✅ Stored inside an HttpOnly Secure Cookie&lt;br&gt;
✅ Sent only to the refresh endpoint&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Initial Login Flow&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;User Login&lt;br&gt;
     │&lt;br&gt;
     ▼&lt;br&gt;
Backend validates credentials&lt;br&gt;
     │&lt;br&gt;
     ▼&lt;br&gt;
Returns&lt;br&gt;
 ├── Access Token (15 min)&lt;br&gt;
 └── Refresh Token (7 days)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Authentication Flow&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A typical enterprise authentication flow looks like this:&lt;/p&gt;

&lt;p&gt;User Login&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
Backend validates credentials&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
Returns:&lt;br&gt;
• Access Token&lt;br&gt;
• Refresh Token&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
Frontend stores Access Token&lt;br&gt;
Refresh Token stays inside HttpOnly Cookie&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
User makes API requests&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
Access Token expires&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
Axios detects 401 Unauthorized&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
Calls /auth/refresh&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
Backend validates Refresh Token&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
Returns new Access Token&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
Retry original request&lt;/p&gt;

&lt;p&gt;The user never has to log in again while the Refresh Token remains valid.&lt;/p&gt;

&lt;p&gt;Why Store Refresh Token in an HttpOnly Cookie?&lt;/p&gt;

&lt;p&gt;Many beginners store both tokens in localStorage.&lt;/p&gt;

&lt;p&gt;This is not recommended.&lt;/p&gt;

&lt;p&gt;If your application suffers from an XSS (Cross-Site Scripting) attack, JavaScript can read everything stored in localStorage.&lt;/p&gt;

&lt;p&gt;An HttpOnly Cookie cannot be accessed by JavaScript, making it significantly more secure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Recommended Storage Strategy&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Token   Storage&lt;br&gt;
Access Token    Memory (React State, Zustand, Redux, etc.)&lt;br&gt;
Refresh Token   HttpOnly Secure Cookie&lt;br&gt;
Using Axios Interceptors&lt;/p&gt;

&lt;p&gt;Axios Interceptors allow us to intercept every request and response globally.&lt;/p&gt;

&lt;p&gt;Instead of checking token expiration inside every API call, we centralize the authentication logic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Request Interceptor&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before every request:&lt;/p&gt;

&lt;p&gt;Read the current Access Token&lt;br&gt;
Attach it to the Authorization header&lt;br&gt;
Authorization: Bearer accessToken&lt;/p&gt;

&lt;p&gt;No need to manually attach tokens every time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Response Interceptor&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When the backend returns 401 Unauthorized:&lt;/p&gt;

&lt;p&gt;Pause the failed request.&lt;br&gt;
Call the refresh endpoint.&lt;br&gt;
Receive a new Access Token.&lt;br&gt;
Update the stored token.&lt;br&gt;
Retry the original request.&lt;/p&gt;

&lt;p&gt;The user never notices that the Access Token expired.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where Does React Query Fit?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;React Query is responsible for:&lt;/p&gt;

&lt;p&gt;Server state&lt;br&gt;
Data fetching&lt;br&gt;
Caching&lt;br&gt;
Background refetching&lt;br&gt;
Automatic retries&lt;/p&gt;

&lt;p&gt;Authentication should not be mixed into every query.&lt;/p&gt;

&lt;p&gt;Instead, the architecture should look like this:&lt;/p&gt;

&lt;p&gt;React Query&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
Axios Instance&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
Axios Interceptors&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
Backend APIs&lt;/p&gt;

&lt;p&gt;React Query simply calls Axios.&lt;/p&gt;

&lt;p&gt;Axios automatically handles authentication.&lt;/p&gt;

&lt;p&gt;This separation keeps your application clean, reusable, and maintainable.&lt;/p&gt;

&lt;p&gt;Example Flow with React Query&lt;/p&gt;

&lt;p&gt;Suppose we're fetching a user's profile.&lt;/p&gt;

&lt;p&gt;useQuery()&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
Axios GET /profile&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
401 Unauthorized&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
Axios refreshes token&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
Retries request&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
Profile returned&lt;br&gt;
      │&lt;br&gt;
      ▼&lt;br&gt;
React Query updates cache&lt;/p&gt;

&lt;p&gt;Notice that React Query never needs to know about authentication.&lt;/p&gt;

&lt;p&gt;Everything happens transparently.&lt;/p&gt;

&lt;p&gt;Prevent Multiple Refresh Requests&lt;/p&gt;

&lt;p&gt;Imagine five API requests are sent simultaneously.&lt;/p&gt;

&lt;p&gt;If the Access Token expires, every request receives:&lt;/p&gt;

&lt;p&gt;401 Unauthorized&lt;/p&gt;

&lt;p&gt;Without proper handling:&lt;/p&gt;

&lt;p&gt;Refresh&lt;br&gt;
Refresh&lt;br&gt;
Refresh&lt;br&gt;
Refresh&lt;br&gt;
Refresh&lt;/p&gt;

&lt;p&gt;This creates:&lt;/p&gt;

&lt;p&gt;Duplicate refresh requests&lt;br&gt;
Race conditions&lt;br&gt;
Unnecessary server load&lt;br&gt;
Better Approach&lt;br&gt;
First request&lt;br&gt;
        │&lt;br&gt;
Starts refresh&lt;br&gt;
        │&lt;br&gt;
───────────────&lt;br&gt;
Other failed requests wait&lt;br&gt;
───────────────&lt;br&gt;
        │&lt;br&gt;
New Access Token received&lt;br&gt;
        │&lt;br&gt;
Retry all queued requests&lt;/p&gt;

&lt;p&gt;This queueing strategy is commonly used in enterprise applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Logout Flow&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Eventually, the Refresh Token also expires.&lt;/p&gt;

&lt;p&gt;When refreshing fails:&lt;/p&gt;

&lt;p&gt;401 Unauthorized&lt;br&gt;
        │&lt;br&gt;
        ▼&lt;br&gt;
Refresh Failed&lt;br&gt;
        │&lt;br&gt;
        ▼&lt;br&gt;
Clear user state&lt;br&gt;
        │&lt;br&gt;
        ▼&lt;br&gt;
Redirect to Login&lt;/p&gt;

&lt;p&gt;This ensures invalid sessions are cleaned up properly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Best Practices&lt;/strong&gt;&lt;br&gt;
✅ Keep Access Tokens short-lived (5–15 minutes)&lt;br&gt;
✅ Store Refresh Tokens inside HttpOnly Secure Cookies&lt;br&gt;
✅ Store Access Tokens in memory whenever possible&lt;br&gt;
✅ Use Axios Interceptors for automatic token refresh&lt;br&gt;
✅ Keep authentication logic outside React Query&lt;br&gt;
✅ Retry the original request after refreshing the token&lt;br&gt;
✅ Queue failed requests during refresh to prevent duplicate refresh calls&lt;br&gt;
✅ Clear authentication state when refresh fails&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Architecture Overview&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;React Components&lt;br&gt;
        │&lt;br&gt;
        ▼&lt;br&gt;
React Query&lt;br&gt;
        │&lt;br&gt;
        ▼&lt;br&gt;
Axios Instance&lt;br&gt;
        │&lt;br&gt;
        ▼&lt;br&gt;
Request Interceptor&lt;br&gt;
        │&lt;br&gt;
        ▼&lt;br&gt;
Protected API&lt;br&gt;
        │&lt;br&gt;
   401 Unauthorized&lt;br&gt;
        │&lt;br&gt;
        ▼&lt;br&gt;
Response Interceptor&lt;br&gt;
        │&lt;br&gt;
        ▼&lt;br&gt;
Refresh Endpoint&lt;br&gt;
        │&lt;br&gt;
        ▼&lt;br&gt;
New Access Token&lt;br&gt;
        │&lt;br&gt;
        ▼&lt;br&gt;
Retry Original Request&lt;br&gt;
Conclusion&lt;/p&gt;

&lt;p&gt;Using Access Tokens and Refresh Tokens is the industry standard for building secure authentication systems.&lt;/p&gt;

&lt;p&gt;By combining Axios Interceptors with React Query, you can create a seamless authentication experience where expired tokens are refreshed automatically without interrupting the user.&lt;/p&gt;

&lt;p&gt;Keeping authentication inside the Axios layer also makes your React Query hooks simple, reusable, and focused only on fetching data.&lt;/p&gt;

&lt;p&gt;🎥 Video Tutorial&lt;/p&gt;

&lt;p&gt;If you prefer learning through video, check out the complete guide:&lt;/p&gt;

&lt;p&gt;How to Automatically Refresh JWT Tokens in React&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=ntr2CCoeP8o&amp;amp;t=71s" rel="noopener noreferrer"&gt;https://www.youtube.com/watch?v=ntr2CCoeP8o&amp;amp;t=71s&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you found this article helpful, consider leaving a ❤️, sharing it with other developers, and following me for more React, TypeScript, and full-stack development content.&lt;/p&gt;

</description>
      <category>react</category>
      <category>authentication</category>
      <category>jwt</category>
      <category>axios</category>
    </item>
    <item>
      <title>🚀 Build a Production-Ready E-Commerce Application with React &amp; Modern Frontend Technologies - 2026</title>
      <dc:creator>codeek</dc:creator>
      <pubDate>Sat, 13 Jun 2026 09:58:00 +0000</pubDate>
      <link>https://dev.to/codeek/build-a-production-ready-e-commerce-application-with-react-modern-frontend-technologies-1im0</link>
      <guid>https://dev.to/codeek/build-a-production-ready-e-commerce-application-with-react-modern-frontend-technologies-1im0</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzmihh20h2yxuq18h91rs.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%2Fzmihh20h2yxuq18h91rs.png" alt="Ecommerce in React with modern tech stacks - 2026" width="800" height="482"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Want to learn how modern e-commerce applications are built in real-world companies?&lt;/p&gt;

&lt;p&gt;In this comprehensive project-based series, we'll build a complete online store from scratch using React and industry-standard tools used by professional frontend developers.&lt;/p&gt;

&lt;p&gt;Here is a link to a playlist freely uploaded in Youtube:&lt;br&gt;
&lt;a href="https://www.youtube.com/playlist?list=PL_02r0p8Ku_6tR8L-n-yj7MW8rrMtswwk" rel="noopener noreferrer"&gt;Youtube playlist&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🎯 What You'll Build&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;✅ Advanced Product Listing Page&lt;/p&gt;

&lt;p&gt;✅ Search, Filtering, Sorting &amp;amp; Pagination&lt;/p&gt;

&lt;p&gt;✅ Product Details &amp;amp; Related Products&lt;/p&gt;

&lt;p&gt;✅ Shopping Cart with Persistent State&lt;/p&gt;

&lt;p&gt;✅ Secure Stripe Payment Integration&lt;/p&gt;

&lt;p&gt;✅ Responsive Mobile-First UI&lt;/p&gt;

&lt;p&gt;✅ Dynamic Loading &amp;amp; Error States&lt;/p&gt;

&lt;p&gt;✅ Reusable Component Architecture&lt;/p&gt;

&lt;p&gt;✅ API Integration &amp;amp; Server State Management&lt;/p&gt;

&lt;p&gt;✅ Modern Animations &amp;amp; Interactive Effects&lt;/p&gt;

&lt;p&gt;✅ Hero Sliders &amp;amp; Product Carousels&lt;/p&gt;

&lt;p&gt;✅ Performance Optimization Techniques&lt;/p&gt;

&lt;p&gt;✅ Production-Ready Folder Structure&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🛠️ Technologies You'll Learn&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;⚛️ React&lt;/p&gt;

&lt;p&gt;🐻 Zustand for Global State Management&lt;/p&gt;

&lt;p&gt;🔄 React Query (TanStack Query) for Server State &amp;amp; Caching&lt;/p&gt;

&lt;p&gt;📡 Axios for API Communication&lt;/p&gt;

&lt;p&gt;💳 Stripe for Payment Processing&lt;/p&gt;

&lt;p&gt;🎨 Chakra UI for Accessible UI Components&lt;/p&gt;

&lt;p&gt;🧭 React Router for Client-Side Routing&lt;/p&gt;

&lt;p&gt;🎠 Swiper.js for Modern Sliders&lt;/p&gt;

&lt;p&gt;✨ Tilt Parallax for Interactive Animations&lt;/p&gt;

&lt;p&gt;🟨 JavaScript&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;💡 Why Build This Project?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Most tutorials teach you isolated concepts.&lt;/p&gt;

&lt;p&gt;This series focuses on building a complete real-world application while applying best practices used in professional development teams.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You'll learn:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;✅ Scalable frontend architecture&lt;br&gt;
✅ State management patterns&lt;br&gt;
✅ Efficient data fetching strategies&lt;br&gt;
✅ Payment gateway integration&lt;br&gt;
✅ Component reusability&lt;br&gt;
✅ Performance optimization&lt;br&gt;
✅ Responsive design principles&lt;br&gt;
✅ Production-ready coding practices&lt;/p&gt;

&lt;p&gt;By the end of this series, you'll have a portfolio-worthy project that demonstrates the skills companies expect from modern React developers.&lt;/p&gt;

&lt;p&gt;Whether you're a beginner building your first serious project or an experienced developer looking to strengthen your React fundamentals, this series will help you gain practical experience by building something real.&lt;/p&gt;

&lt;p&gt;🔥 Build. Learn. Deploy. Get Job-Ready.&lt;/p&gt;

&lt;p&gt;Follow along and let's create a modern e-commerce application from scratch.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>🚀 Build a Production-Ready E-Commerce Application with React &amp; Modern Frontend Technologies</title>
      <dc:creator>codeek</dc:creator>
      <pubDate>Sat, 13 Jun 2026 09:58:00 +0000</pubDate>
      <link>https://dev.to/codeek/build-a-production-ready-e-commerce-application-with-react-modern-frontend-technologies-2l4l</link>
      <guid>https://dev.to/codeek/build-a-production-ready-e-commerce-application-with-react-modern-frontend-technologies-2l4l</guid>
      <description>&lt;p&gt;Want to learn how modern e-commerce applications are built in real-world companies?&lt;/p&gt;

&lt;p&gt;In this comprehensive project-based series, we'll build a complete online store from scratch using React and industry-standard tools used by professional frontend developers.&lt;/p&gt;

&lt;p&gt;Here is a link to a playlist freely uploaded in Youtube:&lt;br&gt;
&lt;a href="https://youtu.be/NWPLHEpaHGc" rel="noopener noreferrer"&gt;Youtube playlist&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🎯 What You'll Build&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;✅ Advanced Product Listing Page&lt;/p&gt;

&lt;p&gt;✅ Search, Filtering, Sorting &amp;amp; Pagination&lt;/p&gt;

&lt;p&gt;✅ Product Details &amp;amp; Related Products&lt;/p&gt;

&lt;p&gt;✅ Shopping Cart with Persistent State&lt;/p&gt;

&lt;p&gt;✅ Secure Stripe Payment Integration&lt;/p&gt;

&lt;p&gt;✅ Responsive Mobile-First UI&lt;/p&gt;

&lt;p&gt;✅ Dynamic Loading &amp;amp; Error States&lt;/p&gt;

&lt;p&gt;✅ Reusable Component Architecture&lt;/p&gt;

&lt;p&gt;✅ API Integration &amp;amp; Server State Management&lt;/p&gt;

&lt;p&gt;✅ Modern Animations &amp;amp; Interactive Effects&lt;/p&gt;

&lt;p&gt;✅ Hero Sliders &amp;amp; Product Carousels&lt;/p&gt;

&lt;p&gt;✅ Performance Optimization Techniques&lt;/p&gt;

&lt;p&gt;✅ Production-Ready Folder Structure&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🛠️ Technologies You'll Learn&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;⚛️ React&lt;/p&gt;

&lt;p&gt;🐻 Zustand for Global State Management&lt;/p&gt;

&lt;p&gt;🔄 React Query (TanStack Query) for Server State &amp;amp; Caching&lt;/p&gt;

&lt;p&gt;📡 Axios for API Communication&lt;/p&gt;

&lt;p&gt;💳 Stripe for Payment Processing&lt;/p&gt;

&lt;p&gt;🎨 Chakra UI for Accessible UI Components&lt;/p&gt;

&lt;p&gt;🧭 React Router for Client-Side Routing&lt;/p&gt;

&lt;p&gt;🎠 Swiper.js for Modern Sliders&lt;/p&gt;

&lt;p&gt;✨ Tilt Parallax for Interactive Animations&lt;/p&gt;

&lt;p&gt;🟨 JavaScript&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;💡 Why Build This Project?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Most tutorials teach you isolated concepts.&lt;/p&gt;

&lt;p&gt;This series focuses on building a complete real-world application while applying best practices used in professional development teams.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You'll learn:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Scalable frontend architecture&lt;br&gt;
State management patterns&lt;br&gt;
Efficient data fetching strategies&lt;br&gt;
Payment gateway integration&lt;br&gt;
Component reusability&lt;br&gt;
Performance optimization&lt;br&gt;
Responsive design principles&lt;br&gt;
Production-ready coding practices&lt;/p&gt;

&lt;p&gt;By the end of this series, you'll have a portfolio-worthy project that demonstrates the skills companies expect from modern React developers.&lt;/p&gt;

&lt;p&gt;Whether you're a beginner building your first serious project or an experienced developer looking to strengthen your React fundamentals, this series will help you gain practical experience by building something real.&lt;/p&gt;

&lt;p&gt;🔥 Build. Learn. Deploy. Get Job-Ready.&lt;/p&gt;

&lt;p&gt;Follow along and let's create a modern e-commerce application from scratch.&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>react</category>
      <category>tutorial</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Build Live stream or video call app in React.js in few minutes</title>
      <dc:creator>codeek</dc:creator>
      <pubDate>Fri, 12 Dec 2025 17:04:53 +0000</pubDate>
      <link>https://dev.to/codeek/integrating-realtime-zegocloud-sdk-in-reactjs-19ml</link>
      <guid>https://dev.to/codeek/integrating-realtime-zegocloud-sdk-in-reactjs-19ml</guid>
      <description>&lt;h3&gt;
  
  
  Build a Live stream app in React with Zegocloud 🚀
&lt;/h3&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%2Fuum5c24krs80039iwcm4.webp" 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%2Fuum5c24krs80039iwcm4.webp" alt="Built live streaming and video call website or application using react and zegocloud" width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
If your preference is video, here is a &lt;a href="https://www.youtube.com/watch?v=AR8qMrnvsNs" rel="noopener noreferrer"&gt;video source&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Video calling and live streaming have become must-have features in today's applications, and &lt;strong&gt;ZEGOCLOUD API&lt;/strong&gt; simplifies the integration process remarkably. You can implement &lt;em&gt;complete live streaming functionality, create separate rooms, add in-app chat&lt;/em&gt;, and more with minimal code.&lt;br&gt;
  What makes ZEGOCLOUD particularly attractive is their generous offer: every new account receives &lt;em&gt;10,000 free minutes&lt;/em&gt;, perfect for testing or launching a basic version of your application.&lt;/p&gt;

&lt;p&gt;This guide walks you through creating a live streaming app, step by step — simply follow the instructions and use the code snippets provided here or from ZEGOCLOUD's official documentation.&lt;br&gt;
&lt;a href="//www.zegocloud.com"&gt;Zegocloud&lt;/a&gt;&lt;br&gt;
The flexibility doesn't end with React. ZEGOCLOUD supports multiple modern frameworks including &lt;strong&gt;Nextjs&lt;/strong&gt;, &lt;strong&gt;Angular&lt;/strong&gt;, &lt;strong&gt;Vue&lt;/strong&gt; and also with &lt;strong&gt;Wordpress&lt;/strong&gt; and &lt;strong&gt;HTML&lt;/strong&gt; with framework or code examples available for each. &lt;br&gt;
By following this tutorial, we'll have a fully operational live streaming application in React. Let's dive in! 🚀&lt;/p&gt;
&lt;h2&gt;
  
  
  Project Setup And Prerequisites
&lt;/h2&gt;

&lt;p&gt;Let's make sure we have everything we need before we start:&lt;/p&gt;

&lt;p&gt;1️⃣ Node.js &lt;br&gt;
Make sure &lt;strong&gt;Node.js&lt;/strong&gt; is installed on our machine. If it's not already installed.&lt;/p&gt;

&lt;p&gt;Download and install from the official site:&lt;br&gt;
&lt;a href="https://nodejs.org" rel="noopener noreferrer"&gt;nodejs&lt;/a&gt;&lt;br&gt;
Choose &lt;strong&gt;LTS&lt;/strong&gt; version. &lt;/p&gt;

&lt;p&gt;This installs:&lt;br&gt;
&lt;em&gt;node&lt;br&gt;
npm&lt;br&gt;
npx&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To check if Node.js is installed or needs an update, we need to run the script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node -v  # Check installed version
npm update nodejs  # Update Node.js if needed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Setting up React with Vite
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;First of all, lets create an empty folder with any name, lets say &lt;strong&gt;live-stream-app-react&lt;/strong&gt; and open in your editor like Visual studio Code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Lets now open terminal and run the script&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm create vite@latest .

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

&lt;/div&gt;



&lt;p&gt;We then need to give package name in the prompt, any name you prefer and choose React from the second prompt and then Javascript/Typescript from the third prompt.&lt;br&gt;
This will install all the required packages and dependencies in your folder, &lt;strong&gt;live-stream-app-react&lt;/strong&gt; in our case.&lt;/p&gt;
&lt;h2&gt;
  
  
  Lets sign up for a ZEGOCLOUD Account for free
&lt;/h2&gt;

&lt;p&gt;To use ZEGOCLOUD SDK, we need to sign up for a free account and get our App ID and App Sign here:&lt;br&gt;
&lt;a href="https://console.zegocloud.com/account/signup" rel="noopener noreferrer"&gt;🔗 Sign Up on ZEGOCLOUD&lt;br&gt;
&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After signing up, we will receive 10,000 free minutes to test and deploy our live streaming application.&lt;/p&gt;
&lt;h2&gt;
  
  
  Let’s Start: Building a live streaming App with ZEGOCLOUD in React
&lt;/h2&gt;

&lt;p&gt;Now that we have everything set up, let’s start integrating ZEGOCLOUD into our React project step by step.&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 1: Install the ZEGOCLOUD SDK
&lt;/h3&gt;

&lt;p&gt;To integrate ZEGOCLOUD into your React project, we will need to install the &lt;strong&gt;SDK&lt;/strong&gt; using the following script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install @zegocloud/zego-uikit-prebuilt

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 2: Get our AppID and ServerSecret
&lt;/h2&gt;

&lt;p&gt;Lets now log in to ZEGOCLOUD and navigate to the developer console to obtain our AppID and ServerSecret which we need to use in our project code later to initialize SDK.&lt;/p&gt;

&lt;p&gt;⚠️ Important: Lets keep our AppID and ServerSecret private! We need to consider we never share it with anyone or exposing it to others.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Initialize the SDK in React
&lt;/h2&gt;

&lt;p&gt;Now, modify your App.jsx/App.tsx file to initialize the ZEGOCLOUD SDK and create a function to start live streaming component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import * as React from "react";
import { ZegoUIKitPrebuilt } from "@zegocloud/zego-uikit-prebuilt";

function randomID(len) {
  let result = "";
  if (result) return result;
  var chars = "12345qwertyuiopasdfgh67890jklmnbvcxzMNBVCZXASDQWERTYHGFUIOLKJP",
    maxPos = chars.length,
    i;
  len = len || 5;
  for (i = 0; i &amp;lt; len; i++) {
    result += chars.charAt(Math.floor(Math.random() * maxPos));
  }
  return result;
}

export function getUrlParams(url = window.location.href) {
  let urlStr = url.split("?")[1];
  return new URLSearchParams(urlStr);
}

export default function App() {
  const roomID = getUrlParams().get("roomID") || randomID(5);
  let role_str = getUrlParams(window.location.href).get("role") || "Host";
  const role =
    role_str === "Host"
      ? ZegoUIKitPrebuilt.Host
      : role_str === "Cohost"
      ? ZegoUIKitPrebuilt.Cohost
      : ZegoUIKitPrebuilt.Audience;

  let sharedLinks = [];
  if (role === ZegoUIKitPrebuilt.Host || role === ZegoUIKitPrebuilt.Cohost) {
    sharedLinks.push({
      name: "Join as co-host",
      url:
        window.location.protocol +
        "//" +
        window.location.host +
        window.location.pathname +
        "?roomID=" +
        roomID +
        "&amp;amp;role=Cohost",
    });
  }
  sharedLinks.push({
    name: "Join as audience",
    url:
      window.location.protocol +
      "//" +
      window.location.host +
      window.location.pathname +
      "?roomID=" +
      roomID +
      "&amp;amp;role=Audience",
  });
  // generate Kit Token
  const appID = your_app_id;
  const serverSecret = "your_app_secret";
  const kitToken = ZegoUIKitPrebuilt.generateKitTokenForTest(
    appID,
    serverSecret,
    roomID,
    randomID(5),
    randomID(5)
  );

  // start the call
  let myMeeting = async (element) =&amp;gt; {
    // Create instance object from Kit Token.
    const zp = ZegoUIKitPrebuilt.create(kitToken);
    // start the call
    zp.joinRoom({
      container: element,
      scenario: {
        mode: ZegoUIKitPrebuilt.LiveStreaming,
        config: {
          role,
        },
      },
      sharedLinks,
    });
  };

  return (
    &amp;lt;div
      className="myCallContainer"
      ref={myMeeting}
      style={{ width: "100vw", height: "100vh" }}
    &amp;gt;&amp;lt;/div&amp;gt;
  );
}

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 4: Add our AppID and ServerSecret
&lt;/h2&gt;

&lt;p&gt;Now, we need to add our &lt;strong&gt;AppID&lt;/strong&gt; and &lt;strong&gt;ServerSecret&lt;/strong&gt; here in this codeblock of above code in App.jsx/App.tsx:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// generate Kit Token
  const appID = your_app_id;
  const serverSecret = "your_app_secret";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 5: Run the App
&lt;/h2&gt;

&lt;p&gt;Now, lets start our project by running the script:&lt;br&gt;
&lt;/p&gt;

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

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

&lt;/div&gt;



&lt;p&gt;Our live streaming app is now up and running! 🎉&lt;/p&gt;

&lt;p&gt;🎬 Want a Video Tutorial?&lt;br&gt;
If you prefer watching a video instead of reading, check out my tutorial on YouTube where I explain the entire process step by step! 🎥&lt;br&gt;
&lt;a href="https://www.youtube.com/watch?v=AR8qMrnvsNs" rel="noopener noreferrer"&gt;Youtube video&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And before leaving, we can also connect in github:&lt;br&gt;
&lt;a href="https://github.com/abhishek61067" rel="noopener noreferrer"&gt;My github&lt;/a&gt;&lt;/p&gt;

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

&lt;p&gt;Hurray! 🎉 We have successfully built a fully functional live streaming app using React and ZEGOCLOUD. &lt;/p&gt;

&lt;p&gt;I will be coming back with other tutorials regarding Nextjs, Reactjs and so many other things about Frontend and web development. Until then, have a good time my friends.&lt;/p&gt;

&lt;p&gt;Warm Regards,&lt;br&gt;
Codeek&lt;/p&gt;

</description>
      <category>react</category>
      <category>webdev</category>
      <category>zegocloud</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
