Skip to content

Commit 18a15a3

Browse files
committed
docs: translate custom hooks (30%)
1 parent ee8b3fd commit 18a15a3

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

src/content/learn/reusing-logic-with-custom-hooks.md

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -513,43 +513,43 @@ export default function ChatRoom({ roomId }) {
513513
);
514514
}
515515
```
516-
// TODO: continue from here
516+
517517
```js chat.js
518518
export function createConnection({ serverUrl, roomId }) {
519-
// A real implementation would actually connect to the server
519+
// Gerçek bir uygulama sunucuya gerçekten bağlanacaktır
520520
if (typeof serverUrl !== 'string') {
521-
throw Error('Expected serverUrl to be a string. Received: ' + serverUrl);
521+
throw Error(`serverUrl'in bir string olması bekleniyordu. Alınan: ` + serverUrl);
522522
}
523523
if (typeof roomId !== 'string') {
524-
throw Error('Expected roomId to be a string. Received: ' + roomId);
524+
throw Error(`roomId'nin bir string olması bekleniyordu. Alınan: ` + roomId);
525525
}
526526
let intervalId;
527527
let messageCallback;
528528
return {
529529
connect() {
530-
console.log('Connecting to "' + roomId + '" room at ' + serverUrl + '...');
530+
console.log('' + serverUrl + `'deki` + roomId + ' odasına bağlanılıyor...')
531531
clearInterval(intervalId);
532532
intervalId = setInterval(() => {
533533
if (messageCallback) {
534534
if (Math.random() > 0.5) {
535535
messageCallback('hey')
536536
} else {
537-
messageCallback('lol');
537+
messageCallback('acayip komik');
538538
}
539539
}
540540
}, 3000);
541541
},
542542
disconnect() {
543543
clearInterval(intervalId);
544544
messageCallback = null;
545-
console.log('Disconnected from "' + roomId + '" room at ' + serverUrl + '');
545+
console.log('❌ ' + serverUrl + `'deki` + roomId + ' odasından ayrılındı')
546546
},
547547
on(event, callback) {
548548
if (messageCallback) {
549-
throw Error('Cannot add the handler twice.');
549+
throw Error('İki kez yönetici eklenemez.');
550550
}
551551
if (event !== 'message') {
552-
throw Error('Only "message" event is supported.');
552+
throw Error('Sadece "message" olayı destekleniyor.');
553553
}
554554
messageCallback = callback;
555555
},
@@ -599,9 +599,9 @@ button { margin-left: 10px; }
599599
600600
</Sandpack>
601601
602-
When you change `serverUrl` or `roomId`, the Effect ["reacts" to your changes](/learn/lifecycle-of-reactive-effects#effects-react-to-reactive-values) and re-synchronizes. You can tell by the console messages that the chat re-connects every time that you change your Effect's dependencies.
602+
`serverUrl` ya da `roomId`'yi değiştirdiğinizde, efekt [değişikliklerinize "tepki verir"](/learn/lifecycle-of-reactive-effects#effects-react-to-reactive-values) ve yeniden senkronize olur. Konsol mesajlarından, efekt'in bağlı olduğu değerleri her değiştirdiğinizde sohbetin yeniden bağlandığını görebilirsiniz.
603603
604-
Now move the Effect's code into a custom Hook:
604+
Şimdi efekt'in kodunu özel bir Hook'a taşıyın:
605605
606606
```js {2-13}
607607
export function useChatRoom({ serverUrl, roomId }) {
@@ -613,14 +613,14 @@ export function useChatRoom({ serverUrl, roomId }) {
613613
const connection = createConnection(options);
614614
connection.connect();
615615
connection.on('message', (msg) => {
616-
showNotification('New message: ' + msg);
616+
showNotification('Yeni mesaj: ' + msg);
617617
});
618618
return () => connection.disconnect();
619619
}, [roomId, serverUrl]);
620620
}
621621
```
622622
623-
This lets your `ChatRoom` component call your custom Hook without worrying about how it works inside:
623+
Bu `ChatRoom` bileşeninizin özel Hook'unuzun içinde nasıl çalıştığıyla ilgilenmeden onu çağırmasına olanak sağlar:
624624

625625
```js {4-7}
626626
export default function ChatRoom({ roomId }) {
@@ -634,18 +634,18 @@ export default function ChatRoom({ roomId }) {
634634
return (
635635
<>
636636
<label>
637-
Server URL:
637+
Sunucu URL'i:
638638
<input value={serverUrl} onChange={e => setServerUrl(e.target.value)} />
639639
</label>
640-
<h1>Welcome to the {roomId} room!</h1>
640+
<h1>{roomId} odasına hoşgeldiniz!</h1>
641641
</>
642642
);
643643
}
644644
```
645645

646-
This looks much simpler! (But it does the same thing.)
646+
Bu çok daha basit görünüyor! (Ama aynı şeyi yapıyor.)
647647

648-
Notice that the logic *still responds* to prop and state changes. Try editing the server URL or the selected room:
648+
Mantığın prop ve state değişikliklerine *hala tepki verdiğine* dikkat edin. Sunucu URL'sini veya seçilen odayı düzenlemeyi deneyin:
649649
650650
<Sandpack>
651651
@@ -658,14 +658,14 @@ export default function App() {
658658
return (
659659
<>
660660
<label>
661-
Choose the chat room:{' '}
661+
Sohbet odasını seçin:{' '}
662662
<select
663663
value={roomId}
664664
onChange={e => setRoomId(e.target.value)}
665665
>
666-
<option value="general">general</option>
667-
<option value="travel">travel</option>
668-
<option value="music">music</option>
666+
<option value="general">genel</option>
667+
<option value="travel">seyahat</option>
668+
<option value="music">müzik</option>
669669
</select>
670670
</label>
671671
<hr />
@@ -692,10 +692,10 @@ export default function ChatRoom({ roomId }) {
692692
return (
693693
<>
694694
<label>
695-
Server URL:
695+
Sunucu URL'i:
696696
<input value={serverUrl} onChange={e => setServerUrl(e.target.value)} />
697697
</label>
698-
<h1>Welcome to the {roomId} room!</h1>
698+
<h1>{roomId} odasına hoşgeldiniz!</h1>
699699
</>
700700
);
701701
}
@@ -715,7 +715,7 @@ export function useChatRoom({ serverUrl, roomId }) {
715715
const connection = createConnection(options);
716716
connection.connect();
717717
connection.on('message', (msg) => {
718-
showNotification('New message: ' + msg);
718+
showNotification('Yeni mesaj: ' + msg);
719719
});
720720
return () => connection.disconnect();
721721
}, [roomId, serverUrl]);
@@ -724,40 +724,40 @@ export function useChatRoom({ serverUrl, roomId }) {
724724
725725
```js chat.js
726726
export function createConnection({ serverUrl, roomId }) {
727-
// A real implementation would actually connect to the server
727+
// Gerçek bir uygulama sunucuya gerçekten bağlanacaktır
728728
if (typeof serverUrl !== 'string') {
729-
throw Error('Expected serverUrl to be a string. Received: ' + serverUrl);
729+
throw Error(`serverUrl'in bir string olması bekleniyordu. Alınan: ` + serverUrl);
730730
}
731731
if (typeof roomId !== 'string') {
732-
throw Error('Expected roomId to be a string. Received: ' + roomId);
732+
throw Error(`roomId'nin bir string olması bekleniyordu. Alınan: ` + roomId);
733733
}
734734
let intervalId;
735735
let messageCallback;
736736
return {
737737
connect() {
738-
console.log('Connecting to "' + roomId + '" room at ' + serverUrl + '...');
738+
console.log('' + serverUrl + `'deki` + roomId + ' odasına bağlanılıyor...')
739739
clearInterval(intervalId);
740740
intervalId = setInterval(() => {
741741
if (messageCallback) {
742742
if (Math.random() > 0.5) {
743743
messageCallback('hey')
744744
} else {
745-
messageCallback('lol');
745+
messageCallback('acayip komik');
746746
}
747747
}
748748
}, 3000);
749749
},
750750
disconnect() {
751751
clearInterval(intervalId);
752752
messageCallback = null;
753-
console.log('Disconnected from "' + roomId + '" room at ' + serverUrl + '');
753+
console.log('❌ ' + serverUrl + `'deki` + roomId + ' odasından ayrılındı')
754754
},
755755
on(event, callback) {
756756
if (messageCallback) {
757-
throw Error('Cannot add the handler twice.');
757+
throw Error('İki kez yönetici eklenemez.');
758758
}
759759
if (event !== 'message') {
760-
throw Error('Only "message" event is supported.');
760+
throw Error('Sadece "message" olayı destekleniyor.');
761761
}
762762
messageCallback = callback;
763763
},
@@ -806,7 +806,7 @@ button { margin-left: 10px; }
806806
```
807807
808808
</Sandpack>
809-
809+
// TODO: Continue from here
810810
Notice how you're taking the return value of one Hook:
811811

812812
```js {2}

0 commit comments

Comments
 (0)