Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1da7574

Browse files
da-inda-in
and
da-in
authoredFeb 5, 2024
translate: use-server (#857)
* translate: use-server * fix: use-server analyze --------- Co-authored-by: da-in <da-in@wavve.com>
1 parent 4522fa1 commit 1da7574

File tree

1 file changed

+44
-45
lines changed

1 file changed

+44
-45
lines changed
 

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

+44-45
Original file line numberDiff line numberDiff line change
@@ -34,38 +34,38 @@ async function addToCart(data) {
3434
}
3535
```
3636

37-
When calling a Server Action on the client, it will make a network request to the server that includes a serialized copy of any arguments passed. If the Server Action returns a value, that value will be serialized and returned to the client.
37+
Server Action을 클라이언트에서 호출하면, 직렬화된 인자의 사본을 포함하는 서버로의 네트워크 요청이 생성됩니다. Server Action이 값을 반환하면, 그 값은 직렬화되고 클라이언트에 반환됩니다.
3838

39-
Instead of individually marking functions with `'use server'`, you can add the directive to the top of a file to mark all exports within that file as Server Actions that can be used anywhere, including imported in client code.
39+
함수 각각에 `'use server'`를 표기하는 대신, 파일의 맨 위에 지시어를 추가하여 파일의 모든 export를, 클라이언트를 포함한 모든 곳에서 사용할 수 있는 Server Action으로 표기할 수 있습니다.
4040

4141
#### Caveats {/*caveats*/}
42-
* `'use server'` must be at the very beginning of their function or module; above any other code including imports (comments above directives are OK). They must be written with single or double quotes, not backticks.
43-
* `'use server'` can only be used in server-side files. The resulting Server Actions can be passed to Client Components through props. See supported [types for serialization](#serializable-parameters-and-return-values).
44-
* To import a Server Action from [client code](/reference/react/use-client), the directive must be used on a module level.
45-
* Because the underlying network calls are always asynchronous, `'use server'` can only be used on async functions.
46-
* Always treat arguments to Server Actions as untrusted input and authorize any mutations. See [security considerations](#security).
47-
* Server Actions should be called in a [transition](/reference/react/useTransition). Server Actions passed to [`<form action>`](/reference/react-dom/components/form#props) or [`formAction`](/reference/react-dom/components/input#props) will automatically be called in a transition.
48-
* Server Actions are designed for mutations that update server-side state; they are not recommended for data fetching. Accordingly, frameworks implementing Server Actions typically process one action at a time and do not have a way to cache the return value.
42+
* `'use server'`는 함수 또는 모듈의 맨 처음에 있어야 합니다. import를 포함한 다른 코드보다 위에 있어야 합니다(지시어 위의 주석은 괜찮습니다). 백틱이 아닌 단일 또는 이중 따옴표로 작성해야 합니다.
43+
* `'use server'`는 서버 측 파일에서만 사용할 수 있습니다. 결과적인 Server Action은 props를 통해 클라이언트 컴포넌트로 전달할 수 있습니다. 제공되는 [직렬화 타입](#serializable-parameters-and-return-values)을 참고하세요.
44+
* Server Action을 [클라이언트 코드](/reference/react/use-client)에서 import 하기 위해, 지시어는 모듈 수준에서 사용되어야 합니다.
45+
* 기본 네트워크 호출이 항상 비동기이므로 `'use server'`는 비동기 함수에서만 사용할 수 있습니다.
46+
* 항상 Server Action의 인자를 신뢰할 수 없는 입력으로 취급하고 모든 변경을 검토하세요. [보안 고려사항](#security)을 확인하세요.
47+
* Server Action은 [transition](/reference/react/useTransition) 안에서 호출되어야합니다. [`<form action>`](/reference/react-dom/components/form#props) 또는 [`formAction`](/reference/react-dom/components/input#props)로 전달된 Server Action은 자동으로 transition 내에서 호출됩니다.
48+
* Server Action은 서버 측 상태를 업데이트하는 mutation을 위해 설계되었으며 데이터 fetching에는 권장되지 않습니다. 따라서 서버 액션을 구현하는 프레임워크는 일반적으로 한 번에 하나의 액션을 처리하며 반환 값을 캐시할 방법이 없습니다.
4949

50-
### Security considerations {/*security*/}
50+
### 보안 고려사항 {/*security*/}
5151

52-
Arguments to Server Actions are fully client-controlled. For security, always treat them as untrusted input, and make sure to validate and escape arguments as appropriate.
52+
Server Action에 대한 인수는 완전히 클라이언트에서 제어됩니다. 보안을 위해 항상 신뢰할 수 없는 입력으로 취급하여, 인자를 적절하게 검증하고 이스케이프 하는지 확인하세요.
5353

54-
In any Server Action, make sure to validate that the logged-in user is allowed to perform that action.
54+
Server Action에서 로그인한 사용자가 해당 작업을 수행할 수 있는지 확인하세요.
5555

5656
<Wip>
5757

58-
To prevent sending sensitive data from a Server Action, there are experimental taint APIs to prevent unique values and objects from being passed to client code.
58+
Server Action에서 중요한 데이터를 전송하지 않도록 하기 위해, 고유한 값과 객체가 클라이언트 코드로 전달되는 것을 방지하기 위한 실험적인 테인트 API가 있습니다.
5959

60-
See [experimental_taintUniqueValue](/reference/react/experimental_taintUniqueValue) and [experimental_taintObjectReference](/reference/react/experimental_taintObjectReference).
60+
[experimental_taintUniqueValue](/reference/react/experimental_taintUniqueValue)[experimental_taintObjectReference](/reference/react/experimental_taintObjectReference)를 참고하세요.
6161

6262
</Wip>
6363

64-
### Serializable arguments and return values {/*serializable-parameters-and-return-values*/}
64+
### 직렬화 가능 인수와 반환 값 {/*serializable-parameters-and-return-values*/}
6565

66-
As client code calls the Server Action over the network, any arguments passed will need to be serializable.
66+
클라이언트 코드가 네트워크를 통해 서버 작업을 호출할 때 전달된 인수는 모두 직렬화되어야 합니다.
6767

68-
Here are supported types for Server Action arguments:
68+
다음은 지원되는 Server Action 인자의 타입입니다.
6969

7070
* Primitives
7171
* [string](https://developer.mozilla.org/en-US/docs/Glossary/String)
@@ -74,37 +74,35 @@ Here are supported types for Server Action arguments:
7474
* [boolean](https://developer.mozilla.org/en-US/docs/Glossary/Boolean)
7575
* [undefined](https://developer.mozilla.org/en-US/docs/Glossary/Undefined)
7676
* [null](https://developer.mozilla.org/en-US/docs/Glossary/Null)
77-
* [symbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol), only symbols registered in the global Symbol registry via [`Symbol.for`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for)
78-
* Iterables containing serializable values
77+
* [symbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol), [`Symbol.for`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/for)를 통해 전역 Symbol로 등록된 Symbol 한정
78+
* 직렬화 가능한 값을 포함한 Iterables
7979
* [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
8080
* [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)
8181
* [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)
8282
* [Set](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set)
83-
* [TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) and [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
83+
* [TypedArray](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)
8484
* [Date](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)
85-
* [FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData) instances
86-
* Plain [objects](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object): those created with [object initializers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer), with serializable properties
87-
* Functions that are Server Actions
85+
* [FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData) 인스턴스
86+
* [object initializers](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer)로 직렬화 가능한 속성과 함께 생성된 일반 [objects](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)
87+
* Server Action인 함수
8888
* [Promises](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
8989

90-
Notably, these are not supported:
91-
* React elements, or [JSX](https://react.dev/learn/writing-markup-with-jsx)
92-
* Functions, including component functions or any other function that is not a Server Action
93-
* [Classes](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Classes_in_JavaScript)
94-
* Objects that are instances of any class (other than the built-ins mentioned) or objects with [a null prototype](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object#null-prototype_objects)
95-
* Symbols not registered globally, ex. `Symbol('my new symbol')`
96-
97-
98-
Supported serializable return values are the same as [serializable props](/reference/react/use-client#passing-props-from-server-to-client-components) for a boundary Client Component.
90+
특히 다음은 지원되지 않습니다.
91+
* React 엘리먼트 또는 [JSX](https://react.dev/learn/writing-markup-with-jsx)
92+
* 컴포넌트 함수 또는 Server Action이 아닌 다른 함수를 포함하는 함수
93+
* [클래스](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Classes_in_JavaScript)
94+
* 클래스의 인스턴스인 객체(언급된 내장 객체 제외)또는 [null 프로토타입](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object#null-prototype_objects)이 있는 개체
95+
* 전역에 등록되지 않은 Symbol, 예. `Symbol('my new symbol')`
9996

97+
지원되는 직렬화 가능한 반환 값은 경계 클라이언트 컴포넌트의 [직렬화 가능한 props](/reference/react/use-client#passing-props-from-server-to-client-components)와 동일합니다.
10098

10199
## 사용법 {/*usage*/}
102100

103-
### Server Actions in forms {/*server-actions-in-forms*/}
101+
### Server Action 형식 {/*server-actions-in-forms*/}
104102

105-
The most common use case of Server Actions will be calling server functions that mutate data. On the browser, the [HTML form element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form) is the traditional approach for a user to submit a mutation. With React Server Components, React introduces first-class support for Server Actions in [forms](/reference/react-dom/components/form).
103+
Server Action의 가장 일반적인 사용 사례는, 데이터를 변경하는 Server Function을 호출하는 것입니다. 브라우저에서 [HTML form 엘리먼트](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form)는 사용자가 mutation을 제출하는 전통적인 접근 방식입니다. React 서버 컴포넌트로, React는 [forms](/reference/react-dom/components/form)에서 Server Action에 대한 최상의 지원을 제공합니다.
106104

107-
Here is a form that allows a user to request a username.
105+
사용자가 사용자 이름을 요청할 수 있는 양식이 있습니다.
108106

109107
```js [[1, 3, "formData"]]
110108
// App.js
@@ -125,15 +123,16 @@ export default function App() {
125123
}
126124
```
127125

128-
In this example `requestUsername` is a Server Action passed to a `<form>`. When a user submits this form, there is a network request to the server function `requestUsername`. When calling a Server Action in a form, React will supply the form's <CodeStep step={1}>[FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData)</CodeStep> as the first argument to the Server Action.
126+
예시에서 `requestUsername``<form>`를 통한 Server Action이다. 사용자가 이 양식을 제출하면 서버 함수인 `requestUsername`에 네트워크 요청이 있습니다. form에서 Server Action을 호출할 때 React는 form의 <CodeStep step={1}>[FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData)</CodeStep>를 Server Action의 첫 번째 인자로 제공합니다.
127+
128+
Server Action을 from `action`에 전달하여, React는 form을 [점진적 향상](https://developer.mozilla.org/en-US/docs/Glossary/Progressive_Enhancement)할 수 있습니다. 이것은 자바스크립트 번들이 로드되기 전에 양식을 제출할 수 있다는 것을 의미합니다.
129129

130-
By passing a Server Action to the form `action`, React can [progressively enhance](https://developer.mozilla.org/en-US/docs/Glossary/Progressive_Enhancement) the form. This means that forms can be submitted before the JavaScript bundle is loaded.
131130

132-
#### Handling return values in forms {/*handling-return-values*/}
131+
#### form에서 반환 값 처리 {/*handling-return-values*/}
133132

134-
In the username request form, there might be the chance that a username is not available. `requestUsername` should tell us if it fails or not.
133+
username 요청 form에서, username을 사용할 수 없을 가능성이 있습니다. `requestUsername`은 실패 여부를 알려주어야 합니다.
135134

136-
To update the UI based on the result of a Server Action while supporting progressive enhancement, use [`useFormState`](/reference/react-dom/hooks/useFormState).
135+
점진적 향상을 지원하며 Server Action의 결과를 기반으로 UI를 업데이트하려면, [`useFormState`](/reference/react-dom/hooks/useFormState)를 사용하세요.
137136

138137
```js
139138
// requestUsername.js
@@ -171,13 +170,13 @@ function UsernameForm() {
171170
}
172171
```
173172

174-
Note that like most Hooks, `useFormState` can only be called in <CodeStep step={1}>[client code](/reference/react/use-client)</CodeStep>.
173+
대부분의 Hook과 마찬가지로 `useFormState`<CodeStep step={1}>[client code](/reference/react/use-client)</CodeStep>에서만 호출할 수 있습니다.
175174

176-
### Calling a Server Action outside of `<form>` {/*calling-a-server-action-outside-of-form*/}
175+
### `<form>`외부에서 Server Action 호출하기 {/*calling-a-server-action-outside-of-form*/}
177176

178-
Server Actions are exposed server endpoints and can be called anywhere in client code.
177+
Server Action은 노출된 서버 엔드포인트이며 클라이언트 코드 어디에서나 호출할 수 있습니다.
179178

180-
When using a Server Action outside of a [form](/reference/react-dom/components/form), call the Server Action in a [transition](/reference/react/useTransition), which allows you to display a loading indicator, show [optimistic state updates](/reference/react/useOptimistic), and handle unexpected errors. Forms will automatically wrap Server Actions in transitions.
179+
[form](/reference/react-dom/components/form) 외부에서 Server Action을 사용할 때, [transition](/reference/react/useTransition)에서 서버 액션을 호출하면 로딩 인디케이터를 표시하고, [낙관적 상태 업데이트](/reference/react/useOptimistic)를 표시하며 예기치 않은 오류를 처리할 수 있습니다. Form은 transition의 Server Action을 자동으로 래핑합니다.
181180

182181
```js {9-12}
183182
import incrementLike from './actions';
@@ -214,4 +213,4 @@ export default async function incrementLike() {
214213
}
215214
```
216215

217-
To read a Server Action return value, you'll need to `await` the promise returned.
216+
Server Action 반환 값을 읽으려면 반환된 promise를 `await` 해야합니다.

0 commit comments

Comments
 (0)
Please sign in to comment.