Skip to content

Commit 9bf15fb

Browse files
ZacharyBearYucohny
andauthored
docs(cn): update learn/synchronizing-with-effects translation (#1270)
Co-authored-by: Yucohny <[email protected]>
1 parent acef23f commit 9bf15fb

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/content/learn/synchronizing-with-effects.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: ' Effect 同步'
2+
title: '使用 Effect 同步'
33
---
44

55
<Intro>
@@ -307,7 +307,7 @@ function VideoPlayer({ src, isPlaying }) {
307307
console.log('调用 video.pause()');
308308
ref.current.pause();
309309
}
310-
}, []); // 浙江产生错误
310+
}, []); // 这将产生错误
311311

312312
return <video ref={ref} src={src} loop playsInline />;
313313
}
@@ -510,7 +510,7 @@ export function createConnection() {
510510
console.log('✅ 连接中……');
511511
},
512512
disconnect() {
513-
console.log('连接失败');
513+
console.log('连接断开');
514514
}
515515
};
516516
}
@@ -568,7 +568,7 @@ export function createConnection() {
568568
console.log('✅ 连接中……');
569569
},
570570
disconnect() {
571-
console.log('连接失败');
571+
console.log('连接断开');
572572
}
573573
};
574574
}
@@ -583,7 +583,7 @@ input { display: block; margin-bottom: 20px; }
583583
现在在开发模式下,控制台会打印三条记录:
584584
585585
1. `"✅ 连接中……"`
586-
2. `"连接失败"`
586+
2. `"连接断开"`
587587
3. `"✅ 连接中……"`
588588
589589
**在开发环境下,出现这样的结果才是符合预期的**。重复挂载组件,可以确保在 React 中离开和返回页面时不会导致代码运行出现问题。上面的代码中规定了挂载组件时连接服务器、卸载组件时断连服务器。所以断开、连接再重新连接是符合预期的行为。当为 Effect 正确实现清理函数时,无论 Effect 执行一次,还是执行、清理、再执行,用户都不会感受到明显的差异。所以,在开发环境下,出现额外的连接、断连时,这是 React 正在调试你的代码。这是很正常的现象,不要试图消除它!

src/sidebarLearn.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@
169169
"path": "/learn/manipulating-the-dom-with-refs"
170170
},
171171
{
172-
"title": "Synchronizing with Effects",
172+
"title": "使用 Effect 同步",
173173
"path": "/learn/synchronizing-with-effects"
174174
},
175175
{

0 commit comments

Comments
 (0)