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/use-server.md
+65-65Lines changed: 65 additions & 65 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,26 +6,26 @@ canary: true
6
6
7
7
<Canary>
8
8
9
-
`'use server'`is 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.
`'use server'`marks server-side functions that can be called from client-side code.
16
+
`'use server'`istemci tarafı kodundan çağrılabilen sunucu tarafı işlevlerini işaretler.
17
17
18
18
</Intro>
19
19
20
20
<InlineToc />
21
21
22
22
---
23
23
24
-
## Reference {/*reference*/}
24
+
## Başvuru dokümanı {/*reference*/}
25
25
26
26
### `'use server'` {/*use-server*/}
27
27
28
-
Add `'use server'` at the top of an async function body to mark the function as callable by the client. We call these functions _Server Actions_.
28
+
Fonksiyonu istemci tarafından çağrılabilir olarak işaretlemek için bir asenkron fonksiyon gövdesinin başına `'use server'' ekleyin. Bu işlevlere _Sunucu Eylemleri_ adını veriyoruz.
29
29
30
30
```js {2}
31
31
asyncfunctionaddToCart(data) {
@@ -34,77 +34,76 @@ async function addToCart(data) {
34
34
}
35
35
```
36
36
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
+
İstemcide bir Sunucu Eylemi çağrıldığında, sunucuya iletilen tüm bağımsız değişkenlerin serileştirilmiş bir kopyasını içeren bir ağ isteği gönderilir. Sunucu Eylemi bir değer döndürürse, bu değer serileştirilir ve istemciye döndürülür.
38
38
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
+
İşlevleri tek tek `'use server'` ile işaretlemek yerine, bir dosyanın en üstüne bu yönergeyi ekleyerek o dosyadaki tüm dışa aktarımları, istemci koduna aktarılanlar da dahil olmak üzere her yerde kullanılabilecek Sunucu Eylemleri olarak işaretleyebilirsiniz.
40
40
41
-
#### 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/rsc/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.
41
+
#### Uyarılar {/*caveats*/}
42
+
*`'use server'`fonksiyon veya modüllerinin en başında olmalıdır; içe aktarmalar dahil diğer tüm kodların üzerinde (direktiflerin üzerindeki yorumlar uygundur). Tek ya da çift tırnakla yazılmalıdırlar, ters tırnakla değil.
43
+
*`'use server'`sadece sunucu tarafındaki dosyalarda kullanılabilir. Ortaya çıkan Sunucu Eylemleri prop'lar aracılığıyla İstemci Bileşenlerine aktarılabilir. Desteklenen [serileştirme türleri](#serializable-parameters-and-return-values) bölümüne bakın.
*Temel ağ çağrıları her zaman asenkron olduğundan, `'use server'`yalnızca asenkron fonksiyonlarda kullanılabilir.
46
+
*Sunucu Eylemlerine yönelik bağımsız değişkenleri her zaman güvenilmeyen girdi olarak değerlendirin ve tüm mutasyonları yetkilendirin. Bkz. [güvenlik hususları](#security).
47
+
*Sunucu Eylemleri bir [Transition](/reference/react/useTransition) içinde çağrılmalıdır. [`<form action>`](/reference/react-dom/components/form#props)veya[`formAction`](/reference/react-dom/components/input#props)'a geçirilen Sunucu Eylemleri otomatik olarak bir geçişte çağrılacaktır.
48
+
*Sunucu Eylemleri sunucu tarafı durumunu güncelleyen mutasyonlar için tasarlanmıştır; veri getirme için önerilmezler. Buna göre, Sunucu Eylemlerini uygulayan çatılar genellikle bir seferde bir eylemi işler ve dönüş değerini önbelleğe almanın bir yolu yoktur.
49
49
50
-
### Security considerations {/*security*/}
50
+
### Güvenlikle ilgili hususlar {/*security*/}
51
51
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
+
Sunucu Eylemlerine yönelik bağımsız değişkenler tamamen istemci kontrolündedir. Güvenlik için bunları her zaman güvenilmeyen girdi olarak ele alın ve bağımsız değişkenleri uygun şekilde doğruladığınızdan ve kaçtığınızdan emin olun.
53
53
54
-
In any Server Action, make sure to validate that the logged-in user is allowed to perform that action.
54
+
Herhangi bir Sunucu Eyleminde, oturum açan kullanıcının bu eylemi gerçekleştirmesine izin verildiğini doğruladığınızdan emin olun.
55
55
56
56
<Wip>
57
57
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
+
Bir Sunucu Eyleminden hassas verilerin gönderilmesini önlemek için, benzersiz değerlerin ve nesnelerin istemci koduna aktarılmasını önleyen deneysel taint API'leri vardır.
* [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)
* [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)
*[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) aracılığıyla yalnızca global Sembol kayıt defterine kayıtlı semboller
78
+
*Serileştirilebilir değerler içeren yinelenebilir dosyalar
* 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
*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')`
94
+
*Herhangi bir sınıfın örneği olan nesneler (belirtilen yerleşikler dışında) veya [null prototipli](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object#null-prototype_objects)
95
+
*Global olarak kaydedilmemiş semboller, örn. `Symbol('yeni sembolüm')`
96
96
97
97
98
-
Supported serializable return values are the same as [serializable props](/reference/rsc/use-client#passing-props-from-server-to-client-components)for a boundary Client Component.
98
+
Desteklenen serileştirilebilir dönüş değerleri, bir sınır İstemci Bileşeni için [serileştirilebilir proplar](/reference/rsc/use-client#passing-props-from-server-to-client-components)ile aynıdır.
### Server Actions in forms {/*server-actions-in-forms*/}
104
+
Sunucu Eylemlerinin en yaygın kullanım durumu, verileri değiştiren sunucu işlevlerini çağırmak olacaktır. Tarayıcıda, [HTML form elemanı](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form) kullanıcının bir mutation göndermesi için geleneksel yaklaşımdır. React Sunucu Bileşenleri ile React, [forms](/reference/react-dom/components/form) Sunucu Eylemleri için birinci sınıf destek sunuyor.
104
105
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).
106
-
107
-
Here is a form that allows a user to request a username.
106
+
İşte bir kullanıcının kullanıcı adı talep etmesini sağlayan bir form.
108
107
109
108
```js [[1, 3, "formData"]]
110
109
// App.js
@@ -119,21 +118,21 @@ export default function App() {
119
118
return (
120
119
<form action={requestUsername}>
121
120
<input type="text" name="username"/>
122
-
<button type="submit">Request</button>
121
+
<button type="submit">İstek</button>
123
122
</form>
124
123
);
125
124
}
126
125
```
127
126
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 <CodeStepstep={1}>[FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData)</CodeStep> as the first argument to the Server Action.
127
+
Bu örnekte `requestUsername`bir `<form>`a aktarılan bir Sunucu Eylemidir. Bir kullanıcı bu formu gönderdiğinde, `requestUsername` sunucu işlevine bir ağ isteği gönderilir. Bir formda bir Sunucu Eylemi çağırırken, React formun <CodeStepstep={1}>[FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData)</CodeStep> öğesini Sunucu Eylemine ilk argüman olarak sağlayacaktır.
129
128
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.
129
+
React, `action` formuna bir Sunucu Eylemi geçirerek formu [aşamalı olarak geliştirebilir](https://developer.mozilla.org/en-US/docs/Glossary/Progressive_Enhancement). Bu, formların JavaScript paketi yüklenmeden önce gönderilebileceği anlamına gelir.
131
130
132
-
#### Handling return values in forms {/*handling-return-values*/}
131
+
#### Formlarda dönüş değerlerini işleme {/*handling-return-values*/}
133
132
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
+
Kullanıcı adı istek formunda, bir kullanıcı adının mevcut olmaması ihtimali olabilir. `requestUsername`bize başarısız olup olmadığını söylemelidir.
135
134
136
-
To update the UI based on the result of a Server Action while supporting progressive enhancement, use [`useActionState`](/reference/react/useActionState).
135
+
Aşamalı geliştirmeyi desteklerken bir Sunucu Eyleminin sonucuna göre kullanıcı arayüzünü güncellemek için [`useActionState`](/reference/react/useActionState) kullanın.
137
136
138
137
```js
139
138
// requestUsername.js
@@ -143,9 +142,9 @@ export default async function requestUsername(formData) {
143
142
constusername=formData.get('username');
144
143
if (canRequest(username)) {
145
144
// ...
146
-
return'successful';
145
+
return'başarılı';
147
146
}
148
-
return'failed';
147
+
return'başarısız oldu';
149
148
}
150
149
```
151
150
@@ -163,21 +162,22 @@ function UsernameForm() {
163
162
<>
164
163
<form action={action}>
165
164
<input type="text" name="username"/>
166
-
<button type="submit">Request</button>
165
+
<button type="submit">İstek</button>
167
166
</form>
168
-
<p>Last submission request returned: {state}</p>
167
+
<p>Son gönderim talebi iade edildi: {state}</p>
169
168
</>
170
169
);
171
170
}
172
171
```
173
172
174
173
Note that like most Hooks, `useActionState` can only be called in <CodeStepstep={1}>[client code](/reference/rsc/use-client)</CodeStep>.
174
+
Çoğu Hook gibi `useActionState`in de yalnızca <CodeStepstep={1}>[client code](/reference/rsc/use-client)</CodeStep> içinde çağrılabileceğini unutmayın.
175
175
176
-
### Calling a Server Action outside of `<form>` {/*calling-a-server-action-outside-of-form*/}
176
+
### Sunucu Eylemini `<form>` dışında çağırma {/*calling-a-server-action-outside-of-form*/}
177
177
178
-
Server Actions are exposed server endpoints and can be called anywhere in client code.
178
+
Sunucu Eylemleri açık sunucu uç noktalarıdır ve istemci kodunun herhangi bir yerinde çağrılabilir.
179
179
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.
180
+
[Form](/reference/react-dom/components/form) dışında bir Sunucu Eylemi kullanırken, Sunucu Eylemini bir [Transition](/reference/react/useTransition) içinde çağırın; bu sayede bir yükleme göstergesi görüntüleyebilir, [iyimser state güncellemeleri](/reference/react/useOptimistic) gösterebilir ve beklenmedik hataları ele alabilirsiniz
0 commit comments