EdgeOne Pages React Router Starter - CSR

Client-side rendering with data fetching in the browser.

Perfect for interactive applications where SEO is not critical and you want to minimize server load.

Loading data on the client...

import { useState, useEffect } from "react";

export default function CSRPage() {
  const [data, setData] = useState(null);
  const [loading, setLoading] = useState(true);

  useEffect(() => {
    // Data fetching happens on the client side
    const fetchData = async () => {
      setLoading(true);
      const response = await fetch('https://api.example.com/data');
      const jsonData = await response.json();
      setData(jsonData);
      setLoading(false);
    };

    fetchData();
  }, []); // Runs once when component mounts

  if (loading) {
    return <div>Loading...</div>;
  }

  return (
    <div>
      <h2>CSR: Client-Side Rendering</h2>
      <p>This page is rendered entirely on the client.</p>
      <p>Client Time: {new Date().toISOString()}</p>
      <p>Data: {JSON.stringify(data)}</p>
    </div>
  );
}