Skip to content

Commit 6cef2b2

Browse files
Translate use server directive reference (#842)
* Update use-server.md * Update src/content/reference/react/use-server.md * Update src/content/reference/react/use-server.md --------- Co-authored-by: Néstor Guillermo Hernández <[email protected]>
1 parent 0edecbb commit 6cef2b2

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/content/reference/react/use-server.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@ title: "'use server'"
44

55
<Wip>
66

7-
This section is incomplete.
7+
Esta sección está incompleta.
88

9-
These directives are needed only if you're [using React Server Components](/learn/start-a-new-react-project#bleeding-edge-react-frameworks) or building a library compatible with them.
9+
Estas directivas solo son necesarias si estás [usando React Server Components](/learn/start-a-new-react-project#bleeding-edge-react-frameworks) o construyendo una librería compatible con ellos.
1010

1111
</Wip>
1212

1313

1414
<Intro>
1515

16-
`'use server'` marks server-side functions that can be called from client-side code.
16+
`'use server'` marca funciones del lado del servidor que pueden llamarse desde el código del lado del cliente.
1717

1818
</Intro>
1919

2020
<InlineToc />
2121

2222
---
2323

24-
## Reference {/*reference*/}
24+
## Referencia {/*reference*/}
2525

2626
### `'use server'` {/*use-server*/}
2727

28-
Add `'use server';` at the very top of an async function to mark that the function can be executed by the client.
28+
Añade `'use server';` en la parte superior de una función asíncrona para marcar que la función puede ser ejecutada por el cliente.
2929

3030
```js
3131
async function addToCart(data) {
@@ -36,13 +36,13 @@ async function addToCart(data) {
3636
// <ProductDetailPage addToCart={addToCart} />
3737
```
3838

39-
This function can be passed to the client. When called on the client, it will make a network request to the server that includes a serialized copy of any arguments passed. If the server function returns a value, that value will be serialized and returned to the client.
39+
Esta función puede ser pasada al cliente. Cuando es llamada en el cliente, hará una petición de red al servidor que incluye una copia serializada de cualquier argumento pasado. Si la función del servidor devuelve un valor, ese valor será serializado y devuelto al cliente.
4040

41-
Alternatively, add `'use server';` at the very top of a file to mark all exports within that file as async server functions that can be used anywhere, including imported in client component files.
41+
Alternativamente, añade `'use server'` en la parte superior de un archivo para marcar todas las exportaciones dentro de ese archivo como funciones asíncronas del servidor que pueden ser usadas en cualquier lugar, incluso importadas en los archivos de componentes de cliente.
4242

43-
#### Caveats {/*caveats*/}
43+
#### Advertencias {/*caveats*/}
4444

45-
* Remember that parameters to functions marked with `'use server'` are fully client-controlled. For security, always treat them as untrusted input, making sure to validate and escape the arguments as appropriate.
46-
* To avoid the confusion that might result from mixing client- and server-side code in the same file, `'use server'` can only be used in server-side files; the resulting functions can be passed to client components through props.
47-
* Because the underlying network calls are always asynchronous, `'use server'` can be used only on async functions.
48-
* Directives like `'use server'` must be at the very beginning of their function or file, above any other code including imports (comments above directives are OK). They must be written with single or double quotes, not backticks. (The `'use xyz'` directive format somewhat resembles the `useXyz()` Hook naming convention, but the similarity is coincidental.)
45+
* Recuerda que los parámetros de las funciones marcadas con `'use server'` están totalmente controlados en el cliente. Por seguridad, siempre tratálos como entradas no confiables, asegúrate de validar y escapar los argumentos según corresponda.
46+
* Para evitar la confusión que podría resultar de mezclar el código del lado del cliente y del lado del servidor en el mismo archivo, `'use server'` solo puede ser usado en archivos del lado del servidor; las funciones resultantes pueden pasarse a componentes de cliente a través de las _props_.
47+
* Dado que las llamadas a la red subyacente son siempre asíncronas, `'use server'` solo puede utilizarse en funciones asíncronas.
48+
* Directivas como `'use server'` deben estar en el inicio de su función o archivo, por encima de cualquier otro código incluyendo importaciones (comentarios por encima de las directivas están bien). Deben escribirse con comillas simples o dobles, no con comillas invertidas. (El formato de la directiva `'use xyz'` se parece en algo a la convención de nombres de los Hooks `useXyz()`, pero el parecido es coincidencia).

0 commit comments

Comments
 (0)