Hello! Welcome to the final lesson of the entire "React.js: Basic to Advanced" course. Congratulations on making it this far.
In our last session, we mastered the production build process. You learned how to configure Vite to transform your development source code into a highly optimized, production-ready set of static files inside the dist directory.
Today, we take the final and most rewarding step: we will deploy that production-ready application to a static hosting platform, making it live on the internet for anyone to see. We will explore two of the most popular platforms in the modern web ecosystem: Vercel and Netlify. This lesson will bridge the gap between localhost and a live, shareable URL, completing the full development lifecycle.

1. What is Deployment?
So far, your application has only been running on your local machine using npm run dev. Deployment is the process of taking the static assets generated by npm run build and placing them on a web server that is accessible via the internet.
Deploying React Apps with Vercel: Step-by-Step
The article 'Deploying React Apps with Vercel' provides an excellent explanation of what deployment means in the context of a modern JavaScript application and why the build step is necessary. Let's start with a quick review to set the stage.
Please read the first three sections: 'What Is “Deployment”?', 'Why Can’t We Just Upload the React Files?', and 'What Does npm run build Do?'. This will serve as a concise refresher of concepts from our previous lesson.
As the article reiterates, we cannot just upload our /src folder. Browsers don't understand JSX or TypeScript. The build process you learned about in the last lesson is what creates the browser-ready HTML, CSS, and JavaScript files in the dist folder.
It is the contents of this dist folder that we deploy.
There are two primary methods for deployment:
- Manual Deployment: You run
npm run buildlocally and then drag-and-drop the resultingdistfolder into the provider's web interface. This is quick and simple for a one-time deployment. - Git-Based Deployment (CI/CD): You connect your GitHub (or other Git provider) repository to the hosting platform. Every time you
git pushto your main branch, the platform automatically pulls the code, runs the build command for you in the cloud, and deploys the new version. This is the standard professional workflow, often referred to as Continuous Integration/Continuous Deployment (CI/CD).
We will explore both methods.
2. Deploying to Netlify
Netlify is a powerful platform that excels at hosting static sites and serverless functions. It's known for its simplicity and robust free tier.
Method 1: Manual "Drag-and-Drop" Deployment
This is the fastest way to get your site online.
How To Deploy React App FREE [on Netlify]
The video 'How To Deploy React App FREE [on Netlify]' provides a very clear and concise walkthrough of the manual deployment process.
Watch from 00:25 to 00:46 to see the npm run build step, then from 01:28 to 04:17. This will guide you through signing up, dragging the dist folder into the Netlify UI, and changing the default site name to something more memorable. You can follow along with your own project.
To summarize the steps:
- Run
npm run buildin your project's terminal to generate thedistfolder. - Sign up for a Netlify account (you can use your GitHub account for convenience).
- On your Netlify dashboard, find the "Add new site" section and choose "Deploy manually".
- Drag your entire
distfolder onto the upload area. - Once deployed, Netlify will give you a random URL (e.g.,
sparkling-biscuit-1234.netlify.app). You can change this in the site settings to a custom subdomain of your choice.
Handling Client-Side Routing in SPAs
If your application uses React Router, you will immediately notice a problem. Navigating within the app works, but if you refresh the page on a route like /about, you'll get a 404 "Page Not Found" error.
This happens because the browser sends a request to the server for the /about path. Since this is a Single Page Application (SPA), the file /about/index.html doesn't actually exist on the server; all routing is handled by JavaScript on the client side.
We need to tell Netlify: "For any path that you can't find, just serve the index.html file, and let React Router handle the rest."
You can do this by creating a simple file in your public directory named _redirects (note: no file extension).
Add this single line to the _redirects file:
/* /index.html 200
This rule tells Netlify to redirect all paths (/*) to index.html with a 200 status code. Since files in the public directory are copied directly to the dist folder during the build, this configuration will be included in your next deployment. After adding this file, rebuild and redeploy.
Method 2: Git-Based Deployment with Netlify CLI
While manual deployment is easy, the professional approach is to automate it.
Netlify's official documentation for Vite provides the authoritative guide for setting up a Git-based deployment.
Read the sections 'Netlify integration' and 'Deploy a Vite site on Netlify'. These sections explain how Netlify automatically detects your Vite project settings and how to use the Netlify CLI to link your repository for continuous deployment.
Here is the workflow:
- Ensure your project is a Git repository and has been pushed to GitHub.
- Install the Netlify CLI globally:
npm install netlify-cli -g. - In your project's root directory, run
netlify init. - The CLI will guide you through logging in, connecting to your GitHub repo, and creating a new site.
- It will automatically detect that you're using Vite and suggest the correct build command (
npm run build) and publish directory (dist). Confirm these settings.
Once linked, any time you git push to your main branch, Netlify will automatically build and deploy your site.
3. Deploying to Vercel
Vercel is another top-tier platform for static and hybrid applications, developed by the team behind the Next.js framework. Its workflow is heavily optimized for Git-based deployment from the ground up.
Deploying React Apps with Vercel: Step-by-Step
The 'Deploying React Apps with Vercel' guide provides a comprehensive step-by-step walkthrough of this exact process. We will follow it closely.
Please read from the section 'Prerequisites: Before You Start' through 'Auto Updates on Every Git Push'. This will guide you through pushing your code to GitHub, creating a Vercel account, importing the project, and deploying. Also, pay close attention to the 'Add Env Variables in Vercel' and 'Common Beginner Mistakes and Fixes' sections.
The Vercel workflow is incredibly streamlined:
- Push to GitHub: Make sure your React project is on a GitHub repository.
- Sign Up for Vercel: Go to vercel.com and sign up using your GitHub account.
- Import Project: Click "Add New... > Project" and import your React project repository from the list.
- Configure and Deploy: Vercel automatically detects you are using Vite. It will pre-fill the Build Command (
vite build) and Output Directory (dist). You usually don't need to change anything. Click "Deploy".
Vercel will clone your repo, install dependencies, run the build, and deploy your site to a unique URL. Like Netlify, it automatically handles SPA redirects for you, so client-side routing works out of the box without any extra configuration.
Managing Environment Variables
A critical aspect of production deployment is handling secrets like API keys. As you know, .env files should be listed in .gitignore and never committed to your repository.
Both Vercel and Netlify provide a secure place in their project dashboards to manage these variables:
- In Vercel: Go to Project Settings > Environment Variables.
- In Netlify: Go to Site configuration > Build & deploy > Environment.
You add your variables (e.g., VITE_API_KEY) here. When the platform runs your build, it will inject these variables into the process, just as your local .env file does during development.
Test your understanding!
You've just finished a new feature that requires a new API key. You add VITE_NEW_API_KEY="secret123" to your local .env file, test it, and it works perfectly. You commit your code and push it to your main branch, which is connected to Vercel for automatic deployment.
The deployment finishes successfully, but the new feature is broken on the live site, with console errors indicating the API key is undefined. Why did this happen, and what two steps must you take to fix it?
Show answer
Reason: The deployment failed because the .env file is (correctly) not committed to your GitHub repository due to being listed in .gitignore. Therefore, when Vercel pulled your code, the new environment variable was missing during its build process.
Fix:
- Go to your project's dashboard on Vercel (or Netlify). Navigate to the "Environment Variables" section in the settings.
- Add a new variable with the name
VITE_NEW_API_KEYand the valuesecret123. - Trigger a new deployment. You can usually do this from the "Deployments" tab in the dashboard, or simply by making another small commit and pushing it to your main branch.
Conclusion and Course Wrap-Up
Congratulations! You have now completed the entire development lifecycle, from creating your first component to deploying a fully functional, production-ready application to the world.
Key Takeaways from this Lesson:
- Deployment is the process of making your locally-built application accessible on the internet.
- You always deploy the static output from your build process (the
distfolder), not your source code. - Platforms like Vercel and Netlify offer streamlined hosting for modern web applications, providing features like CDNs, SSL, and Continuous Deployment (CI/CD).
- The professional standard is Git-based deployment, where pushing to your repository automatically triggers a new build and deploy.
- For Single Page Applications (SPAs), you must configure your hosting provider to handle client-side routing by redirecting all requests to
index.html. - Environment variables must be securely configured in your hosting provider's dashboard, as
.envfiles are not part of your Git repository.
A Final Word on Your Journey
You have come a long way since Lesson 1. You started with the fundamentals of React and JSX, progressed through components, props, and state with useState. You tamed side effects with useEffect, built interactive forms, and managed complex state with useReducer and the Context API. You then dove into advanced concepts, optimizing performance with memoization, creating reusable logic with custom hooks, implementing client-side routing, and exploring advanced state management libraries. Finally, you learned to test your application, configure a production build, and send it out into the world.
Your foundation in computer science and proficiency with JavaScript and TypeScript have served you well, allowing you to not only learn the "how" but to understand the "why" behind React's architecture and the modern frontend toolchain.
You are now fully equipped to build, test, optimize, and deploy sophisticated, production-grade React applications. The journey of a developer is one of continuous learning. Keep building projects, explore the vast React ecosystem (like Next.js for server-side rendering or React Native for mobile), and continue to deepen your expertise.
Thank you for your dedication throughout this course. Happy coding