Skip to content

Commit 278f926

Browse files
authored
docs(en): merge reactjs.org/main into zh-hans.reactjs.org/main @ 7ab1969 (#1715)
2 parents fb6916a + eddbf3f commit 278f926

17 files changed

+186
-16
lines changed
75.6 KB
Binary file not shown.
64.9 KB
Binary file not shown.
Binary file not shown.

src/components/MDX/Sandpack/template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export const template = {
22
'/src/index.js': {
33
hidden: true,
4-
code: `import React, { StrictMode } from "react";
4+
code: `import { StrictMode } from "react";
55
import { createRoot } from "react-dom/client";
66
import "./styles.css";
77

src/components/PageHeading.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ function PageHeading({
2727
tags = [],
2828
breadcrumbs,
2929
}: PageHeadingProps) {
30-
console.log('version', version);
3130
return (
3231
<div className="px-5 sm:px-12 pt-3.5">
3332
<div className="max-w-4xl ms-0 2xl:mx-auto">

src/components/Seo.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,14 @@ export const Seo = withRouter(
124124
)}
125125
<link
126126
rel="preload"
127-
href="/fonts/Source-Code-Pro-Regular.woff2"
127+
href="https://react.dev/fonts/Source-Code-Pro-Regular.woff2"
128+
as="font"
129+
type="font/woff2"
130+
crossOrigin="anonymous"
131+
/>
132+
<link
133+
rel="preload"
134+
href="https://react.dev/fonts/Source-Code-Pro-Bold.woff2"
128135
as="font"
129136
type="font/woff2"
130137
crossOrigin="anonymous"

src/content/community/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ Stack Overflow 是非常受欢迎的论坛,在论坛中,你可以提出代
2929

3030
## 新闻 {/*news*/}
3131

32-
关于 React 的最新消息,请在 Twitter 上关注 [**@reactjs**](https://twitter.com/reactjs),同时关注本站中的 [React 的官方博客](/blog/)
32+
关于 React 的最新消息,请在 Twitter 上关注 [**@reactjs**](https://twitter.com/reactjs)、 在 Bluesky 关注 [**@react.dev**](https://bsky.app/profile/react.dev) 以及关注本站的 [React 的官方博客](/blog/)

src/content/community/meetups.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Do you have a local React.js meetup? Add it here! (Please keep the list alphabet
3838

3939
## Canada {/*canada*/}
4040
* [Halifax, NS](https://www.meetup.com/Halifax-ReactJS-Meetup/)
41-
* [Montreal, QC - React Native](https://www.meetup.com/fr-FR/React-Native-MTL/)
41+
* [Montreal, QC](https://guild.host/react-montreal/)
4242
* [Vancouver, BC](https://www.meetup.com/ReactJS-Vancouver-Meetup/)
4343
* [Ottawa, ON](https://www.meetup.com/Ottawa-ReactJS-Meetup/)
4444
* [Saskatoon, SK](https://www.meetup.com/saskatoon-react-meetup/)

src/content/learn/build-a-react-app-from-scratch.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ React 生态系统中包含许多用于解决这些问题的工具。我们列
116116
通过路由拆分代码,并与打包和数据获取集成,可以减少应用程序的初始加载时间以及渲染应用程序最大可见内容所需的时间 ([最大内容绘制](https://web.dev/articles/lcp))。
117117

118118
有关代码拆分的说明,请参阅你的构建工具文档:
119-
- [Vite 构建优化](https://v3.vitejs.dev/guide/features.html#build-optimizations)
119+
- [Vite 构建优化](https://vite.dev/guide/features.html#build-optimizations)
120120
- [Parcel 代码拆分](https://parceljs.org/features/code-splitting/)
121121
- [Rsbuild 代码拆分](https://rsbuild.dev/guide/optimization/code-splitting)
122122

src/content/learn/preserving-and-resetting-state.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,7 +2016,7 @@ export default function ContactList() {
20162016
<label>
20172017
<input
20182018
type="checkbox"
2019-
value={reverse}
2019+
checked={reverse}
20202020
onChange={e => {
20212021
setReverse(e.target.checked)
20222022
}}
@@ -2115,7 +2115,7 @@ export default function ContactList() {
21152115
<label>
21162116
<input
21172117
type="checkbox"
2118-
value={reverse}
2118+
checked={reverse}
21192119
onChange={e => {
21202120
setReverse(e.target.checked)
21212121
}}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2081,7 +2081,6 @@ export function useCounter(delay) {
20812081
<Sandpack>
20822082
20832083
```js
2084-
import { useState } from 'react';
20852084
import { useCounter } from './useCounter.js';
20862085

20872086
export default function Counter() {

src/content/learn/separating-events-from-effects.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ function ChatRoom({ roomId, theme }) {
439439
// ...
440440
```
441441
442-
这个方法解决了问题。注意你必须从 Effect 依赖项中 **移除** `onConnected`**Effect Event 是非响应式的并且必须从依赖项中删除**。
442+
这个方法解决了问题。注意你必须从 Effect 依赖项中 **移除** `theme`,因为 Effect 中没有使用它。你也不需要 **添加** `onConnected`,因为 **Effect Event 是非响应式的并且必须从依赖项中删除**。
443443
444444
验证新表现是否和你预期的一样:
445445

src/content/reference/react/useTransition.md

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,3 +1949,162 @@ export async function updateQuantity(newName) {
19491949
这是预期内的,因为在 Transition 中的 Action 不保证执行顺序。对于常见用例,React 提供了更高级的抽象,如 [`useActionState`](/reference/react/useActionState) 和 [`<form>` actions](/reference/react-dom/components/form) 来为你处理顺序问题。对于高级用例,你需要自行实现队列和中止逻辑来处理这种情况。
19501950
19511951
1952+
Example of `useActionState` handling execution order:
1953+
1954+
<Sandpack>
1955+
1956+
```json package.json hidden
1957+
{
1958+
"dependencies": {
1959+
"react": "beta",
1960+
"react-dom": "beta"
1961+
},
1962+
"scripts": {
1963+
"start": "react-scripts start",
1964+
"build": "react-scripts build",
1965+
"test": "react-scripts test --env=jsdom",
1966+
"eject": "react-scripts eject"
1967+
}
1968+
}
1969+
```
1970+
1971+
```js src/App.js
1972+
import { useState, useActionState } from "react";
1973+
import { updateQuantity } from "./api";
1974+
import Item from "./Item";
1975+
import Total from "./Total";
1976+
1977+
export default function App({}) {
1978+
// Store the actual quantity in separate state to show the mismatch.
1979+
const [clientQuantity, setClientQuantity] = useState(1);
1980+
const [quantity, updateQuantityAction, isPending] = useActionState(
1981+
async (prevState, payload) => {
1982+
setClientQuantity(payload);
1983+
const savedQuantity = await updateQuantity(payload);
1984+
return savedQuantity; // Return the new quantity to update the state
1985+
},
1986+
1 // Initial quantity
1987+
);
1988+
1989+
return (
1990+
<div>
1991+
<h1>Checkout</h1>
1992+
<Item action={updateQuantityAction}/>
1993+
<hr />
1994+
<Total clientQuantity={clientQuantity} savedQuantity={quantity} isPending={isPending} />
1995+
</div>
1996+
);
1997+
}
1998+
1999+
```
2000+
2001+
```js src/Item.js
2002+
import {startTransition} from 'react';
2003+
2004+
export default function Item({action}) {
2005+
function handleChange(e) {
2006+
// Update the quantity in an Action.
2007+
startTransition(() => {
2008+
action(e.target.value);
2009+
});
2010+
}
2011+
return (
2012+
<div className="item">
2013+
<span>Eras Tour Tickets</span>
2014+
<label htmlFor="name">Quantity: </label>
2015+
<input
2016+
type="number"
2017+
onChange={handleChange}
2018+
defaultValue={1}
2019+
min={1}
2020+
/>
2021+
</div>
2022+
)
2023+
}
2024+
```
2025+
2026+
```js src/Total.js
2027+
const intl = new Intl.NumberFormat("en-US", {
2028+
style: "currency",
2029+
currency: "USD"
2030+
});
2031+
2032+
export default function Total({ clientQuantity, savedQuantity, isPending }) {
2033+
return (
2034+
<div className="total">
2035+
<span>Total:</span>
2036+
<div>
2037+
<div>
2038+
{isPending
2039+
? "🌀 Updating..."
2040+
: `${intl.format(savedQuantity * 9999)}`}
2041+
</div>
2042+
<div className="error">
2043+
{!isPending &&
2044+
clientQuantity !== savedQuantity &&
2045+
`Wrong total, expected: ${intl.format(clientQuantity * 9999)}`}
2046+
</div>
2047+
</div>
2048+
</div>
2049+
);
2050+
}
2051+
```
2052+
2053+
```js src/api.js
2054+
let firstRequest = true;
2055+
export async function updateQuantity(newName) {
2056+
return new Promise((resolve, reject) => {
2057+
if (firstRequest === true) {
2058+
firstRequest = false;
2059+
setTimeout(() => {
2060+
firstRequest = true;
2061+
resolve(newName);
2062+
// Simulate every other request being slower
2063+
}, 1000);
2064+
} else {
2065+
setTimeout(() => {
2066+
resolve(newName);
2067+
}, 50);
2068+
}
2069+
});
2070+
}
2071+
```
2072+
2073+
```css
2074+
.item {
2075+
display: flex;
2076+
align-items: center;
2077+
justify-content: start;
2078+
}
2079+
2080+
.item label {
2081+
flex: 1;
2082+
text-align: right;
2083+
}
2084+
2085+
.item input {
2086+
margin-left: 4px;
2087+
width: 60px;
2088+
padding: 4px;
2089+
}
2090+
2091+
.total {
2092+
height: 50px;
2093+
line-height: 25px;
2094+
display: flex;
2095+
align-content: center;
2096+
justify-content: space-between;
2097+
}
2098+
2099+
.total div {
2100+
display: flex;
2101+
flex-direction: column;
2102+
align-items: flex-end;
2103+
}
2104+
2105+
.error {
2106+
color: red;
2107+
}
2108+
```
2109+
2110+
</Sandpack>

src/content/reference/rsc/server-functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ To support Server Functions as a bundler or framework, we recommend pinning to a
2828

2929
</Note>
3030

31-
When a Server Functions is defined with the [`"use server"`](/reference/rsc/use-server) directive, your framework will automatically create a reference to the server function, and pass that reference to the Client Component. When that function is called on the client, React will send a request to the server to execute the function, and return the result.
31+
When a Server Function is defined with the [`"use server"`](/reference/rsc/use-server) directive, your framework will automatically create a reference to the server function, and pass that reference to the Client Component. When that function is called on the client, React will send a request to the server to execute the function, and return the result.
3232

3333
Server Functions can be created in Server Components and passed as props to Client Components, or they can be imported and used in Client Components.
3434

src/content/warnings/react-dom-test-utils.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
title: react-dom/test-utils Deprecation Warnings
33
---
44

5-
TODO: update for 19?
6-
75
## ReactDOMTestUtils.act() warning {/*reactdomtestutilsact-warning*/}
86

97
`act` from `react-dom/test-utils` has been deprecated in favor of `act` from `react`.

src/content/warnings/react-test-renderer.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
title: react-test-renderer Deprecation Warnings
33
---
44

5-
TODO: Update this for 19?
6-
75
## ReactTestRenderer.create() warning {/*reacttestrenderercreate-warning*/}
86

97
react-test-renderer is deprecated. A warning will fire whenever calling ReactTestRenderer.create() or ReactShallowRender.render(). The react-test-renderer package will remain available on NPM but will not be maintained and may break with new React features or changes to React's internals.

src/styles/index.css

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@
1212
font-style: normal;
1313
font-weight: 400;
1414
font-display: swap;
15-
src: url('/fonts/Source-Code-Pro-Regular.woff2') format('woff2');
15+
src: url('https://react.dev/fonts/Source-Code-Pro-Regular.woff2')
16+
format('woff2');
17+
}
18+
19+
@font-face {
20+
font-family: 'Source Code Pro';
21+
font-style: normal;
22+
font-weight: 700;
23+
font-display: swap;
24+
src: url('https://react.dev/fonts/Source-Code-Pro-Bold.woff2')
25+
format('woff2');
1626
}
1727

1828
/* Latin */

0 commit comments

Comments
 (0)