0Pricing
Next.js 15 Fullstack (App Router + Server Actions) · Aula

Compreendendo RSC e RCC

Compreenda as principais diferenças e vantagens dos React Server Components (RSC) e React Client Components (RCC) no Next.js 15.

Compreendendo RSC e RCC é uma aula grátis de Next.js 15 Fullstack (App Router + Server Actions) no CoddyKit. Esta é a aula 1 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Next.js 15 Fullstack (App Router + Server Actions), e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Next.js 15 Fullstack (App Router + Server Actions) inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

Welcome to Next.js Components!

In Next.js 15, building user interfaces relies heavily on React components. But there's a new twist!

  • Traditionally, all React components run in the user's browser.
  • Next.js 15 introduces two main types: Server Components (RSC) and Client Components (RCC).
  • Understanding their differences is crucial for building fast, efficient, and interactive Next.js applications. Let's dive in!

What are Server Components (RSC)?

React Server Components (RSC) are components that run exclusively on the server, before any JavaScript is sent to the browser.

  • They generate HTML directly on the server.
  • This HTML is then sent to the client, along with any necessary client-side JavaScript for interactive parts.
  • RSCs are the default component type in the Next.js App Router.

RSC in Action: A Simple Header

Here's a basic component. Since there's no 'use client' directive and no interactive features (like state or event handlers), Next.js treats this as a Server Component by default.

It runs on the server, renders its HTML, and that's what the browser receives.

import React from 'react';

interface HeaderProps {
  title: string;
}

export default function Header({ title }: HeaderProps) {
  return (
    <header>
      <h1>{title}</h1>
      <p>Welcome to our page!</p>
    </header>
  );
}

Benefits of Server Components

RSCs offer significant advantages for performance and efficiency:

  • Zero Client JS: They don't add to the client-side JavaScript bundle, leading to faster page loads.
  • Direct Server Access: Can directly access server resources (like databases or file systems) without needing client-side API calls.
  • Improved SEO: Content is rendered on the server, making it easily crawlable by search engines.
  • Enhanced Security: Sensitive logic and data fetching stay on the server.

What are Client Components (RCC)?

React Client Components (RCC) are what you're likely familiar with – they run entirely in the user's browser, just like traditional React components.

  • They enable interactivity, client-side state management, and access to browser-specific APIs (like localStorage or navigator).
  • RCCs require JavaScript to be downloaded and executed in the browser.

RCC in Action: An Interactive Button

This component uses useState to manage a counter and an event handler to update it. Because it needs client-side interactivity, we mark it with 'use client'.

This directive tells Next.js to send this component's JavaScript to the browser for execution.

'use client';

import React, { useState } from 'react';

export default function CounterButton() {
  const [count, setCount] = useState(0);

  return (
    <button onClick={() => setCount(count + 1)}>
      Clicked {count} times
    </button>
  );
}

The 'use client' Directive

The 'use client' directive is a critical marker in Next.js:

  • It must be placed at the very top of a file, before any imports.
  • It signals to Next.js that this file, and any modules it imports, should be treated as part of the client bundle.
  • This directive acts as a 'boundary' – everything below it, including imported child components (unless explicitly marked as RSCs), will render on the client.

Key Differences at a Glance

Here's a quick comparison of RSCs and RCCs:

  • Execution: RSC (Server), RCC (Browser)
  • Interactivity: RSC (No), RCC (Yes, with hooks/events)
  • State/Effects: RSC (No), RCC (Yes, useState, useEffect)
  • Bundle Size: RSC (Adds zero client JS), RCC (Adds to client JS bundle)
  • Data Access: RSC (Direct server resources), RCC (Needs client-side fetching or props)
  • Directive: RSC (Default, no directive), RCC (Requires 'use client')

When to Use Which Component Type?

Choosing between RSC and RCC depends on your component's needs:

  • Use RSC for: Static content, initial data fetching (e.g., from a database), SEO-critical parts, components that don't need client-side interactivity.
  • Use RCC for: Interactive UI elements (buttons, forms), client-side state management, components requiring browser APIs (e.g., geolocation, local storage), animations.

Often, you'll compose RSCs and RCCs together for a powerful user experience!

Quick Check

Which of the following statements about React Server Components (RSC) and React Client Components (RCC) in Next.js 15 are TRUE?

Recap: RSC & RCC Fundamentals

You've learned the core differences between Server and Client Components in Next.js 15!

  • Server Components (RSC): Run on the server, generate HTML, reduce client JS, are the default.
  • Client Components (RCC): Run in the browser, enable interactivity and state, require the 'use client' directive.
  • Combining them allows you to build highly performant and dynamic web applications.

Next, we'll explore how to fetch data specifically within Server Components efficiently!

Perguntas Frequentes

A aula “Compreendendo RSC e RCC” é grátis?

Sim — o texto completo de “Compreendendo RSC e RCC” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Next.js 15 Fullstack (App Router + Server Actions), atualize para CoddyKit PRO. O curso de Next.js 15 Fullstack (App Router + Server Actions) inclui 4 aulas no total.

O que vou aprender em “Compreendendo RSC e RCC”?

Compreenda as principais diferenças e vantagens dos React Server Components (RSC) e React Client Components (RCC) no Next.js 15. Você pratica Next.js 15 Fullstack (App Router + Server Actions) com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Next.js 15 Fullstack (App Router + Server Actions)?

Nenhuma experiência prévia é necessária. Next.js 15 Fullstack (App Router + Server Actions) no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 1 de 4.

Quanto tempo leva a aula “Compreendendo RSC e RCC”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Next.js 15 Fullstack (App Router + Server Actions)?

Sim. Cada aula de Next.js 15 Fullstack (App Router + Server Actions) inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Compreendendo RSC e RCC
  2. Busca de dados em RSC
  3. Interatividade com RCC
  4. Padrões de Composição para Componentes de Servidor e de Cliente
← Voltar para Next.js 15 Fullstack (App Router + Server Actions)