Skip to content

Commit 0dc7d80

Browse files
authored
docs(en): merge reactjs.org/main into zh-hans.reactjs.org/main @ 6ead1fa (#1695)
2 parents 4e55207 + a33110e commit 0dc7d80

File tree

11 files changed

+29
-71
lines changed

11 files changed

+29
-71
lines changed

postcss.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ module.exports = {
1717
},
1818
},
1919
},
20-
}
20+
};

public/js/jsfiddle-integration-babel.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
// Do not delete or move this file.
66
// Many fiddles reference it so we have to keep it here.
7-
(function() {
7+
(function () {
88
var tag = document.querySelector(
99
'script[type="application/javascript;version=1.7"]'
1010
);
1111
if (!tag || tag.textContent.indexOf('window.onload=function(){') !== -1) {
12-
alert('Bad JSFiddle configuration, please fork the original React JSFiddle');
12+
alert(
13+
'Bad JSFiddle configuration, please fork the original React JSFiddle'
14+
);
1315
}
1416
tag.setAttribute('type', 'text/babel');
1517
tag.textContent = tag.textContent.replace(/^\/\/<!\[CDATA\[/, '');

public/js/jsfiddle-integration.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
// Do not delete or move this file.
66
// Many fiddles reference it so we have to keep it here.
7-
(function() {
7+
(function () {
88
var tag = document.querySelector(
99
'script[type="application/javascript;version=1.7"]'
1010
);
1111
if (!tag || tag.textContent.indexOf('window.onload=function(){') !== -1) {
12-
alert('Bad JSFiddle configuration, please fork the original React JSFiddle');
12+
alert(
13+
'Bad JSFiddle configuration, please fork the original React JSFiddle'
14+
);
1315
}
1416
tag.setAttribute('type', 'text/jsx;harmony=true');
1517
tag.textContent = tag.textContent.replace(/^\/\/<!\[CDATA\[/, '');

src/components/MDX/Sandpack/template.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ root.render(
2828
eject: 'react-scripts eject',
2929
},
3030
dependencies: {
31-
react: '19.0.0-rc-3edc000d-20240926',
32-
'react-dom': '19.0.0-rc-3edc000d-20240926',
31+
react: '^19.1.0',
32+
'react-dom': '^19.1.0',
3333
'react-scripts': '^5.0.0',
3434
},
3535
},

src/content/community/meetups.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Do you have a local React.js meetup? Add it here! (Please keep the list alphabet
8181
* [Thessaloniki](https://www.meetup.com/Thessaloniki-ReactJS-Meetup/)
8282

8383
## India {/*india*/}
84-
* [Ahmedabad](https://www.meetup.com/react-ahmedabad/)
84+
* [Ahmedabad](https://reactahmedabad.dev/)
8585
* [Bangalore (React)](https://www.meetup.com/ReactJS-Bangalore/)
8686
* [Bangalore (React Native)](https://www.meetup.com/React-Native-Bangalore-Meetup)
8787
* [Chennai](https://www.linkedin.com/company/chennaireact)
@@ -169,6 +169,7 @@ Do you have a local React.js meetup? Add it here! (Please keep the list alphabet
169169
* [Cleveland, OH - ReactJS](https://www.meetup.com/Cleveland-React/)
170170
* [Columbus, OH - ReactJS](https://www.meetup.com/ReactJS-Columbus-meetup/)
171171
* [Dallas, TX - ReactJS](https://www.meetup.com/ReactDallas/)
172+
* [Denver, CO - React Denver](https://reactdenver.com/)
172173
* [Detroit, MI - Detroit React User Group](https://www.meetup.com/Detroit-React-User-Group/)
173174
* [Indianapolis, IN - React.Indy](https://www.meetup.com/React-Indy)
174175
* [Irvine, CA - ReactJS](https://www.meetup.com/ReactJS-OC/)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ export function useOnlineStatus() {
13331333
13341334
在上述示例中,`useOnlineStatus` 借助一组 [`useState`](/reference/react/useState) 和 [`useEffect`](/reference/react/useEffect) 实现。但这不是最好的解决方案。它有许多边界用例没有考虑到。例如,它认为当组件加载时,`isOnline` 已经为 `true`,但是如果网络已经离线的话这就是错误的。你可以使用浏览器的 [`navigator.onLine`](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/onLine) API 来检查,但是在生成初始 HTML 的服务端直接使用它是没用的。简而言之这段代码可以改进。
13351335
1336-
幸运的是,React 18 包含了一个叫做 [`useSyncExternalStore`](/reference/react/useSyncExternalStore) 的专用 API,它可以解决你所有这些问题。这里展示了如何利用这个新 API 来重写你的 `useOnlineStatus` Hook:
1336+
React 包含了一个叫做 [`useSyncExternalStore`](/reference/react/useSyncExternalStore) 的专用 API,它可以解决你所有这些问题。这里展示了如何利用这个新 API 来重写你的 `useOnlineStatus` Hook:
13371337
13381338
<Sandpack>
13391339

src/content/reference/react/Component.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ button { margin-left: 10px; }
12731273

12741274
要实现错误边界组件,你需要提供 [`static getDerivedStateFromError`](#static-getderivedstatefromerror),它允许你更新状态以响应错误并向用户显示错误消息。你还可以选择实现 [`componentDidCatch`](#componentdidcatch) 来添加一些额外的逻辑,例如将错误添加到分析服务。
12751275

1276-
<CanaryBadge /> With [`captureOwnerStack`](/reference/react/captureOwnerStack) you can include the Owner Stack during development.
1276+
With [`captureOwnerStack`](/reference/react/captureOwnerStack) you can include the Owner Stack during development.
12771277

12781278
```js {9-12,14-27}
12791279
import * as React from 'react';
@@ -1298,7 +1298,6 @@ class ErrorBoundary extends React.Component {
12981298
// 在 div 中(由 APP 创建)
12991299
// 在 App 中
13001300
info.componentStack,
1301-
// 仅在 react@canary 版本可用
13021301
// 警告:Owner Stack 在生产中不可用
13031302
React.captureOwnerStack(),
13041303
);

src/content/reference/react/StrictMode.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function App() {
124124

125125
<Note>
126126

127-
When `StrictMode` is enabled for a part of the app, React will only enable behaviors that are possible in production. For example, if `<StrictMode>` is not enabled at the root of the app, it will not [re-run Effects an extra time](#fixing-bugs-found-by-cleaning-up-and-re-attaching-dom-refs-in-development) on initial mount, since this would cause child effects to double fire without the parent effects, which cannot happen in production.
127+
When `StrictMode` is enabled for a part of the app, React will only enable behaviors that are possible in production. For example, if `<StrictMode>` is not enabled at the root of the app, it will not [re-run Effects an extra time](#fixing-bugs-found-by-re-running-effects-in-development) on initial mount, since this would cause child effects to double fire without the parent effects, which cannot happen in production.
128128

129129
</Note>
130130

src/content/reference/react/captureOwnerStack.md

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -120,22 +120,6 @@ createRoot(document.createElement('div'), {
120120
);
121121
```
122122

123-
```json package.json hidden
124-
{
125-
"dependencies": {
126-
"react": "canary",
127-
"react-dom": "canary",
128-
"react-scripts": "latest"
129-
},
130-
"scripts": {
131-
"start": "react-scripts start",
132-
"build": "react-scripts build",
133-
"test": "react-scripts test --env=jsdom",
134-
"eject": "react-scripts eject"
135-
}
136-
}
137-
```
138-
139123
```html public/index.html hidden
140124
<!DOCTYPE html>
141125
<html lang="en">
@@ -351,22 +335,6 @@ const container = document.getElementById("root");
351335
createRoot(container).render(<App />);
352336
```
353337

354-
```json package.json hidden
355-
{
356-
"dependencies": {
357-
"react": "canary",
358-
"react-dom": "canary",
359-
"react-scripts": "latest"
360-
},
361-
"scripts": {
362-
"start": "react-scripts start",
363-
"build": "react-scripts build",
364-
"test": "react-scripts test --env=jsdom",
365-
"eject": "react-scripts eject"
366-
}
367-
}
368-
```
369-
370338
```js src/App.js
371339
function Component() {
372340
return <button onClick={() => console.error('Some console error')}>Trigger console.error()</button>;
@@ -411,22 +379,6 @@ export default function App() {
411379
}
412380
```
413381

414-
```json package.json hidden
415-
{
416-
"dependencies": {
417-
"react": "canary",
418-
"react-dom": "canary",
419-
"react-scripts": "latest"
420-
},
421-
"scripts": {
422-
"start": "react-scripts start",
423-
"build": "react-scripts build",
424-
"test": "react-scripts test --env=jsdom",
425-
"eject": "react-scripts eject"
426-
}
427-
}
428-
```
429-
430382
</Sandpack>
431383

432384
### `captureOwnerStack` is not available {/*captureownerstack-is-not-available*/}

src/content/reference/react/useId.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ function PasswordField() {
4646
4747
* `useId` **不应该被用来生成列表中的 key**。[key 应该由你的数据生成](/learn/rendering-lists#where-to-get-your-key)。
4848
49+
* `useId` currently cannot be used in [async Server Components](/reference/rsc/server-components#async-components-with-server-components).
50+
4951
---
5052
5153
## 用法 {/*usage*/}

src/content/reference/react/useSyncExternalStore.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -405,43 +405,43 @@ function getSnapshot() {
405405
406406
这里的 `subscribe` 函数是在组件 **内部** 定义的,所以它每次渲染都不同:
407407
408-
```js {4-7}
408+
```js {2-5}
409409
function ChatIndicator() {
410-
const isOnline = useSyncExternalStore(subscribe, getSnapshot);
411-
412410
// 🚩 总是不同的函数,所以 React 每次重新渲染都会重新订阅
413411
function subscribe() {
414412
// ...
415413
}
414+
415+
const isOnline = useSyncExternalStore(subscribe, getSnapshot);
416416

417417
// ...
418418
}
419419
```
420420
421421
如果重新渲染时你传一个不同的 `subscribe` 函数,React 会重新订阅你的 store。如果这造成了性能问题,因而你想避免重新订阅,就把 `subscribe` 函数移到外面:
422422
423-
```js {6-9}
424-
function ChatIndicator() {
425-
const isOnline = useSyncExternalStore(subscribe, getSnapshot);
423+
```js {1-4}
424+
// ✅ 总是相同的函数,所以 React 不需要重新订阅
425+
function subscribe() {
426426
// ...
427427
}
428428

429-
// ✅ 总是相同的函数,所以 React 不需要重新订阅
430-
function subscribe() {
429+
function ChatIndicator() {
430+
const isOnline = useSyncExternalStore(subscribe, getSnapshot);
431431
// ...
432432
}
433433
```
434434
435435
或者,把 `subscribe` 包在 [`useCallback`](/reference/react/useCallback) 里面以便只在某些参数改变时重新订阅:
436436
437-
```js {4-8}
437+
```js {2-5}
438438
function ChatIndicator({ userId }) {
439-
const isOnline = useSyncExternalStore(subscribe, getSnapshot);
440-
441439
// ✅ 只要 userId 不变,都是同一个函数
442440
const subscribe = useCallback(() => {
443441
// ...
444442
}, [userId]);
443+
444+
const isOnline = useSyncExternalStore(subscribe, getSnapshot);
445445

446446
// ...
447447
}

0 commit comments

Comments
 (0)