Skip to content

Commit d7ef54b

Browse files
committed
use.md
1 parent 8f1e0fd commit d7ef54b

1 file changed

Lines changed: 29 additions & 174 deletions

File tree

  • src/content/reference/react

src/content/reference/react/use.md

Lines changed: 29 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,11 +1030,7 @@ export default function App() {
10301030
}
10311031
```
10321032
1033-
<<<<<<< HEAD
1034-
<CodeStep step={2}>İstemci Bileşeni</CodeStep> prop olarak iletilen Promise'i alır ve <CodeStep step={5}>`use`</CodeStep> API'ına ileterek kullanır. Bu yöntem Sunucu Bileşeni içerisinde oluşturulan <CodeStep step={4}>Promise</CodeStep>'ten alınan verinin <CodeStep step={2}>İstemci Bileşeni</CodeStep> tarafından okunmasına olanak tanır.
1035-
=======
1036-
The Client Component then takes the Promise it received as a prop and passes it to the `use` API. This allows the Client Component to read the value from the Promise that was initially created by the Server Component.
1037-
>>>>>>> 2639f369946f763fff9a2572b0d7c4b9e2f83ebd
1033+
Client Component daha sonra prop olarak aldığı Promise’i alır ve `use` API’sine geçirir. Bu, Client Component’in başlangıçta Server Component tarafından oluşturulan Promise’ten gelen değeri okumasını sağlar.
10381034
10391035
```js
10401036
// message.js
@@ -1047,12 +1043,7 @@ export function Message({ messagePromise }) {
10471043
return <p>Aktarılan Mesaj: {messageContent}</p>;
10481044
}
10491045
```
1050-
<<<<<<< HEAD
1051-
1052-
<CodeStep step={2}>`Message`</CodeStep> bir <CodeStep step={3}>[`Suspense`](/reference/react/Suspense)</CodeStep> içerisinde olduğu için Promise çözümleninceye kadar yedek görünüm görüntülenecektir. Promise çözümlendiğinde değer <CodeStep step={5}>`use`</CodeStep> API tarafından okunacak ve <CodeStep step={2}>`Message`</CodeStep> bileşeni Suspense'in yedek görünüm ile yer değiştirecektir.
1053-
=======
1054-
Because `Message` is wrapped in a [Suspense](/reference/react/Suspense) boundary, the fallback will be displayed until the Promise is resolved. When the Promise is resolved, the value will be read by the `use` API and the `Message` component will replace the Suspense fallback.
1055-
>>>>>>> 2639f369946f763fff9a2572b0d7c4b9e2f83ebd
1046+
`Message`, bir [Suspense](/reference/react/Suspense) boundary’si ile sarıldığı için, Promise resolve edilene kadar fallback gösterilir. Promise resolve edildiğinde, değer `use` API’si tarafından okunur ve `Message` component’i Suspense fallback’inin yerini alır.
10561047
10571048
<Sandpack>
10581049
@@ -1119,65 +1110,29 @@ root.render(
11191110
11201111
</Sandpack>
11211112
1122-
<<<<<<< HEAD
1123-
<Note>
1124-
1125-
Sunucu Bileşeni'nden İstemci Bileşeni'ne Promise aktarıldığında çözümlenen değer sunucu ile istemci arasından geçmesi için serileştirilebilir olması gerekir. Fonksiyonlar gibi veri türleri serileştirilemezler ve Promise'in çözümlenen değeri olamazlar.
1126-
1127-
</Note>
1128-
1129-
1130-
=======
1131-
>>>>>>> 2639f369946f763fff9a2572b0d7c4b9e2f83ebd
11321113
<DeepDive>
11331114
11341115
#### Promise'i Sunucu Bileşeninde mi yoksa İstemci Bileşeninde mi çözümlemeliyim? {/*resolve-promise-in-server-or-client-component*/}
11351116
1136-
<<<<<<< HEAD
1137-
Promise, Sunucu Bileşeni'nden İstemci Bileşeni'ne aktarılabilir ve İstemci Bileşeni içerisinde `use` API kullanarak çözümlenebilir. Yanı sıra istersen Promise'i Sunucu Bileşeni içerisinde `await` kullanarak çözümleyebilir ve gerekli veriyi İstemci Bileşeni içerisine prop olarak iletebilirsin.
1138-
=======
1139-
A Promise can be resolved with `await` in a Server Component, or passed as a prop to a Client Component and resolved there with `use`.
1117+
Bir Promise, bir Server Component içinde `await` ile resolve edilebilir veya bir Client Component’e prop olarak geçirilip orada `use` ile resolve edilebilir.
11401118
1141-
Using `await` in a Server Component suspends the Server Component itself, and the Client Component receives the resolved value as a prop:
1142-
>>>>>>> 2639f369946f763fff9a2572b0d7c4b9e2f83ebd
1119+
Bir Server Component içinde `await` kullanmak Server Component’in kendisini suspend eder ve Client Component resolved value’yu prop olarak alır:
11431120
11441121
```js
11451122
// Server Component
11461123
export default async function App() {
1147-
// Will suspend the Server Component.
1124+
// Server Component’i suspend eder.
11481125
const messageContent = await fetchMessage();
11491126
return <Message messageContent={messageContent} />;
11501127
}
11511128
```
11521129
1153-
<<<<<<< HEAD
1154-
Ancak bir [Sunucu Bileşeninde](/reference/rsc/server-components) `await` kullanmak, `await` deyimi bitene kadar bileşenin oluşturulmasını engelleyecektir. Bir Sunucu Bileşeninden bir İstemci Bileşenine bir Promise geçirmek, Promise'in Sunucu Bileşeninin oluşturulmasını engellemesini önler.
1155-
1156-
</DeepDive>
1157-
1158-
### Reddedilen Promise'ler ile başa çıkmak {/*dealing-with-rejected-promises*/}
1159-
1160-
Bazen `use`'a aktarılan Promise reddedilebilir. Reddedilen Promise'leri şu şekilde yönetebilirsiniz:
1161-
1162-
1. [Error Boundary ile kullanıcılara hata gösterme](#displaying-an-error-to-users-with-error-boundary)
1163-
2. [`Promise.catch` ile alternatif değer sağlama](#providing-an-alternative-value-with-promise-catch)
1164-
1165-
<Pitfall>
1166-
`use`, try-catch bloğu içerisinde çağırılamaz. Try-catch bloğu yerine [bileşeni Error Boundary içerisine ekleyin](#displaying-an-error-to-users-with-error-boundary), ya da [Promise'in `.catch` methodundan yararlanarak alternatif bir değer sağlayın](#providing-an-alternative-value-with-promise-catch).
1167-
</Pitfall>
1168-
1169-
#### Error Boundary ile kullanıcılara hata gösterme {/*displaying-an-error-to-users-with-error-boundary*/}
1170-
1171-
Bir Promise reddedildiğinde kullanıcıya hata göstermek istiyorsanız, [Error Boundary](/reference/react/Component#catching-rendering-errors-with-an-error-boundary) kullanabilirsiniz.
1172-
Error Boundary kullanmak için, `use` API’sini çağırdığınız bileşeni bir Error Boundary ile sarın.
1173-
Eğer `use` fonksiyonuna iletilen Promise reddedilirse, Error Boundary için tanımlanan fallback içerik görüntülenecektir.
1174-
=======
1175-
A Server Component can also start a Promise without awaiting it and pass the Promise to a Client Component. The Server Component returns immediately, and the Client Component suspends when it calls `use`:
1130+
Bir Server Component ayrıca bir Promise’i await etmeden başlatabilir ve Promise’i bir Client Component’e geçirebilir. Server Component hemen return eder ve Client Component `use` çağırdığında suspend olur:
11761131
11771132
```js
11781133
// Server Component
11791134
export default function App() {
1180-
// Not awaited: starts here, resolves on the client.
1135+
// Await edilmedi: burada başlar, client’ta resolve olur.
11811136
const messagePromise = fetchMessage();
11821137
return <Message messagePromise={messagePromise} />;
11831138
}
@@ -1186,20 +1141,21 @@ export default function App() {
11861141
```js
11871142
// Client Component
11881143
'use client';
1144+
11891145
import { use } from 'react';
11901146

11911147
export function Message({ messagePromise }) {
1192-
// Will suspend until the data is available.
1148+
// Data available olana kadar suspend eder.
11931149
const messageContent = use(messagePromise);
11941150
return <p>{messageContent}</p>;
11951151
}
11961152
```
11971153
1198-
Prefer `await` in a Server Component when possible, since it keeps the data fetching on the server. If a Server Component above already awaits the data, pass the resolved value down as a prop instead of creating a new Promise to call `use`.
1154+
Mümkün olduğunda Server Component içinde `await` kullanmayı tercih edin; çünkü bu, data fetching’i server tarafında tutar. Eğer üstteki bir Server Component data’yı zaten await ediyorsa, `use` çağırmak için yeni bir Promise oluşturmak yerine resolved value’yu prop olarak aşağı geçirin.
11991155
1200-
You can also pass promise as a prop to a Client Component without awaiting it, and then read it with `use(promise)` to suspend deeper in the tree. This allows more of the surrounding UI to complete while the Promise is pending. A common case is interactive content like popovers and tooltips, where the data is needed only after a hover or click. Client Components can't `await`, so they rely on `use` to suspend on a Promise.
1156+
Ayrıca promise’i await etmeden bir Client Component’e prop olarak geçirebilir ve ardından tree’nin daha derininde suspend etmek için `use(promise)` ile okuyabilirsiniz. Bu, Promise pending durumdayken çevredeki UI’ın daha büyük bir kısmının tamamlanmasına olanak tanır. Yaygın bir durum, popover ve tooltip gibi interactive content’lerdir; burada data yalnızca hover veya click sonrasında gerekir. Client Component’ler `await` kullanamaz, bu yüzden bir Promise üzerinde suspend olmak için `use`’a güvenirler.
12011157
1202-
In either case, wrap the component that reads the Promise in a Suspense boundary so React can show a fallback while the Promise is pending. See [Revealing content together at once](/reference/react/Suspense#revealing-content-together-at-once) for guidance on boundary placement.
1158+
Her iki durumda da, Promise’i okuyan component’i bir Suspense boundary ile sarın; böylece React, Promise pending durumdayken bir fallback gösterebilir. Boundary placement konusunda rehberlik için [Revealing content together at once](/reference/react/Suspense#revealing-content-together-at-once) bölümüne bakın.
12031159
12041160
</DeepDive>
12051161
@@ -1210,7 +1166,6 @@ In either case, wrap the component that reads the Promise in a Suspense boundary
12101166
If the Promise passed to `use` is rejected, the error propagates to the nearest [Error Boundary](/reference/react/Component#catching-rendering-errors-with-an-error-boundary). Wrap the component that calls `use` in an Error Boundary to display a fallback when the Promise is rejected.
12111167
12121168
In the example below, `fetchData` rejects on the first attempt and succeeds on retry. The Error Boundary catches the rejection and shows a fallback with a "Try again" button.
1213-
>>>>>>> 2639f369946f763fff9a2572b0d7c4b9e2f83ebd
12141169
12151170
<Sandpack>
12161171
@@ -1231,33 +1186,22 @@ export default function App() {
12311186
}
12321187

12331188
return (
1234-
<<<<<<< HEAD
1235-
<ErrorBoundary fallback={<p>⚠️Bir şeyler yanlış gitti</p>}>
1236-
<Suspense fallback={<p>⌛Mesaj indiriliyor...</p>}>
1237-
<Message messagePromise={messagePromise} />
1238-
=======
12391189
<ErrorBoundary
12401190
resetKeys={[albumsPromise]}
12411191
fallbackRender={() => (
12421192
<>
1243-
<p>⚠️ Something went wrong loading the albums.</p>
1244-
<button onClick={handleRetry}>Try again</button>
1193+
<p>⚠️ Albümler yüklenirken bir sorun oluştu.</p>
1194+
<button onClick={handleRetry}>Tekrar dene</button>
12451195
</>
12461196
)}
12471197
>
1248-
<Suspense fallback={<p>Loading...</p>}>
1198+
<Suspense fallback={<p>Yükleniyor...</p>}>
12491199
<Albums albumsPromise={albumsPromise} />
1250-
>>>>>>> 2639f369946f763fff9a2572b0d7c4b9e2f83ebd
12511200
</Suspense>
12521201
</ErrorBoundary>
12531202
);
12541203
}
12551204

1256-
<<<<<<< HEAD
1257-
function Message({ messagePromise }) {
1258-
const content = use(messagePromise);
1259-
return <p>Aktarılan mesaj: {content}</p>;
1260-
=======
12611205
function Albums({ albumsPromise }) {
12621206
const albums = use(albumsPromise);
12631207
return (
@@ -1269,7 +1213,6 @@ function Albums({ albumsPromise }) {
12691213
))}
12701214
</ul>
12711215
);
1272-
>>>>>>> 2639f369946f763fff9a2572b0d7c4b9e2f83ebd
12731216
}
12741217
```
12751218
@@ -1288,46 +1231,12 @@ export function fetchData(url) {
12881231
return cache.get(url);
12891232
}
12901233

1291-
<<<<<<< HEAD
1292-
export default function App() {
1293-
const [messagePromise, setMessagePromise] = useState(null);
1294-
const [show, setShow] = useState(false);
1295-
function download() {
1296-
setMessagePromise(fetchMessage());
1297-
setShow(true);
1298-
}
1299-
1300-
if (show) {
1301-
return <MessageContainer messagePromise={messagePromise} />;
1302-
} else {
1303-
return <button onClick={download}>Mesajı İndir</button>;
1304-
}
1305-
=======
13061234
export function refetchData(url) {
13071235
cache.delete(url);
13081236
retried = true;
13091237
return fetchData(url);
1310-
>>>>>>> 2639f369946f763fff9a2572b0d7c4b9e2f83ebd
13111238
}
13121239

1313-
<<<<<<< HEAD
1314-
```js src/index.js hidden
1315-
import React, { StrictMode } from 'react';
1316-
import { createRoot } from 'react-dom/client';
1317-
import './styles.css';
1318-
1319-
// TODO: Bu örneği,
1320-
// Codesandbox Sunucu Bileşeni
1321-
// demo ortamı oluşturulduğunda güncelleyin
1322-
import App from './App';
1323-
1324-
const root = createRoot(document.getElementById('root'));
1325-
root.render(
1326-
<StrictMode>
1327-
<App />
1328-
</StrictMode>
1329-
);
1330-
=======
13311240
async function getData(url) {
13321241
// Add a fake delay to make the loading state visible.
13331242
await new Promise(resolve => setTimeout(resolve, 1000));
@@ -1357,7 +1266,6 @@ async function getData(url) {
13571266
}
13581267
throw new Error('Not implemented');
13591268
}
1360-
>>>>>>> 2639f369946f763fff9a2572b0d7c4b9e2f83ebd
13611269
```
13621270
13631271
```json package.json hidden
@@ -1373,116 +1281,63 @@ async function getData(url) {
13731281
```
13741282
</Sandpack>
13751283
1376-
<<<<<<< HEAD
1377-
#### `Promise.catch` methodunu kullanarak alternatif bir veri sunmak {/*providing-an-alternative-value-with-promise-catch*/}
1378-
1379-
Eğer `use`'a aktarılan Promise reddedildiğinde yerine alternatif bir değer sağlamak istiyorsan Promise'in <CodeStep step={1}>[`catch`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch)</CodeStep> methodunu kullanabilirsin.
1380-
1381-
```js [[1, 6, "catch"],[2, 7, "return"]]
1382-
import { Message } from './message.js';
1383-
1384-
export default function App() {
1385-
const messagePromise = new Promise((resolve, reject) => {
1386-
reject();
1387-
}).catch(() => {
1388-
return "yeni mesaj bulunamadı.";
1389-
});
1390-
1391-
return (
1392-
<Suspense fallback={<p>Mesaj bekleniyor...</p>}>
1393-
<Message messagePromise={messagePromise} />
1394-
</Suspense>
1395-
);
1396-
}
1397-
```
1398-
1399-
Promise'in <CodeStep step={1}>`catch`</CodeStep> methodunu kullanmak için Promise objesinden <CodeStep step={1}>`catch`</CodeStep>'i çağır. <CodeStep step={1}>`catch`</CodeStep> tek bir argüman alır: Bir hata mesajını argüman olarak alan bir fonksiyon. <CodeStep step={1}>`catch`</CodeStep>'e geçirilen fonskiyon tarafından döndürülen her şey, Promise'in çözümlenen değeri olarak kullanılacaktır.
1400-
1401-
=======
1402-
>>>>>>> 2639f369946f763fff9a2572b0d7c4b9e2f83ebd
14031284
---
14041285
14051286
## Sorun Giderme {/*troubleshooting*/}
14061287
1407-
<<<<<<< HEAD
1408-
### "Suspense İstisnası: Bu gerçek bir hata değil!" {/*suspense-exception-error*/}
1409-
1410-
Ya `use` fonksiyonunu bir **React Component** veya **Hook** fonksiyonu dışında çağırıyorsunuz,
1411-
ya da `use`’u bir **trycatch** bloğu içinde çağırıyorsunuz. Eğer `use`’u bir trycatch bloğu içinde çağırıyorsanız, bileşeninizi bir **Error Boundary** ile sarın,
1412-
veya Promisein `catch` metodunu kullanarak hatayı yakalayın ve Promise’i başka bir değerle çözümleyin (**resolve edin**). [Bu örneklere bakın](#dealing-with-rejected-promises).
1288+
### Şu hatayı alıyorum: "Suspense Exception: This is not a real error!" {/*suspense-exception-error*/}
14131289
1414-
Eğer `use`'u bir React Bileşeni veya Hook fonksiyonu dışında çağırıyorsanız `use` çağrısını bir React Bileşeni veya Hook fonksiyonu içerisine taşıyın.
1415-
1416-
```jsx
1417-
function MessageComponent({messagePromise}) {
1418-
function download() {
1419-
// ❌ `use`, bir Bileşen veya Hook olmayan fonksiyon tarafından çağırılıyor
1420-
const message = use(messagePromise);
1421-
// ...
1422-
```
1423-
1424-
Bunun yerine, `use` fonksiyonunu herhangi bir bileşen kapanışının dışında çağırın. `use` fonksiyonunu çağıran fonksiyon bir bileşen veya Hook olmalıdır.
1425-
1426-
```jsx
1427-
function MessageComponent({messagePromise}) {
1428-
// ✅ `use`, bir component’ten çağrılıyor.
1429-
const message = use(messagePromise);
1430-
// ...
1431-
```
1432-
=======
1433-
### I'm getting an error: "Suspense Exception: This is not a real error!" {/*suspense-exception-error*/}
1434-
1435-
You are calling `use` inside a try-catch block. `use` throws internally to integrate with Suspense, so it cannot be wrapped in try-catch. Instead, wrap the component that calls `use` in an [Error Boundary](#displaying-an-error-with-an-error-boundary) to handle errors.
1290+
`use`’u bir try-catch block’u içinde çağırıyorsunuz. `use`, Suspense ile entegre olmak için internal olarak throw eder, bu yüzden try-catch ile sarılamaz. Bunun yerine, error’ları handle etmek için `use` çağıran component’i bir [Error Boundary](#displaying-an-error-with-an-error-boundary) ile sarın.
14361291
14371292
```jsx
14381293
function Albums({ albumsPromise }) {
14391294
try {
1440-
// ❌ Don't wrap `use` in try-catch
1295+
// ❌ `use`’u try-catch içinde sarmayın
14411296
const albums = use(albumsPromise);
14421297
} catch (e) {
14431298
return <p>Error</p>;
14441299
}
14451300
// ...
14461301
```
14471302
1448-
Instead, wrap the component in an Error Boundary:
1303+
Bunun yerine, component’i bir Error Boundary ile sarın:
14491304
14501305
```jsx
14511306
function Albums({ albumsPromise }) {
1452-
// ✅ Call `use` without try-catch
1307+
// ✅ `use`’u try-catch olmadan çağırın
14531308
const albums = use(albumsPromise);
14541309
// ...
14551310
```
14561311
14571312
```jsx
1458-
// ✅ Use an Error Boundary to handle errors
1313+
//Error’ları handle etmek için bir Error Boundary kullanın
14591314
<ErrorBoundary fallback={<p>Error</p>}>
14601315
<Albums albumsPromise={albumsPromise} />
14611316
</ErrorBoundary>
14621317
```
14631318
14641319
---
14651320
1466-
### I'm getting a warning: "A component was suspended by an uncached promise" {/*uncached-promise-error*/}
1321+
### Şu uyarıyı alıyorum: "A component was suspended by an uncached promise" {/*uncached-promise-error*/}
14671322
1468-
The Promise passed to `use` is not cached, so React cannot reuse it across re-renders.
1323+
`use`’a geçirilen Promise cache’lenmemiştir, bu yüzden React onu re-render’lar arasında yeniden kullanamaz.
14691324
1470-
This commonly happens when calling `fetch` or an `async` function directly in render:
1325+
Bu durum genellikle render sırasında doğrudan `fetch` veya bir `async` function çağrıldığında olur:
14711326
14721327
```js
14731328
function Albums() {
1474-
// 🔴 This creates a new Promise on every render
1329+
// 🔴 Bu, her render’da yeni bir Promise oluşturur
14751330
const albums = use(fetch('/albums'));
1331+
14761332
// ...
14771333
}
14781334
```
14791335
1480-
To fix this, cache the Promise so the same instance is reused:
1336+
Bunu düzeltmek için, aynı instance’ın yeniden kullanılmasını sağlayacak şekilde Promise’i cache’leyin:
14811337
14821338
```js
1483-
// ✅ fetchData returns the same Promise for the same URL
1339+
// ✅ fetchData aynı URL için aynı Promise’i döndürür
14841340
const albums = use(fetchData('/albums'));
14851341
```
14861342
1487-
See [caching Promises for Client Components](#caching-promises-for-client-components) for more details.
1488-
>>>>>>> 2639f369946f763fff9a2572b0d7c4b9e2f83ebd
1343+
Daha fazla detay için [Client Components için Promise cache’leme](#caching-promises-for-client-components) bölümüne bakın.

0 commit comments

Comments
 (0)