Client Components rendering#
Client Components, on the other hand, are crucial for creating interactive and dynamic user interfaces. On initial page load, Client Components are rendered statically on the server as part of the initial HTML, providing a fast, non-interactive preview. Once the client-side JavaScript is fully loaded, these components become interactive. Client Components also have access to browser APIs, like geolocation
or localStorage
.
To create Client Components in Next.js, you need to specify a boundary between server and client code using the "use client"
directive. This directive should be placed at the top of the component file, above all imports.
Let's look at a real-life example of how to define a Client Component: