-
-
+
+
);
}
@@ -926,11 +926,11 @@ export function TasksProvider({ children }) {
const [tasks, dispatch] = useReducer(tasksReducer, initialTasks);
return (
-
-
+
+
{children}
-
-
+
+
);
}
```
@@ -968,11 +968,11 @@ export function TasksProvider({ children }) {
);
return (
-
-
+
+
{children}
-
-
+
+
);
}
@@ -1179,11 +1179,11 @@ export function TasksProvider({ children }) {
);
return (
-
-
+
+
{children}
-
-
+
+
);
}
@@ -1368,4 +1368,3 @@ ul, li { margin: 0; padding: 0; }
- 你可以在你的应用程序中大量使用 context 和 reducer 的组合。
-
diff --git a/src/content/learn/typescript.md b/src/content/learn/typescript.md
index f023d54c64..e9b7bfe340 100644
--- a/src/content/learn/typescript.md
+++ b/src/content/learn/typescript.md
@@ -260,9 +260,9 @@ export default function MyApp() {
const [theme, setTheme] = useState('light');
return (
-
+
-
+
)
}
@@ -310,9 +310,9 @@ export default function MyApp() {
const object = useMemo(() => ({ kind: "complex" }), []);
return (
-
+
-
+
)
}
diff --git a/src/content/reference/react-dom/createPortal.md b/src/content/reference/react-dom/createPortal.md
index b309cfb9ec..b57dc17d8c 100644
--- a/src/content/reference/react-dom/createPortal.md
+++ b/src/content/reference/react-dom/createPortal.md
@@ -240,7 +240,11 @@ export default function ModalContent({ onClose }) {
使用 portal 时,确保应用程序的无障碍性非常重要。例如,你可能需要管理键盘焦点,以便用户可以自然进出 portal。
+<<<<<<< HEAD
创建模态对话框时,请遵循 [WAI-ARIA 模态实践指南](https://www.w3.org/WAI/ARIA/apg/#dialog_modal)。如果你使用了社区包,请确保它具有无障碍性,并遵循这些指南。
+=======
+Follow the [WAI-ARIA Modal Authoring Practices](https://www.w3.org/WAI/ARIA/apg/patterns/dialog-modal) when creating modals. If you use a community package, ensure that it is accessible and follows these guidelines.
+>>>>>>> 50d6991ca6652f4bc4c985cf0c0e593864f2cc91
diff --git a/src/content/reference/react-dom/static/prerender.md b/src/content/reference/react-dom/static/prerender.md
index 2a11634e62..1c3b98a57a 100644
--- a/src/content/reference/react-dom/static/prerender.md
+++ b/src/content/reference/react-dom/static/prerender.md
@@ -68,7 +68,7 @@ async function handler(request) {
#### Caveats {/*caveats*/}
-`nonce` is not an available option when prerendering. Nonces must be unique per request and if you use nonces to secure your application with [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP) it would be inappropriate and insecure to include the a nonce value in the prerender itself.
+`nonce` is not an available option when prerendering. Nonces must be unique per request and if you use nonces to secure your application with [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP) it would be inappropriate and insecure to include the nonce value in the prerender itself.
@@ -231,7 +231,7 @@ async function renderToString() {
const {prelude} = await prerender(, {
bootstrapScripts: ['/main.js']
});
-
+
const reader = prelude.getReader();
let content = '';
while (true) {
@@ -318,7 +318,13 @@ async function renderToString() {
### 我的流要等到整个应用渲染完成后才会启动。 {/*my-stream-doesnt-start-until-the-entire-app-is-rendered*/}
+<<<<<<< HEAD
`prerender` 的响应会等待整个应用渲染完成,包括所有 Suspense 边界的内容加载完成后,才会解析。这种设计适用于静态站点生成(SSG),并不支持在内容加载时进行流式加载。
如果需要在内容加载时进行流式加载,可以使用类似 [renderToReadableStream](/reference/react-dom/server/renderToReadableStream) 的流式服务器渲染 API。
-
\ No newline at end of file
+
+=======
+The `prerender` response waits for the entire app to finish rendering, including waiting for all Suspense boundaries to resolve, before resolving. It is designed for static site generation (SSG) ahead of time and does not support streaming more content as it loads.
+
+To stream content as it loads, use a streaming server render API like [renderToReadableStream](/reference/react-dom/server/renderToReadableStream).
+>>>>>>> 50d6991ca6652f4bc4c985cf0c0e593864f2cc91
diff --git a/src/content/reference/react-dom/static/prerenderToNodeStream.md b/src/content/reference/react-dom/static/prerenderToNodeStream.md
index fb8073ef07..cc99c52d4e 100644
--- a/src/content/reference/react-dom/static/prerenderToNodeStream.md
+++ b/src/content/reference/react-dom/static/prerenderToNodeStream.md
@@ -69,7 +69,7 @@ On the client, call [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) to
#### Caveats {/*caveats*/}
-`nonce` is not an available option when prerendering. Nonces must be unique per request and if you use nonces to secure your application with [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP) it would be inappropriate and insecure to include the a nonce value in the prerender itself.
+`nonce` is not an available option when prerendering. Nonces must be unique per request and if you use nonces to secure your application with [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP) it would be inappropriate and insecure to include the nonce value in the prerender itself.
@@ -95,7 +95,7 @@ app.use('/', async (request, response) => {
const { prelude } = await prerenderToNodeStream(, {
bootstrapScripts: ['/main.js'],
});
-
+
response.setHeader('Content-Type', 'text/plain');
prelude.pipe(response);
});
@@ -232,7 +232,7 @@ async function renderToString() {
const {prelude} = await prerenderToNodeStream(, {
bootstrapScripts: ['/main.js']
});
-
+
return new Promise((resolve, reject) => {
let data = '';
prelude.on('data', chunk => {
@@ -320,4 +320,3 @@ Any Suspense boundaries with incomplete children will be included in the prelude
The `prerenderToNodeStream` response waits for the entire app to finish rendering, including waiting for all Suspense boundaries to resolve, before resolving. It is designed for static site generation (SSG) ahead of time and does not support streaming more content as it loads.
To stream content as it loads, use a streaming server render API like [renderToPipeableStream](/reference/react-dom/server/renderToPipeableStream).
-
diff --git a/src/content/reference/react/Component.md b/src/content/reference/react/Component.md
index f83eba3c2b..04ab56d72d 100644
--- a/src/content/reference/react/Component.md
+++ b/src/content/reference/react/Component.md
@@ -1814,9 +1814,9 @@ function Form() {
export default function MyApp() {
return (
-
+
-
+
)
}
```
@@ -1900,9 +1900,9 @@ function Form() {
export default function MyApp() {
return (
-
+
-
+
)
}
```
diff --git a/src/content/reference/react/apis.md b/src/content/reference/react/apis.md
index bba46bdae8..d279cc966c 100644
--- a/src/content/reference/react/apis.md
+++ b/src/content/reference/react/apis.md
@@ -13,12 +13,20 @@ translators:
---
+<<<<<<< HEAD
* [`createContext`](/reference/react/createContext) API 可以创建一个 context,你可以将其提供给子组件,通常会与 [`useContext`](/reference/react/useContext) 一起配合使用。
* [`forwardRef`](/reference/react/forwardRef) 允许组件将 DOM 节点作为 ref 暴露给父组件。
* [`lazy`](/reference/react/lazy) 允许你延迟加载组件,直到该组件需要第一次被渲染。
* [`memo`](/reference/react/memo) 允许你在 props 没有变化的情况下跳过组件的重渲染。通常 [`useMemo`](/reference/react/useMemo) 与 [`useCallback`](/reference/react/useCallback) 会一起配合使用。
* [`startTransition`](/reference/react/startTransition) 允许你可以标记一个状态更新是不紧急的。类似于 [`useTransition`](/reference/react/useTransition)。
* [`act`](/reference/react/act) 允许你在测试中包装渲染和交互,以确保在断言之前已完成更新。
+=======
+* [`createContext`](/reference/react/createContext) lets you define and provide context to the child components. Used with [`useContext`.](/reference/react/useContext)
+* [`lazy`](/reference/react/lazy) lets you defer loading a component's code until it's rendered for the first time.
+* [`memo`](/reference/react/memo) lets your component skip re-renders with same props. Used with [`useMemo`](/reference/react/useMemo) and [`useCallback`.](/reference/react/useCallback)
+* [`startTransition`](/reference/react/startTransition) lets you mark a state update as non-urgent. Similar to [`useTransition`.](/reference/react/useTransition)
+* [`act`](/reference/react/act) lets you wrap renders and interactions in tests to ensure updates have processed before making assertions.
+>>>>>>> 50d6991ca6652f4bc4c985cf0c0e593864f2cc91
---
diff --git a/src/content/reference/react/cloneElement.md b/src/content/reference/react/cloneElement.md
index 4050402dad..25457b94de 100644
--- a/src/content/reference/react/cloneElement.md
+++ b/src/content/reference/react/cloneElement.md
@@ -414,9 +414,9 @@ export default function List({ items, renderItem }) {
{items.map((item, index) => {
const isHighlighted = index === selectedIndex;
return (
-
+
{renderItem(item)}
-
+
);
})}
```
@@ -472,12 +472,12 @@ export default function List({ items, renderItem }) {
{items.map((item, index) => {
const isHighlighted = index === selectedIndex;
return (
-
{renderItem(item)}
-
+
);
})}
diff --git a/src/content/reference/react/createContext.md b/src/content/reference/react/createContext.md
index 9ba3f58c09..df84ab0c47 100644
--- a/src/content/reference/react/createContext.md
+++ b/src/content/reference/react/createContext.md
@@ -38,14 +38,22 @@ const ThemeContext = createContext('light');
`createContext` 返回一个上下文对象。
+<<<<<<< HEAD
**该上下文对象本身不包含任何信息**。它只表示其他组件读取或提供的那个上下文。一般来说,在组件上方使用 [`SomeContext.Provider`](#provider) 指定上下文的值,并在被包裹的下方组件内调用 [`useContext(SomeContext)`](/reference/react/useContext) 读取它。上下文对象有一些属性:
* `SomeContext.Provider` 让你为被它包裹的组件提供上下文的值。
* `SomeContext.Consumer` 是一个很少会用到的备选方案,它用于读取上下文的值。
+=======
+**The context object itself does not hold any information.** It represents _which_ context other components read or provide. Typically, you will use [`SomeContext`](#provider) in components above to specify the context value, and call [`useContext(SomeContext)`](/reference/react/useContext) in components below to read it. The context object has a few properties:
+
+* `SomeContext` lets you provide the context value to components.
+* `SomeContext.Consumer` is an alternative and rarely used way to read the context value.
+* `SomeContext.Provider` is a legacy way to provide the context value before React 19.
+>>>>>>> 50d6991ca6652f4bc4c985cf0c0e593864f2cc91
---
-### `SomeContext.Provider` {/*provider*/}
+### `SomeContext` Provider {/*provider*/}
用上下文 provider 包裹组件,以为里面所有的组件指定一个上下文的值:
@@ -54,13 +62,21 @@ function App() {
const [theme, setTheme] = useState('light');
// ……
return (
-
+
-
+
);
}
```
+
+
+Starting in React 19, you can render `` as a provider.
+
+In older versions of React, use ``.
+
+
+
#### Props {/*provider-props*/}
* `value`:该值为想传递给所有处于这个 provider 内读取该上下文的组件,无论它们处于多深的层级。上下文的值可以为任何类型。provider 内的组件可通过调用 [`useContext(SomeContext)`](/reference/react/useContext) 获取上方距离它最近的上下文 provider 的 `value`。
@@ -141,11 +157,11 @@ function App() {
// ...
return (
-
-
+
+
-
-
+
+
);
}
```
@@ -187,11 +203,11 @@ import { ThemeContext, AuthContext } from './Contexts.js';
function App() {
// ...
return (
-
-
+
+
-
-
+
+
);
}
```
@@ -213,5 +229,9 @@ const ThemeContext = createContext('light');
该值永远不会发生改变。当 React 无法找到匹配的 provider 时,该值会被作为后备方案。
+<<<<<<< HEAD
要想使上下文的值随时间变化,[添加状态并使用一个上下文 provider 包裹组件](/reference/react/useContext#updating-data-passed-via-context)。
+=======
+To make context change over time, [add state and wrap components in a context provider.](/reference/react/useContext#updating-data-passed-via-context)
+>>>>>>> 50d6991ca6652f4bc4c985cf0c0e593864f2cc91
diff --git a/src/content/reference/react/legacy.md b/src/content/reference/react/legacy.md
index 3cbc40c89e..62cca6a70a 100644
--- a/src/content/reference/react/legacy.md
+++ b/src/content/reference/react/legacy.md
@@ -27,9 +27,18 @@ title: "过时的 React API"
这些 API 在 React 19 中被移除。
+<<<<<<< HEAD
* [`createFactory`](https://18.react.dev/reference/react/createFactory):使用 JSX 来替代。
* 类组件:[`static contextTypes`](https://18.react.dev//reference/react/Component#static-contexttypes): 使用 [`static contextType`](#static-contexttype) 来替代。
* 类组件:[`static childContextTypes`](https://18.react.dev//reference/react/Component#static-childcontexttypes): 使用 [`static contextType`](#static-contexttype) 来替代。
* 类组件:[`static getChildContext`](https://18.react.dev//reference/react/Component#getchildcontext): 使用 [`Context.Provider`](/reference/react/createContext#provider) 来替代。
* 类组件:[`static propTypes`](https://18.react.dev//reference/react/Component#static-proptypes): 使用 [TypeScript](https://www.typescriptlang.org/) 等类型系统来替代。
* 类组件:[`this.refs`](https://18.react.dev//reference/react/Component#refs): 使用 [`createRef`](/reference/react/createRef) 来替代。
+=======
+* [`createFactory`](https://18.react.dev/reference/react/createFactory): use JSX instead.
+* Class Components: [`static contextTypes`](https://18.react.dev//reference/react/Component#static-contexttypes): use [`static contextType`](#static-contexttype) instead.
+* Class Components: [`static childContextTypes`](https://18.react.dev//reference/react/Component#static-childcontexttypes): use [`static contextType`](#static-contexttype) instead.
+* Class Components: [`static getChildContext`](https://18.react.dev//reference/react/Component#getchildcontext): use [`Context`](/reference/react/createContext#provider) instead.
+* Class Components: [`static propTypes`](https://18.react.dev//reference/react/Component#static-proptypes): use a type system like [TypeScript](https://www.typescriptlang.org/) instead.
+* Class Components: [`this.refs`](https://18.react.dev//reference/react/Component#refs): use [`createRef`](/reference/react/createRef) instead.
+>>>>>>> 50d6991ca6652f4bc4c985cf0c0e593864f2cc91
diff --git a/src/content/reference/react/memo.md b/src/content/reference/react/memo.md
index 6eeac9ac5b..ca9e00ef42 100644
--- a/src/content/reference/react/memo.md
+++ b/src/content/reference/react/memo.md
@@ -226,12 +226,12 @@ export default function MyApp() {
}
return (
-
+
-
+
);
}
diff --git a/src/content/reference/react/use.md b/src/content/reference/react/use.md
index cecded1755..7825e9a8e8 100644
--- a/src/content/reference/react/use.md
+++ b/src/content/reference/react/use.md
@@ -74,9 +74,9 @@ function Button() {
```js [[1, 3, "ThemeContext"], [2, 3, "\\"dark\\""], [1, 5, "ThemeContext"]]
function MyPage() {
return (
-
+
-
+
);
}
@@ -116,9 +116,9 @@ const ThemeContext = createContext(null);
export default function MyApp() {
return (
-
+
-
+
)
}
diff --git a/src/content/reference/react/useContext.md b/src/content/reference/react/useContext.md
index d3d68f38d7..5d93d37777 100644
--- a/src/content/reference/react/useContext.md
+++ b/src/content/reference/react/useContext.md
@@ -38,13 +38,23 @@ function MyComponent() {
#### 返回值 {/*returns*/}
+<<<<<<< HEAD
`useContext` 为调用组件返回 context 的值。它被确定为传递给树中调用组件上方最近的 `SomeContext.Provider` 的 `value`。如果没有这样的 provider,那么返回值将会是为创建该 context 传递给 [`createContext`](/reference/react/createContext) 的 `defaultValue`。返回的值始终是最新的。如果 context 发生变化,React 会自动重新渲染读取 context 的组件。
+=======
+`useContext` returns the context value for the calling component. It is determined as the `value` passed to the closest `SomeContext` above the calling component in the tree. If there is no such provider, then the returned value will be the `defaultValue` you have passed to [`createContext`](/reference/react/createContext) for that context. The returned value is always up-to-date. React automatically re-renders components that read some context if it changes.
+>>>>>>> 50d6991ca6652f4bc4c985cf0c0e593864f2cc91
#### 注意事项 {/*caveats*/}
+<<<<<<< HEAD
* 组件中的 `useContext()` 调用不受 **同一** 组件返回的 provider 的影响。相应的 `` 需要位于调用 `useContext()` 的组件 **之上**。
* 从 provider 接收到不同的 `value` 开始,React 自动重新渲染使用了该特定 context 的所有子级。先前的值和新的值会使用 [`Object.is`](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/is) 来做比较。使用 [`memo`](/reference/react/memo) 来跳过重新渲染并不妨碍子级接收到新的 context 值。
* 如果你的构建系统在输出中产生重复的模块(可能发生在符号链接中),这可能会破坏 context。通过 context 传递数据只有在用于传递 context 的 `SomeContext` 和用于读取数据的 `SomeContext` 是完全相同的对象时才有效,这是由 `===` 比较决定的。
+=======
+* `useContext()` call in a component is not affected by providers returned from the *same* component. The corresponding `` **needs to be *above*** the component doing the `useContext()` call.
+* React **automatically re-renders** all the children that use a particular context starting from the provider that receives a different `value`. The previous and the next values are compared with the [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) comparison. Skipping re-renders with [`memo`](/reference/react/memo) does not prevent the children receiving fresh context values.
+* If your build system produces duplicates modules in the output (which can happen with symlinks), this can break context. Passing something via context only works if `SomeContext` that you use to provide context and `SomeContext` that you use to read it are ***exactly* the same object**, as determined by a `===` comparison.
+>>>>>>> 50d6991ca6652f4bc4c985cf0c0e593864f2cc91
---
@@ -70,9 +80,9 @@ function Button() {
```js [[1, 3, "ThemeContext"], [2, 3, "\\"dark\\""], [1, 5, "ThemeContext"]]
function MyPage() {
return (
-
+
-
+
);
}
@@ -98,9 +108,9 @@ const ThemeContext = createContext(null);
export default function MyApp() {
return (
-
+
-
+
)
}
@@ -183,14 +193,14 @@ function Button({ children }) {
function MyPage() {
const [theme, setTheme] = useState('dark');
return (
-
+
-
+
);
}
```
@@ -213,7 +223,7 @@ const ThemeContext = createContext(null);
export default function MyApp() {
const [theme, setTheme] = useState('light');
return (
-
+
-
+
)
}
@@ -317,14 +327,14 @@ const CurrentUserContext = createContext(null);
export default function MyApp() {
const [currentUser, setCurrentUser] = useState(null);
return (
-
-
+
);
}
@@ -411,8 +421,8 @@ export default function MyApp() {
const [theme, setTheme] = useState('light');
const [currentUser, setCurrentUser] = useState(null);
return (
-
-
+
Use dark mode
-
-
+
+
)
}
@@ -596,16 +606,16 @@ export default function MyApp() {
function MyProviders({ children, theme, setTheme }) {
const [currentUser, setCurrentUser] = useState(null);
return (
-
-
+
{children}
-
-
+
+
);
}
@@ -775,11 +785,11 @@ export function TasksProvider({ children }) {
);
return (
-
-
+
+
{children}
-
-
+
+
);
}
@@ -978,9 +988,9 @@ export default function MyApp() {
const [theme, setTheme] = useState('light');
return (
<>
-
+
-
+
-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.
+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.
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.
diff --git a/src/content/reference/rules/components-and-hooks-must-be-pure.md b/src/content/reference/rules/components-and-hooks-must-be-pure.md
index fcd56c5928..4a7d74359e 100644
--- a/src/content/reference/rules/components-and-hooks-must-be-pure.md
+++ b/src/content/reference/rules/components-and-hooks-must-be-pure.md
@@ -206,8 +206,13 @@ function ProductDetailPage({ product }) {
你可以将 props 和 state 视为在渲染后更新的快照。因此,你不会直接修改 props 或 state,相反,你传递新的 props,或者使用提供给你的 setter 函数来告诉 React,state 需要在下一次组件渲染时更新。
+<<<<<<< HEAD
### 不要修改 props {/*props*/}
props 是不可变的,因为如果你改变了它们,应用程序可能会产生不一致的结果,这会让调试变得困难,因为程序可能会在某些情况下工作,而在另一些情况下不工作。
+=======
+### Don't mutate Props {/*props*/}
+Props are immutable because if you mutate them, the application will produce inconsistent output, which can be hard to debug as it may or may not work depending on the circumstances.
+>>>>>>> 50d6991ca6652f4bc4c985cf0c0e593864f2cc91
```js {2}
function Post({ item }) {
@@ -306,7 +311,12 @@ function useIconStyle(icon) {
}, [icon, theme]);
}
```
+<<<<<<< HEAD
如果你改变了 Hook 的参数,那么自定义 Hook 的缓存(memoization)就会变得不正确,因此避免这样做非常重要。
+=======
+
+If you were to mutate the Hook's arguments, the custom hook's memoization will become incorrect, so it's important to avoid doing that.
+>>>>>>> 50d6991ca6652f4bc4c985cf0c0e593864f2cc91
```js {4}
style = useIconStyle(icon); // `style` 是基于 `icon` 进行记忆化的
@@ -326,7 +336,11 @@ style = useIconStyle(icon); // 计算 `style` 的新值
## 不要改变传递给 JSX 后的值 {/*values-are-immutable-after-being-passed-to-jsx*/}
+<<<<<<< HEAD
不要在 JSX 使用过值之后改变它们。应该在创建 JSX 之前完成值的更改。
+=======
+Don't mutate values after they've been used in JSX. Move the mutation to before the JSX is created.
+>>>>>>> 50d6991ca6652f4bc4c985cf0c0e593864f2cc91
当你在表达式中使用 JSX 时,React 可能会在组件完成渲染之前就急于计算 JSX。这意味着,如果在将值传递给 JSX 之后对它们进行更改,可能会导致 UI 过时,因为 React 不会知道需要更新组件的输出。
diff --git a/src/pages/errors/[errorCode].tsx b/src/pages/errors/[errorCode].tsx
index a67c5742d7..c8cf28ad82 100644
--- a/src/pages/errors/[errorCode].tsx
+++ b/src/pages/errors/[errorCode].tsx
@@ -26,7 +26,7 @@ export default function ErrorDecoderPage({
);
return (
-
+
*/}
-
+
);
}