You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/reference/rsc/server-components.md
+41-42Lines changed: 41 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,37 +1,37 @@
1
1
---
2
-
title: Server Components
2
+
title: Componentes de Servidor
3
3
---
4
4
5
5
<RSC>
6
6
7
-
Server Components are for use in [React Server Components](/learn/start-a-new-react-project#bleeding-edge-react-frameworks).
7
+
Componentes de Servidor são para uso em [Componentes de Servidor React](/learn/start-a-new-react-project#bleeding-edge-react-frameworks).
8
8
9
9
</RSC>
10
10
11
11
<Intro>
12
12
13
-
Server Components are a new type of Component that renders ahead of time, before bundling, in an environment separate from your client app or SSR server.
13
+
Componentes de Servidor são um novo tipo de Componente que renderiza com antecedência, antes do bundling, em um ambiente separado do seu aplicativo cliente ou servidor SSR.
14
14
15
15
</Intro>
16
16
17
-
This separate environment is the "server" in React Server Components. Server Components can run once at build time on your CI server, or they can be run for each request using a web server.
17
+
Este ambiente separado é o "servidor" em Componentes de Servidor React. Componentes de Servidor podem rodar uma vez no tempo de build em seu servidor CI, ou eles podem ser executados para cada requisição usando um servidor web.
18
18
19
19
<InlineToc />
20
20
21
21
<Note>
22
22
23
-
#### How do I build support for Server Components? {/*how-do-i-build-support-for-server-components*/}
23
+
#### Como eu construo suporte para Componentes de Servidor? {/*how-do-i-build-support-for-server-components*/}
24
24
25
-
While React Server Components in React 19 are stable and will not break between minor versions, the underlying APIs used to implement a React Server Components bundler or framework do not follow semver and may break between minors in React 19.x.
25
+
Enquanto Componentes de Servidor React no React 19 são estáveis e não quebrarão entre versões minor, as APIs por baixo utilizadas para implementar um bundler ou framework de Componentes de Servidor React não seguem semver e podem quebrar entre minors no React 19.x.
26
26
27
-
To support React Server Components as a bundler or framework, we recommend pinning to a specific React version, or using the Canary release. We will continue working with bundlers and frameworks to stabilize the APIs used to implement React Server Components in the future.
27
+
Para dar suporte a Componentes de Servidor React como um bundler ou framework, nós recomendamos fixar em uma versão especifica do React, ou utilizar a versão Canary. Nós continuaremos trabalhando com bundlers e frameworks para estabilizar as APIs utilizadas para implementar Componentes de Servidor React no futuro.
28
28
29
29
</Note>
30
30
31
-
### Server Components without a Server {/*server-components-without-a-server*/}
32
-
Server components can run at build time to read from the filesystem or fetch static content, so a web server is not required. For example, you may want to read static data from a content management system.
31
+
### Componentes de Servidor sem um Servidor {/*server-components-without-a-server*/}
32
+
Componentes de Servidor podem executar em tempo de build para ler do sistema de arquivos ou buscar conteúdo estático, então um servidor web não é necessário. Por exemplo, você pode querer ler dados estáticos de um sistema de gerenciamento de conteúdo.
33
33
34
-
Without Server Components, it's common to fetch static data on the client with an Effect:
34
+
Sem Componentes de Servidor, é comum buscar dados estáticos no cliente com um Effect:
This pattern means users need to download and parse an additional 75K (gzipped) of libraries, and wait for a second request to fetch the data after the page loads, just to render static content that will not change for the lifetime of the page.
61
+
Este padrão significa que os usuários precisam baixar e analisar 75KB (gzipped) de bibliotecas adicionais, e esperar por uma segunda requisição para buscar os dados após a página carregar, apenas para renderizar conteúdo estático que não irá mudar durante o tempo de vida da página.
62
62
63
-
With Server Components, you can render these components once at build time:
63
+
Com Componentes de Servidor, você pode renderizar esses componentes uma vez em tempo de build:
64
64
65
65
```js
66
66
importmarkedfrom'marked'; // Not included in bundle
@@ -74,34 +74,34 @@ async function Page({page}) {
74
74
}
75
75
```
76
76
77
-
The rendered output can then be server-side rendered (SSR) to HTML and uploaded to a CDN. When the app loads, the client will not see the original `Page`component, or the expensive libraries for rendering the markdown. The client will only see the rendered output:
77
+
A saída renderizada pode então ser renderizada no lado do servidor (SSR) para HTML e carregada em uma CDN. Quando o app carrega, o cliente não verá o componente `Page`original, ou as bibliotecas caras para renderizar o markdown. O cliente irá apenas ver a saída renderizada:
78
78
79
79
```js
80
80
<div><!-- html for markdown --></div>
81
81
```
82
82
83
-
This means the content is visible during first page load, and the bundle does not include the expensive libraries needed to render the static content.
83
+
Isso significa que o conteúdo é visível durante o primeiro carregamento da página, e o bundle não inclui as bibliotecas custosas necessárias para renderizar o conteúdo estático.
84
84
85
85
<Note>
86
86
87
-
You may notice that the Server Component above is an async function:
87
+
Você pode notar que o Componente de Servidor acima é uma função assíncrona:
88
88
89
89
```js
90
90
asyncfunctionPage({page}) {
91
91
//...
92
92
}
93
93
```
94
94
95
-
Async Components are a new feature of Server Components that allow you to `await`in render.
95
+
Componentes Assíncronos são uma nova funcionalidade dos Componentes de Servidor que permitem que você use `await`no render.
96
96
97
-
See [Async components with Server Components](#async-components-with-server-components)below.
97
+
Veja [Componentes assíncronos com Componentes de Servidor](#async-components-with-server-components)abaixo.
98
98
99
99
</Note>
100
100
101
-
### Server Components with a Server {/*server-components-with-a-server*/}
102
-
Server Components can also run on a web server during a request for a page, letting you access your data layer without having to build an API. They are rendered before your application is bundled, and can pass data and JSX as props to Client Components.
101
+
### Componentes de Servidor com um Servidor {/*server-components-with-a-server*/}
102
+
Componentes de Servidor podem também executar em um servidor web durante uma requisição para uma página, permitindo que você acesse sua camada de dados sem ter que construir uma API. Eles são renderizados antes que sua aplicação seja empacotada e podem passar dados e JSX como props para Componentes Cliente.
103
103
104
-
Without Server Components, it's common to fetch dynamic data on the client in an Effect:
104
+
Sem Componentes de Servidor, é comum buscar dados dinâmicos no cliente em um Effect:
With Server Components, you can read the data and render it in the component:
153
+
Com Componentes de Servidor, você pode ler os dados e renderizá-los no componente:
154
154
155
155
```js
156
156
importdbfrom'./database';
@@ -174,7 +174,7 @@ async function Author({id}) {
174
174
}
175
175
```
176
176
177
-
The bundler then combines the data, rendered Server Components and dynamic Client Components into a bundle. Optionally, that bundle can then be server-side rendered (SSR) to create the initial HTML for the page. When the page loads, the browser does not see the original `Note`and`Author`components; only the rendered output is sent to the client:
177
+
O bundler então combina os dados, Componentes de Servidor renderizados e Componentes Cliente dinâmicos em um bundle. Opcionalmente, esse bundle pode então ser renderizado no lado do servidor (SSR) para criar o HTML inicial para a página. Quando a página carrega, o navegador não vê os componentes `Note`e`Author`originais; apenas a saída renderizada é enviada para o cliente:
178
178
179
179
```js
180
180
<div>
@@ -183,26 +183,25 @@ The bundler then combines the data, rendered Server Components and dynamic Clien
183
183
</div>
184
184
```
185
185
186
-
Server Components can be made dynamic by re-fetching them from a server, where they can access the data and render again. This new application architecture combines the simple “request/response” mental model of server-centric Multi-Page Apps with the seamless interactivity of client-centric Single-Page Apps, giving you the best of both worlds.
186
+
Componentes de Servidor podem ser feitos dinâmicos re-buscando-os de um servidor, onde eles podem acessar os dados e renderizar novamente. Essa nova arquitetura de aplicação combina o modelo mental simples de “requisição/resposta” de Apps Multi-Página server-centric com a interatividade contínua de Apps Single-Page client-centric, dando a você o melhor dos dois mundos.
187
187
188
-
### Adding interactivity to Server Components {/*adding-interactivity-to-server-components*/}
188
+
### Adicionando interatividade aos Componentes de Servidor {/*adding-interactivity-to-server-components*/}
189
189
190
-
Server Components are not sent to the browser, so they cannot use interactive APIs like `useState`. To add interactivity to Server Components, you can compose them with Client Component using the`"use client"` directive.
190
+
Componentes de Servidor não são enviados para o navegador, então eles não podem usar APIs interativas como `useState`. Para adicionar interatividade aos Componentes de Servidor, você pode compô-los com Componentes Cliente usando a diretiva`"use client"`.
191
191
192
192
<Note>
193
193
194
-
#### There is no directive for Server Components. {/*there-is-no-directive-for-server-components*/}
194
+
#### Não existe diretiva para Componentes de Servidor. {/*there-is-no-directive-for-server-components*/}
195
195
196
-
A common misunderstanding is that Server Components are denoted by `"use server"`, but there is no directive for Server Components. The `"use server"`directive is used for Server Functions.
196
+
Um mal-entendido comum é que Componentes de Servidor são denotados por `"use server"`, mas não existe diretiva para Componentes de Servidor. A diretiva `"use server"`é usada para Funções de Servidor.
197
197
198
-
For more info, see the docs for [Directives](/reference/rsc/directives).
198
+
Para mais informações, veja a documentação para [Diretivas](/reference/rsc/directives).
199
199
200
200
</Note>
201
201
202
-
203
-
In the following example, the `Notes` Server Component imports an `Expandable` Client Component that uses state to toggle its `expanded` state:
202
+
No exemplo a seguir, o Componente de Servidor `Notes` importa um Componente Cliente `Expandable` que usa state para alternar seu estado `expanded`:
204
203
```js
205
-
//Server Component
204
+
//Componente de Servidor
206
205
importExpandablefrom'./Expandable';
207
206
208
207
asyncfunctionNotes() {
@@ -219,7 +218,7 @@ async function Notes() {
219
218
}
220
219
```
221
220
```js
222
-
//Client Component
221
+
//Componente Cliente
223
222
"use client"
224
223
225
224
exportdefaultfunctionExpandable({children}) {
@@ -229,15 +228,15 @@ export default function Expandable({children}) {
229
228
<button
230
229
onClick={() =>setExpanded(!expanded)}
231
230
>
232
-
Toggle
231
+
Alternar
233
232
</button>
234
233
{expanded && children}
235
234
</div>
236
235
)
237
236
}
238
237
```
239
238
240
-
This works by first rendering `Notes`as a Server Component, and then instructing the bundler to create a bundle for the Client Component`Expandable`. In the browser, the Client Components will see output of the Server Components passed as props:
239
+
Isso funciona renderizando primeiro `Notes`como um Componente de Servidor, e então instruindo o bundler a criar um bundle para o Componente Cliente`Expandable`. No navegador, os Componentes Cliente verão a saída dos Componentes de Servidor passados como props:
241
240
242
241
```js
243
242
<head>
@@ -257,18 +256,18 @@ This works by first rendering `Notes` as a Server Component, and then instructin
257
256
</body>
258
257
```
259
258
260
-
### Async components with Server Components {/*async-components-with-server-components*/}
259
+
### Componentes assíncronos com Componentes de Servidor {/*async-components-with-server-components*/}
261
260
262
-
Server Components introduce a new way to write Components using async/await. When you`await`in an async component, React will suspend and wait for the promise to resolve before resuming rendering. This works across server/client boundaries with streaming support for Suspense.
261
+
Componentes de Servidor introduzem uma nova forma de escrever Componentes usando async/await. Quando você`await`em um componente assíncrono, React irá suspender e esperar pela promise ser resolvida antes de retomar a renderização. Isso funciona através de limites de servidor/cliente com suporte a streaming para Suspense.
263
262
264
-
You can even create a promise on the server, and await it on the client:
263
+
Você pode até mesmo criar uma promise no servidor, e esperar por ela no cliente:
265
264
266
265
```js
267
-
//Server Component
266
+
//Componente de Servidor
268
267
importdbfrom'./database';
269
268
270
269
asyncfunctionPage({id}) {
271
-
//Will suspend the Server Component.
270
+
//Irá suspender o Componente de Servidor.
272
271
constnote=awaitdb.notes.get(id);
273
272
274
273
// NOTE: not awaited, will start here and await on the client.
@@ -285,7 +284,7 @@ async function Page({id}) {
285
284
```
286
285
287
286
```js
288
-
//Client Component
287
+
//Componente Cliente
289
288
"use client";
290
289
import {use} from'react';
291
290
@@ -297,6 +296,6 @@ function Comments({commentsPromise}) {
297
296
}
298
297
```
299
298
300
-
The `note`content is important data for the page to render, so we `await`it on the server. The comments are below the fold and lower-priority, so we start the promise on the server, and wait for it on the client with the`use` API. This will Suspend on the client, without blocking the `note`content from rendering.
299
+
O conteúdo de `note`é dados importantes para a página renderizar, então nós fazemos `await`nele no servidor. Os comentários estão abaixo da dobra e de baixa prioridade, então nós iniciamos a promise no servidor, e esperamos por ela no cliente com a API`use`. Isso irá Suspender no cliente, sem bloquear o conteúdo de `note`de renderizar.
301
300
302
-
Since async components are [not supported on the client](#why-cant-i-use-async-components-on-the-client), we await the promise with`use`.
301
+
Já que componentes assíncronos [não são suportados no cliente](#why-cant-i-use-async-components-on-the-client), nós fazemos await na promise com`use`.
0 commit comments