The backend is done (Chapter S2 14: Building Feed API and Pagination). Now you'll build what users see: a React app. This chapter sets up the frontend project with Vite, styles it with Tailwind CSS and DaisyUI, and adds page navigation with React Router, including the layout route pattern that keeps the navbar and footer on every page.
In this chapter you'll learn
- what Vite is, and how to create a React project with it
- Tailwind CSS (utility classes) and DaisyUI (ready-made components), and how to install the current versions
- client-side routing with React Router:
BrowserRouter,Routes,Route - nested routes and
<Outlet />for a shared layout - a
NavBarand aFootercomponent
Before you start: basic React (components, JSX, props, useState). Code: DevTinder frontend repository.
Why a separate frontend app?
DevTinder has two applications (Chapter S2 01: Microservices vs Monolith - How to build a project):
- the backend API (Express + MongoDB) you've built, on
localhost:3000 - the frontend (React), which runs in the browser and calls the API, on
localhost:5173during development
They live in separate repositories and are deployed separately (Chapter S3 01: Lanching an AWS Instance and Deploying frontend).
Step 1: Create the project with Vite
Vite is a build tool and dev server for frontend projects. It starts in milliseconds and updates the page instantly when you save a file (Hot Module Replacement). It replaced Create React App, which is no longer maintained.
npm create vite@latest devTinder-web -- --template react
cd devTinder-web
npm install
npm run dev # opens on http://localhost:5173npm create vite@latest devTinder-web -- --template react
cd devTinder-web
npm install
npm run dev # opens on http://localhost:5173The files that matter:
| File | Purpose |
|---|---|
index.html | the single HTML page; React renders into its <div id="root"> |
src/main.jsx | entry point: mounts <App /> into #root |
src/App.jsx | your root component |
src/index.css | global styles |
vite.config.js | Vite configuration (plugins) |
Clean up the starter: delete the demo content from App.jsx and empty App.css/index.css, so you start from a blank page.
Step 2: Tailwind CSS and DaisyUI
What they are
- Tailwind CSS is a utility-first CSS framework. Instead of writing CSS files, you combine small classes directly in JSX:
className="p-4 text-xl font-bold bg-gray-800". - DaisyUI is a component library built on Tailwind. It adds ready-made class names for common components (
btn,navbar,card,dropdown,toast...) and themes, so you don't style every button from scratch.
Install the current versions (Tailwind 4 + DaisyUI 5)
npm install tailwindcss @tailwindcss/vite daisyuinpm install tailwindcss @tailwindcss/vite daisyui// vite.config.js
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import tailwindcss from "@tailwindcss/vite";
export default defineConfig({
plugins: [react(), tailwindcss()],
});// vite.config.js
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import tailwindcss from "@tailwindcss/vite";
export default defineConfig({
plugins: [react(), tailwindcss()],
});/* src/index.css */
@import "tailwindcss";
@plugin "daisyui";/* src/index.css */
@import "tailwindcss";
@plugin "daisyui";That's all. Tailwind 4 needs no tailwind.config.js file for this setup; configuration lives in CSS. We built a test app with exactly these files (Vite 8, React 19, Tailwind 4.3, DaisyUI 5.8), and the DaisyUI classes compiled correctly.
The lectures use Tailwind 3, and versions must match. DaisyUI 5 requires Tailwind 4 (it's set up with @plugin "daisyui"; in CSS). DaisyUI 4 works with Tailwind 3 (set up in tailwind.config.js under plugins: [require("daisyui")]). Installing the newest DaisyUI into a Tailwind 3 project, or the other way round, gives you unstyled components. Either follow the Tailwind 4 setup above, or to match the lectures exactly install npm install -D tailwindcss@3 daisyui@4 and follow the Tailwind 3 guide.
Test it with a DaisyUI button:
<button className="btn btn-primary">It works!</button><button className="btn btn-primary">It works!</button>Step 3: The NavBar component
Copy a navbar from the DaisyUI docs and adapt it:
// src/components/NavBar.jsx
import { Link } from "react-router-dom";
const NavBar = () => {
return (
<div className="navbar bg-base-300 shadow-sm">
<div className="flex-1">
<Link to="/" className="btn btn-ghost text-xl">👩💻 DevTinder</Link>
</div>
<div className="flex-none gap-2">
<div className="dropdown dropdown-end mx-5">
<div tabIndex={0} role="button" className="btn btn-ghost btn-circle avatar">
<div className="w-10 rounded-full">
<img alt="user photo" src="https://geographyandyou.com/images/user-profile.png" />
</div>
</div>
<ul tabIndex={0} className="menu menu-sm dropdown-content bg-base-100 rounded-box z-10 mt-3 w-52 p-2 shadow">
<li><Link to="/profile">Profile</Link></li>
<li><Link to="/connections">Connections</Link></li>
<li><a>Logout</a></li>
</ul>
</div>
</div>
</div>
);
};
export default NavBar;// src/components/NavBar.jsx
import { Link } from "react-router-dom";
const NavBar = () => {
return (
<div className="navbar bg-base-300 shadow-sm">
<div className="flex-1">
<Link to="/" className="btn btn-ghost text-xl">👩💻 DevTinder</Link>
</div>
<div className="flex-none gap-2">
<div className="dropdown dropdown-end mx-5">
<div tabIndex={0} role="button" className="btn btn-ghost btn-circle avatar">
<div className="w-10 rounded-full">
<img alt="user photo" src="https://geographyandyou.com/images/user-profile.png" />
</div>
</div>
<ul tabIndex={0} className="menu menu-sm dropdown-content bg-base-100 rounded-box z-10 mt-3 w-52 p-2 shadow">
<li><Link to="/profile">Profile</Link></li>
<li><Link to="/connections">Connections</Link></li>
<li><a>Logout</a></li>
</ul>
</div>
</div>
</div>
);
};
export default NavBar;className, notclass: JSX attributes follow JavaScript names, andclassis a reserved word.<Link to="...">instead of<a href="...">: explained next.
Step 4: Routing with React Router
Client-side routing
A React app has only one HTML page (index.html). Client-side routing means that when you click a link, JavaScript swaps the components on screen and updates the URL, without asking the server for a new page. Navigation feels instant, and app state (like the logged-in user) survives.
This kind of app is called a SPA (Single-Page Application).
npm install react-router-domnpm install react-router-dom(This installs React Router 7 under its familiar package name. The course's BrowserRouter/Routes/Route/Outlet API works unchanged.)
<Link> vs <a>
<a href="/profile">makes the browser reload the whole page from the server: everything resets.<Link to="/profile">changes the URL in the browser and renders the new route: no reload.
Basic routes
// src/App.jsx
import { BrowserRouter, Routes, Route } from "react-router-dom";
function App() {
return (
<BrowserRouter basename="/">
<Routes>
<Route path="/" element={<div>Base Page</div>} />
<Route path="/login" element={<div>Login Page</div>} />
<Route path="/profile" element={<div>Profile Page</div>} />
</Routes>
</BrowserRouter>
);
}
export default App;// src/App.jsx
import { BrowserRouter, Routes, Route } from "react-router-dom";
function App() {
return (
<BrowserRouter basename="/">
<Routes>
<Route path="/" element={<div>Base Page</div>} />
<Route path="/login" element={<div>Login Page</div>} />
<Route path="/profile" element={<div>Profile Page</div>} />
</Routes>
</BrowserRouter>
);
}
export default App;| Component | Job |
|---|---|
<BrowserRouter> | connects React Router to the browser's address bar (History API). Wrap the app in it once |
<Routes> | looks at the current URL and renders the best matching <Route> |
<Route path element> | "for this path, render this element" |
basename="/" sets the base URL of the app. It matters only if the app is served from a sub-folder (like /app).
Step 5: Nested routes and <Outlet />
Every page should show the NavBar at the top and a Footer at the bottom, with only the middle changing. Copying <NavBar /> into every page would be repetitive. Instead, use a layout route:
// src/components/Body.jsx
import { Outlet } from "react-router-dom";
import NavBar from "./NavBar";
import Footer from "./Footer";
const Body = () => {
return (
<div>
<NavBar />
<Outlet /> {/* the matching CHILD route renders here */}
<Footer />
</div>
);
};
export default Body;// src/components/Body.jsx
import { Outlet } from "react-router-dom";
import NavBar from "./NavBar";
import Footer from "./Footer";
const Body = () => {
return (
<div>
<NavBar />
<Outlet /> {/* the matching CHILD route renders here */}
<Footer />
</div>
);
};
export default Body;// src/App.jsx
<BrowserRouter basename="/">
<Routes>
<Route path="/" element={<Body />}>
<Route path="/login" element={<Login />} />
<Route path="/profile" element={<Profile />} />
</Route>
</Routes>
</BrowserRouter>// src/App.jsx
<BrowserRouter basename="/">
<Routes>
<Route path="/" element={<Body />}>
<Route path="/login" element={<Login />} />
<Route path="/profile" element={<Profile />} />
</Route>
</Routes>
</BrowserRouter>- The parent route
/renders<Body />. - The child routes are nested inside it.
<Outlet />is a placeholder in the parent: React Router puts the matching child there. On/login, Body renders NavBar +<Login />+ Footer; on/profile, NavBar +<Profile />+ Footer.
Without <Outlet />, the child routes match but nothing appears, a common beginner bug.
The Footer
// src/components/Footer.jsx
const Footer = () => {
return (
<footer className="footer footer-center bg-base-300 text-base-content p-4 fixed bottom-0">
<aside>
<p>Copyright © {new Date().getFullYear()} - All rights reserved by DevTinder</p>
</aside>
</footer>
);
};
export default Footer;// src/components/Footer.jsx
const Footer = () => {
return (
<footer className="footer footer-center bg-base-300 text-base-content p-4 fixed bottom-0">
<aside>
<p>Copyright © {new Date().getFullYear()} - All rights reserved by DevTinder</p>
</aside>
</footer>
);
};
export default Footer;Suggested folder structure
src/
├── main.jsx
├── App.jsx ← routes
├── index.css ← Tailwind + DaisyUI
├── components/ ← Body, NavBar, Footer, Login, Feed, Profile, UserCard...
└── utils/ ← constants, Redux store and slices (next chapter)src/
├── main.jsx
├── App.jsx ← routes
├── index.css ← Tailwind + DaisyUI
├── components/ ← Body, NavBar, Footer, Login, Feed, Profile, UserCard...
└── utils/ ← constants, Redux store and slices (next chapter)Common mistakes
- Mismatched Tailwind/DaisyUI versions: components appear unstyled.
classinstead ofclassNamein JSX.<a href>for internal links: full page reloads wipe the app's state.- Nested routes without
<Outlet />: children never render. - Two
<BrowserRouter>s, or using<Link>outside of one: React Router throws an error.
Key takeaways
- Vite creates and serves the React app (
npm create vite@latest), with instant reloads. - Tailwind = utility classes; DaisyUI = ready-made components on top. Tailwind 4 pairs with DaisyUI 5 (
@import "tailwindcss"; @plugin "daisyui";); Tailwind 3 pairs with DaisyUI 4. - React Router does client-side routing:
BrowserRouter→Routes→Route. Use<Link>, not<a>. - A layout route (
Body) with<Outlet />keeps the NavBar and Footer on every page.
Interview questions
Q1. What is a Single-Page Application (SPA)?
A web app that loads one HTML page and then updates the content with JavaScript as the user navigates, instead of requesting a new page from the server each time. Navigation is fast and state is preserved, but SEO and first load need care, and the server must return index.html for every app route (Chapter S3 01: Lanching an AWS Instance and Deploying frontend).
Q2. What is client-side routing, and how does React Router do it?
Client-side routing maps URLs to components in the browser. React Router listens to URL changes through the History API (pushState), matches the current path against your <Route> definitions, and renders the matching element. <Link> updates the URL without a page reload.
Q3. What does <Outlet /> do?
It's the placeholder inside a parent (layout) route where React Router renders the matched child route. It lets several pages share a layout (navbar, sidebar, footer) while only the inner content changes.
Q4. What's the difference between <Link> and <a> in React?
<a href> triggers a full browser navigation: a new request, a page reload and reset app state. React Router's <Link to> intercepts the click, updates the URL with the History API and re-renders only what changed, keeping state.
Q5. What is Vite, and why use it instead of Create React App?
Vite is a frontend build tool and dev server. In development it serves source files as native ES modules, so it starts almost instantly and has very fast Hot Module Replacement; for production it creates an optimized bundle. Create React App was slow and is deprecated; Vite is the common default now.
Q6. What is utility-first CSS?
A styling approach where you compose small single-purpose classes (p-4, text-center, bg-blue-500) directly in markup instead of writing custom CSS rules per component. It speeds up development and keeps styles consistent; Tailwind CSS is the best-known example. Component libraries like DaisyUI add semantic classes (btn, card) on top.
What's next
The app has pages, but nobody can log in yet. In Chapter S2 16: DevTinder UI - Part 2 you'll build the login page, call the backend with axios, fix the CORS error you'll hit, and store the logged-in user in Redux.