Skip to content

Commit 84a0cda

Browse files
merging all conflicts
2 parents 66c88e3 + 49c2d26 commit 84a0cda

File tree

9 files changed

+230
-70
lines changed

9 files changed

+230
-70
lines changed

src/content/blog/2025/04/23/react-labs-view-transitions-activity-and-more.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14303,7 +14303,11 @@ useEffect(() => {
1430314303
}); // 编译器插入的依赖项。
1430414304
```
1430514305

14306+
<<<<<<< HEAD
1430614307
使用这段代码,React 编译器可以为你推断依赖项并自动插入它们,这样你就不需要看到或编写它们。通过像[IDE 扩展](#compiler-ide-extension)[`useEffectEvent`](/reference/react/experimental_useEffectEvent)这样的功能,我们可以提供一个 CodeLens 来显示编译器在你需要调试时插入的内容,或通过移除依赖项来优化。这有助于强化编写 Effects 的正确心智模型,即 Effects 可以在任何时候运行,以将你的组件或 hook 的状态与其他内容同步。
14308+
=======
14309+
With this code, the React Compiler can infer the dependencies for you and insert them automatically so you don't need to see or write them. With features like [the IDE extension](#compiler-ide-extension) and [`useEffectEvent`](/reference/react/useEffectEvent), we can provide a CodeLens to show you what the Compiler inserted for times you need to debug, or to optimize by removing a dependency. This helps reinforce the correct mental model for writing Effects, which can run at any time to synchronize your component or hook's state with something else.
14310+
>>>>>>> 49c2d26722fb1b5865ce0221a4cadc71b615e4cf
1430714311
1430814312
我们希望自动插入依赖项不仅更容易编写,而且通过迫使你从 Effect 的作用角度思考,而不是从组件生命周期角度思考,使它们更容易理解。
1430914313

src/content/learn/escape-hatches.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,8 +455,8 @@ label { display: block; margin-top: 10px; }
455455
```json package.json hidden
456456
{
457457
"dependencies": {
458-
"react": "experimental",
459-
"react-dom": "experimental",
458+
"react": "canary",
459+
"react-dom": "canary",
460460
"react-scripts": "latest",
461461
"toastify-js": "1.12.0"
462462
},
@@ -471,7 +471,7 @@ label { display: block; margin-top: 10px; }
471471

472472
```js
473473
import { useState, useEffect } from 'react';
474-
import { experimental_useEffectEvent as useEffectEvent } from 'react';
474+
import { useEffectEvent } from 'react';
475475
import { createConnection, sendMessage } from './chat.js';
476476
import { showNotification } from './notifications.js';
477477

src/content/learn/removing-effect-dependencies.md

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -610,11 +610,17 @@ function ChatRoom({ roomId }) {
610610
611611
### 你想读取一个值而不对其变化做出“反应”吗? {/*do-you-want-to-read-a-value-without-reacting-to-its-changes*/}
612612
613-
<Wip>
613+
<Canary>
614614
615+
<<<<<<< HEAD
615616
本节描述了一个在稳定版本的 React 中 **尚未发布的实验性** API。
617+
=======
618+
**The `useEffectEvent` API is currently only available in React’s Canary and Experimental channels.**
619+
>>>>>>> 49c2d26722fb1b5865ce0221a4cadc71b615e4cf
616620
617-
</Wip>
621+
[Learn more about React’s release channels here.](/community/versioning-policy#all-release-channels)
622+
623+
</Canary>
618624
619625
假设你希望在用户收到新消息时播放声音,`isMuted``true` 除外:
620626
@@ -1261,8 +1267,8 @@ Effect 中是否有一行代码不应该是响应式的?如何将非响应式
12611267
```json package.json hidden
12621268
{
12631269
"dependencies": {
1264-
"react": "experimental",
1265-
"react-dom": "experimental",
1270+
"react": "canary",
1271+
"react-dom": "canary",
12661272
"react-scripts": "latest"
12671273
},
12681274
"scripts": {
@@ -1276,7 +1282,7 @@ Effect 中是否有一行代码不应该是响应式的?如何将非响应式
12761282
12771283
```js
12781284
import { useState, useEffect, useRef } from 'react';
1279-
import { experimental_useEffectEvent as useEffectEvent } from 'react';
1285+
import { useEffectEvent } from 'react';
12801286
import { FadeInAnimation } from './animation.js';
12811287

12821288
function Welcome({ duration }) {
@@ -1388,8 +1394,8 @@ Effect 需要读取 `duration` 的最新值,但你不希望它对 `duration`
13881394
```json package.json hidden
13891395
{
13901396
"dependencies": {
1391-
"react": "experimental",
1392-
"react-dom": "experimental",
1397+
"react": "canary",
1398+
"react-dom": "canary",
13931399
"react-scripts": "latest"
13941400
},
13951401
"scripts": {
@@ -1404,7 +1410,7 @@ Effect 需要读取 `duration` 的最新值,但你不希望它对 `duration`
14041410
```js
14051411
import { useState, useEffect, useRef } from 'react';
14061412
import { FadeInAnimation } from './animation.js';
1407-
import { experimental_useEffectEvent as useEffectEvent } from 'react';
1413+
import { useEffectEvent } from 'react';
14081414

14091415
function Welcome({ duration }) {
14101416
const ref = useRef(null);
@@ -1824,8 +1830,8 @@ label, button { display: block; margin-bottom: 5px; }
18241830
```json package.json hidden
18251831
{
18261832
"dependencies": {
1827-
"react": "experimental",
1828-
"react-dom": "experimental",
1833+
"react": "canary",
1834+
"react-dom": "canary",
18291835
"react-scripts": "latest",
18301836
"toastify-js": "1.12.0"
18311837
},
@@ -1906,7 +1912,7 @@ export default function App() {
19061912
19071913
```js src/ChatRoom.js active
19081914
import { useState, useEffect } from 'react';
1909-
import { experimental_useEffectEvent as useEffectEvent } from 'react';
1915+
import { useEffectEvent } from 'react';
19101916

19111917
export default function ChatRoom({ roomId, createConnection, onMessage }) {
19121918
useEffect(() => {
@@ -2119,8 +2125,8 @@ export default function ChatRoom({ roomId, isEncrypted, onMessage }) { // Reacti
21192125
```json package.json hidden
21202126
{
21212127
"dependencies": {
2122-
"react": "experimental",
2123-
"react-dom": "experimental",
2128+
"react": "canary",
2129+
"react-dom": "canary",
21242130
"react-scripts": "latest",
21252131
"toastify-js": "1.12.0"
21262132
},
@@ -2188,7 +2194,7 @@ export default function App() {
21882194
21892195
```js src/ChatRoom.js active
21902196
import { useState, useEffect } from 'react';
2191-
import { experimental_useEffectEvent as useEffectEvent } from 'react';
2197+
import { useEffectEvent } from 'react';
21922198
import {
21932199
createEncryptedConnection,
21942200
createUnencryptedConnection,

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -837,11 +837,17 @@ export default function ChatRoom({ roomId }) {
837837
838838
### 把事件处理函数传到自定义 Hook 中 {/*passing-event-handlers-to-custom-hooks*/}
839839
840-
<Wip>
840+
<Canary>
841841
842+
<<<<<<< HEAD
842843
这个章节描述了 React 稳定版 **还未发布的一个实验性 API**。
844+
=======
845+
**The `useEffectEvent` API is currently only available in React’s Canary and Experimental channels.**
846+
>>>>>>> 49c2d26722fb1b5865ce0221a4cadc71b615e4cf
843847
844-
</Wip>
848+
[Learn more about React’s release channels here.](/community/versioning-policy#all-release-channels)
849+
850+
</Canary>
845851
846852
当你在更多组件中使用 `useChatRoom` 时,你可能希望组件能定制它的行为。例如现在 Hook 内部收到消息的处理逻辑是硬编码:
847853
@@ -985,7 +991,7 @@ export default function ChatRoom({ roomId }) {
985991
986992
```js src/useChatRoom.js
987993
import { useEffect } from 'react';
988-
import { experimental_useEffectEvent as useEffectEvent } from 'react';
994+
import { useEffectEvent } from 'react';
989995
import { createConnection } from './chat.js';
990996

991997
export function useChatRoom({ serverUrl, roomId, onReceiveMessage }) {
@@ -1070,8 +1076,8 @@ export function showNotification(message, theme = 'dark') {
10701076
```json package.json hidden
10711077
{
10721078
"dependencies": {
1073-
"react": "experimental",
1074-
"react-dom": "experimental",
1079+
"react": "canary",
1080+
"react-dom": "canary",
10751081
"react-scripts": "latest",
10761082
"toastify-js": "1.12.0"
10771083
},
@@ -1666,7 +1672,7 @@ export default function App() {
16661672
16671673
```js src/useFadeIn.js active
16681674
import { useState, useEffect } from 'react';
1669-
import { experimental_useEffectEvent as useEffectEvent } from 'react';
1675+
import { useEffectEvent } from 'react';
16701676

16711677
export function useFadeIn(ref, duration) {
16721678
const [isRunning, setIsRunning] = useState(true);
@@ -1719,8 +1725,8 @@ html, body { min-height: 300px; }
17191725
```json package.json hidden
17201726
{
17211727
"dependencies": {
1722-
"react": "experimental",
1723-
"react-dom": "experimental",
1728+
"react": "canary",
1729+
"react-dom": "canary",
17241730
"react-scripts": "latest"
17251731
},
17261732
"scripts": {
@@ -2208,8 +2214,8 @@ export function useInterval(onTick, delay) {
22082214
```json package.json hidden
22092215
{
22102216
"dependencies": {
2211-
"react": "experimental",
2212-
"react-dom": "experimental",
2217+
"react": "canary",
2218+
"react-dom": "canary",
22132219
"react-scripts": "latest"
22142220
},
22152221
"scripts": {
@@ -2252,7 +2258,7 @@ export function useCounter(delay) {
22522258
22532259
```js src/useInterval.js
22542260
import { useEffect } from 'react';
2255-
import { experimental_useEffectEvent as useEffectEvent } from 'react';
2261+
import { useEffectEvent } from 'react';
22562262

22572263
export function useInterval(onTick, delay) {
22582264
useEffect(() => {
@@ -2279,8 +2285,8 @@ export function useInterval(onTick, delay) {
22792285
```json package.json hidden
22802286
{
22812287
"dependencies": {
2282-
"react": "experimental",
2283-
"react-dom": "experimental",
2288+
"react": "canary",
2289+
"react-dom": "canary",
22842290
"react-scripts": "latest"
22852291
},
22862292
"scripts": {
@@ -2324,7 +2330,7 @@ export function useCounter(delay) {
23242330
23252331
```js src/useInterval.js active
23262332
import { useEffect } from 'react';
2327-
import { experimental_useEffectEvent as useEffectEvent } from 'react';
2333+
import { useEffectEvent } from 'react';
23282334

23292335
export function useInterval(callback, delay) {
23302336
const onTick = useEffectEvent(callback);

0 commit comments

Comments
 (0)