Implement React Server Components in Next.js
React Server Components (RSC) allow components to render on the server, reducing the amount of JavaScript sent to the client and improving initial load times. They are particularly useful for simplifying data fetching, as data can be retrieved on the server and passed directly to the component without needing a separate client-side API call.
import { getUserData } from "../lib/api";
export default async function UserProfile() {
// Data is fetched directly on the server
const user = await getUserData();
return (
<div>
<h1>{user.name}</h1>
<p>{user.email}</p>
</div>
);
}