Render content in the browser using JavaScript, supporting real-time data and high interactivity
This page is rendered in the browser, with data fetched via client-side API calls.
'use client'; // Must add this line!
import { useState, useEffect } from 'react';
export default function ProductList() {
const [data, setData] = useState([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
// Fetch data on the client
fetch('https://api.example.com/products')
.then(res => res.json())
.then(data => {
setData(data);
setLoading(false);
});
}, []);
if (loading) return <div>Loading...</div>;
return <div>{/* Render data */}</div>;
}2. Key Points:'use client' directive at the top of the fileuseState、useEffect and other Hookswindow、document and other browser APIs| Feature | CSR | SSG |
|---|---|---|
| Render Timing | Browser runtime | Build time |
| Data Freshness | Real-time fresh | Build-time data |
| Initial Load | Slower (JS + data) | Fastest (pure HTML) |
| SEO | Poor | Excellent |
| Use Cases | Dashboards, real-time data | Blogs, docs, product pages |
After completing the experiment, view the page source (right-click → View Page Source) and compare the HTML content differences between SSG and CSR to understand how they work.