Skip to content

Commit 0651ddf

Browse files
authored
fix conflict
1 parent 88a9384 commit 0651ddf

33 files changed

+52
-234
lines changed

src/content/blog/2024/02/15/react-labs-what-we-have-been-working-on-february-2024.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,7 @@ Activity 仍处于研究阶段,我们剩下的工作是最终确定向库开
107107

108108
除了此更新之外,我们的团队还在会议上发表了演讲并在播客中露面,更多地讲述我们的工作并回答问题。
109109

110-
<<<<<<< HEAD
111-
- [Sathya Gunasekaran](/community/team#sathya-gunasekaran)[React India](https://www.youtube.com/watch?v=kjOacmVsLSE) 大会上介绍了 React 编译器。
112-
=======
113-
- [Sathya Gunasekaran](https://github.com/gsathya) spoke about the React Compiler at the [React India](https://www.youtube.com/watch?v=kjOacmVsLSE) conference
114-
>>>>>>> b6450e8f2d89235350932e332195f8549dcf2391
110+
- [Sathya Gunasekaran](https://github.com/gsathya)[React India](https://www.youtube.com/watch?v=kjOacmVsLSE) 大会上介绍了 React 编译器。
115111

116112
- [Dan Abramov](/community/team#dan-abramov)[RemixConf](https://www.youtube.com/watch?v=zMf_xeGPn6s) 上发表了名为“React from Another Dimension”的演讲,探讨了 React 服务器组件与 Action 可能是如何创建的另一种历史。
117113

src/content/blog/2024/10/21/react-compiler-beta-release.md

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,11 @@ npm install -D eslint-plugin-react-compiler@beta
7272
yarn add -D eslint-plugin-react-compiler@beta
7373
</TerminalBlock>
7474

75-
<<<<<<< HEAD
76-
安装后你可以通过[将其添加到 ESLint 配置](/learn/react-compiler#installing-eslint-plugin-react-compiler) 来启用 linter。使用 linter 有助于发现破坏 React 规则的地方,从而在编译器完全发布后更容易采用它。
77-
=======
78-
After installation you can enable the linter by [adding it to your ESLint config](/learn/react-compiler/installation#eslint-integration). Using the linter helps identify Rules of React breakages, making it easier to adopt the compiler when it's fully released.
79-
>>>>>>> b6450e8f2d89235350932e332195f8549dcf2391
75+
安装后你可以通过[将其添加到 ESLint 配置](/learn/react-compiler/installation#eslint-integration) 来启用 linter。使用 linter 有助于发现破坏 React 规则的地方,从而在编译器完全发布后更容易采用它。
8076

8177
## 向后兼容性 {/*backwards-compatibility*/}
8278

83-
<<<<<<< HEAD
84-
React Compiler 生成的代码依赖于 React 19 中添加的运行时 API,但我们后来添加了对 React 17 和 18 的支持。如果你还没有使用 React 19,在 Beta 版本中可以通过在 compiler 配置中设置 `target` 来使用 React Compiler,并添加 `react-compiler-runtime` 作为依赖项。[你可以在这里找到相关文档](/learn/react-compiler#using-react-compiler-with-react-17-or-18)
85-
=======
86-
React Compiler produces code that depends on runtime APIs added in React 19, but we've since added support for the compiler to also work with React 17 and 18. If you are not on React 19 yet, in the Beta release you can now try out React Compiler by specifying a minimum `target` in your compiler config, and adding `react-compiler-runtime` as a dependency. [You can find docs on this here](/reference/react-compiler/configuration#react-17-18).
87-
>>>>>>> b6450e8f2d89235350932e332195f8549dcf2391
79+
React Compiler 生成的代码依赖于 React 19 中添加的运行时 API,但我们后来添加了对 React 17 和 18 的支持。如果你还没有使用 React 19,在 Beta 版本中可以通过在 compiler 配置中设置 `target` 来使用 React Compiler,并添加 `react-compiler-runtime` 作为依赖项。[你可以在这里找到相关文档](/reference/react-compiler/configuration#react-17-18)
8880

8981
## 在库中使用 React Compiler {/*using-react-compiler-in-libraries*/}
9082

@@ -94,11 +86,7 @@ React Compiler 还可以用来编译库。由于 React Compiler 需要在代码
9486

9587
由于库的代码是预编译的,因此用户无需启用 Compiler 即可从编译器的自动记忆化中受益。如果库的 target 不是 React 19,请指定一个最小的 [`target` 并且将 `react-compiler-runtime` 添加为直接依赖](#using-react-compiler-with-react-17-or-18)。这个运行时包将根据应用程序的版本使用正确的 API 实现,并在必要时填充缺失的 API。
9688

97-
<<<<<<< HEAD
98-
[你可以在此处找到更多相关文档。](/learn/react-compiler#using-the-compiler-on-libraries)
99-
=======
100-
[You can find more docs on this here.](/reference/react-compiler/compiling-libraries)
101-
>>>>>>> b6450e8f2d89235350932e332195f8549dcf2391
89+
[你可以在此处找到更多相关文档。](/reference/react-compiler/compiling-libraries)
10290

10391
## 向所有人开放 React Compiler 工作组 {/*opening-up-react-compiler-working-group-to-everyone*/}
10492

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,11 +2495,7 @@ root.render(
24952495
</ViewTransition>
24962496
```
24972497

2498-
<<<<<<< HEAD
2499-
并使用[视图过渡类](/reference/react/ViewTransition#view-transition-classes)在 CSS 中定义 `slow-fade`
2500-
=======
2501-
And define `slow-fade` in CSS using [view transition classes](/reference/react/ViewTransition#view-transition-class):
2502-
>>>>>>> b6450e8f2d89235350932e332195f8549dcf2391
2498+
并使用[视图过渡类](/reference/react/ViewTransition#view-transition-class)在 CSS 中定义 `slow-fade`
25032499

25042500
```css
25052501
::view-transition-old(.slow-fade) {

src/content/learn/add-react-to-an-existing-project.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ title: 将 React 添加到现有项目中
2424
2. **在框架配置中将 `/some-app` 指定为基本路径**(这里有 [Next.js](https://nextjs.org/docs/app/api-reference/config/next-config-js/basePath)[Gatsby](https://www.gatsbyjs.com/docs/how-to/previews-deploys-hosting/path-prefix/) 的配置样例)。
2525
3. **配置服务器或代理**,以便所有位于 `/some-app/` 下的请求都由 React 应用处理。
2626

27-
<<<<<<< HEAD
28-
这可以确保应用的 React 部分可以受益于这些框架中内置的 [最佳实践](/learn/start-a-new-react-project#can-i-use-react-without-a-framework)
29-
=======
30-
This ensures the React part of your app can [benefit from the best practices](/learn/build-a-react-app-from-scratch#consider-using-a-framework) baked into those frameworks.
31-
>>>>>>> b6450e8f2d89235350932e332195f8549dcf2391
27+
这可以确保应用的 React 部分可以受益于这些框架中内置的 [最佳实践](/learn/build-a-react-app-from-scratch#consider-using-a-framework)
3228

3329
许多基于 React 的框架都是全栈的,从而可以让你的 React 应用充分利用服务器。但是,即使无法或不想在服务器上运行 JavaScript,也可以使用相同的方法。在这种情况下,将 HTML/CSS/JS 导出(Next.js 的 [`next export` output](https://nextjs.org/docs/advanced-features/static-html-export),Gatsby 的 default)替换为 `/some-app/`
3430

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -732,13 +732,8 @@ function TodoList() {
732732
733733
这些弊端并不仅限于 React。任何库在组件挂载时进行数据获取都会遇到这些问题。与路由处理一样,要做好数据获取并非易事,因此我们推荐以下方法:
734734
735-
<<<<<<< HEAD
736-
- **如果你正在使用 [框架](/learn/start-a-new-react-project#production-grade-react-frameworks) ,请使用其内置的数据获取机制**。现代 React 框架集成了高效的数据获取机制,不会出现上述问题。
735+
- **如果你正在使用 [框架](/learn/start-a-new-react-project#full-stack-frameworks) ,请使用其内置的数据获取机制**。现代 React 框架集成了高效的数据获取机制,不会出现上述问题。
737736
- **否则,请考虑使用或构建客户端缓存**。流行的开源解决方案包括 [React Query](https://tanstack.com/query/latest)、[useSWR](https://swr.vercel.app/) 和 [React Router v6.4+](https://beta.reactrouter.com/en/main/start/overview)。你也可以自己构建解决方案:在底层使用 Effect,但添加对请求的去重、缓存响应以及避免网络瀑布(通过预加载数据或将数据请求提升到路由层次)的逻辑。
738-
=======
739-
- **If you use a [framework](/learn/start-a-new-react-project#full-stack-frameworks), use its built-in data fetching mechanism.** Modern React frameworks have integrated data fetching mechanisms that are efficient and don't suffer from the above pitfalls.
740-
- **Otherwise, consider using or building a client-side cache.** Popular open source solutions include [React Query](https://tanstack.com/query/latest), [useSWR](https://swr.vercel.app/), and [React Router 6.4+.](https://beta.reactrouter.com/en/main/start/overview) You can build your own solution too, in which case you would use Effects under the hood, but add logic for deduplicating requests, caching responses, and avoiding network waterfalls (by preloading data or hoisting data requirements to routes).
741-
>>>>>>> b6450e8f2d89235350932e332195f8549dcf2391
742737
743738
如果这些方法都不适合你,你可以继续直接在 Effect 中获取数据。
744739

src/content/learn/typescript.md

Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,16 @@ TypeScript 是一种向 JavaScript 代码添加类型定义的常用方法。Typ
1111

1212
<YouWillLearn>
1313

14-
<<<<<<< HEAD
1514
* [在 React 组件中使用 TypeScript](/learn/typescript#typescript-with-react-components)
1615
* [带有 Hook 的类型示例](/learn/typescript#example-hooks)
17-
* [来自 `@types/react` 的常见类型](/learn/typescript/#useful-types)
18-
* [更多学习资源](/learn/typescript/#further-learning)
19-
=======
20-
* [TypeScript with React Components](/learn/typescript#typescript-with-react-components)
21-
* [Examples of typing with Hooks](/learn/typescript#example-hooks)
22-
* [Common types from `@types/react`](/learn/typescript#useful-types)
23-
* [Further learning locations](/learn/typescript#further-learning)
24-
>>>>>>> b6450e8f2d89235350932e332195f8549dcf2391
16+
* [来自 `@types/react` 的常见类型](/learn/typescript#useful-types)
17+
* [更多学习资源](/learn/typescript#further-learning)
2518

2619
</YouWillLearn>
2720

2821
## 安装 {/*installation*/}
2922

30-
<<<<<<< HEAD
31-
所有的 [生产级 React 框架](/learn/start-a-new-react-project#production-grade-react-framework) 都支持使用 TypeScript。请按照框架特定的指南进行安装:
32-
=======
33-
All [production-grade React frameworks](/learn/start-a-new-react-project#full-stack-frameworks) offer support for using TypeScript. Follow the framework specific guide for installation:
34-
>>>>>>> b6450e8f2d89235350932e332195f8549dcf2391
23+
所有的 [生产级 React 框架](/learn/start-a-new-react-project#full-stack-frameworks) 都支持使用 TypeScript。请按照框架特定的指南进行安装:
3524

3625
- [Next.js](https://nextjs.org/docs/app/building-your-application/configuring/typescript)
3726
- [Remix](https://remix.run/docs/en/1.19.2/guides/typescript)
@@ -135,11 +124,7 @@ export default App = AppTSX;
135124

136125
## Hooks 示例 {/*example-hooks*/}
137126

138-
<<<<<<< HEAD
139127
来自 `@types/react` 的类型定义包括内置的 Hook,因此你可以在组件中使用它们,无需任何额外设置。它们是根据你在组件中编写的代码构建的,所以你会得到很多 [类型推断](https://www.typescriptlang.org/docs/handbook/type-inference.html),并且理想情况下不需要处理提供类型的细节。
140-
=======
141-
The type definitions from `@types/react` include types for the built-in Hooks, so you can use them in your components without any additional setup. They are built to take into account the code you write in your component, so you will get [inferred types](https://www.typescriptlang.org/docs/handbook/type-inference.html) a lot of the time and ideally do not need to handle the minutiae of providing the types.
142-
>>>>>>> b6450e8f2d89235350932e332195f8549dcf2391
143128

144129
但是,我们可以看一下如何为 Hook 提供类型的几个示例。
145130

@@ -155,11 +140,7 @@ const [enabled, setEnabled] = useState(false);
155140
这将为 `enabled` 分配 `boolean` 类型,而 `setEnabled` 将是一个接受 `boolean` 参数的函数,或者返回 `boolean` 的函数。如果你想为 state 显式提供一个类型,你可以通过为 `useState` 调用提供一个类型参数来实现:
156141

157142
```ts
158-
<<<<<<< HEAD
159143
// 显式设置类型为 "boolean"
160-
=======
161-
// Explicitly set the type to "boolean"
162-
>>>>>>> b6450e8f2d89235350932e332195f8549dcf2391
163144
const [enabled, setEnabled] = useState<boolean>(false);
164145
```
165146

@@ -303,11 +284,7 @@ export default App = AppTSX;
303284

304285
</Sandpack>
305286

306-
<<<<<<< HEAD
307-
当你没有一个合理的默认值时,这种技术是有效的,而在这些情况下,`null` 作为默认值可能感觉是合理的。但是,为了让类型系统理解你的代码,你需要在 `createContext` 上显式设置 `ContextShape | null`
308-
=======
309-
This technique works when you have a default value which makes sense - but there are occasionally cases when you do not, and in those cases `null` can feel reasonable as a default value. However, to allow the type-system to understand your code, you need to explicitly set `ContextShape | null` on the `createContext`.
310-
>>>>>>> b6450e8f2d89235350932e332195f8549dcf2391
287+
当你有一个合理的默认值情况下,这种技术是有效的。但是当你没有合理的默认值的时候,`null` 作为默认值可能感觉是合理的。但是为了让类型系统理解你的代码,你需要在 `createContext` 上显式设置 `ContextShape | null`
311288

312289
这会导致一个问题,你需要在 context consumer 中消除 `| null` 的类型。我们建议让 Hook 在运行时检查它的存在,并在不存在时抛出一个错误:
313290

@@ -352,17 +329,13 @@ function MyComponent() {
352329

353330
### `useMemo` {/*typing-usememo*/}
354331

355-
<<<<<<< HEAD
356-
[`useMemo`](/reference/react/useMemo) 会从函数调用中创建/重新访问记忆化值,只有在第二个参数中传入的依赖项发生变化时,才会重新运行该函数。函数的类型是根据第一个参数中函数的返回值进行推断的,如果希望明确指定,可以为该 Hook 提供一个类型参数以指定函数类型。
357-
=======
358332
<Note>
359333

360-
[React Compiler](/learn/react-compiler) automatically memoizes values and functions, reducing the need for manual `useMemo` calls. You can use the compiler to handle memoization automatically.
334+
[React Compiler](/learn/react-compiler) 会自动对值和函数进行记忆化处理,从而减少手动调用 `useMemo` 的需求。你可以使用编译器自动处理记忆化。
361335

362336
</Note>
363337

364-
The [`useMemo`](/reference/react/useMemo) Hooks will create/re-access a memorized value from a function call, re-running the function only when dependencies passed as the 2nd parameter are changed. The result of calling the Hook is inferred from the return value from the function in the first parameter. You can be more explicit by providing a type argument to the Hook.
365-
>>>>>>> b6450e8f2d89235350932e332195f8549dcf2391
338+
[`useMemo`](/reference/react/useMemo) 会从函数调用中创建/重新访问记忆化值,只有在第二个参数中传入的依赖项发生变化时,才会重新运行该函数。函数的类型是根据第一个参数中函数的返回值进行推断的,如果希望明确指定,可以为该 Hook 提供一个类型参数以指定函数类型。
366339

367340
```ts
368341
// 从 filterTodos 的返回值推断 visibleTodos 的类型
@@ -372,17 +345,13 @@ const visibleTodos = useMemo(() => filterTodos(todos, tab), [todos, tab]);
372345

373346
### `useCallback` {/*typing-usecallback*/}
374347

375-
<<<<<<< HEAD
376-
[`useCallback`](/reference/react/useCallback) 会在第二个参数中传入的依赖项保持不变的情况下,为函数提供相同的引用。与 `useMemo` 类似,函数的类型是根据第一个参数中函数的返回值进行推断的,如果希望明确指定,可以为这个 Hook 提供一个类型参数以指定函数类型。
377-
=======
378348
<Note>
379349

380-
[React Compiler](/learn/react-compiler) automatically memoizes values and functions, reducing the need for manual `useCallback` calls. You can use the compiler to handle memoization automatically.
350+
[React Compiler](/learn/react-compiler) 会自动对值和函数进行记忆化处理,从而减少手动调用 `useCallback` 的需求。你可以使用编译器自动处理记忆化。
381351

382352
</Note>
383353

384-
The [`useCallback`](/reference/react/useCallback) provide a stable reference to a function as long as the dependencies passed into the second parameter are the same. Like `useMemo`, the function's type is inferred from the return value of the function in the first parameter, and you can be more explicit by providing a type argument to the Hook.
385-
>>>>>>> b6450e8f2d89235350932e332195f8549dcf2391
354+
[`useCallback`](/reference/react/useCallback) 会在第二个参数中传入的依赖项保持不变的情况下,为函数提供相同的引用。与 `useMemo` 类似,函数的类型是根据第一个参数中函数的返回值进行推断的,如果希望明确指定,可以为这个 Hook 提供一个类型参数以指定函数类型。
386355

387356

388357
```ts
@@ -393,11 +362,7 @@ const handleClick = useCallback(() => {
393362

394363
当在 TypeScript 严格模式下,使用 `useCallback` 需要为回调函数中的参数添加类型注解。这是因为回调函数的类型是根据函数的返回值进行推断的——如果没有参数,那么类型就不能完全理解。
395364

396-
<<<<<<< HEAD
397365
根据自身的代码风格偏好,你可以使用 React 类型中的 `*EventHandler` 函数以在定义回调函数的同时为事件处理程序提供类型注解:
398-
=======
399-
Depending on your code-style preferences, you could use the `*EventHandler` functions from the React types to provide the type for the event handler at the same time as defining the callback:
400-
>>>>>>> b6450e8f2d89235350932e332195f8549dcf2391
401366

402367
```ts
403368
import { useState, useCallback } from 'react';
@@ -480,11 +445,7 @@ interface ModalRendererProps {
480445
}
481446
```
482447

483-
<<<<<<< HEAD
484448
注意,你不能使用 TypeScript 来描述子元素是某种类型的 JSX 元素,所以你不能使用类型系统来描述一个只接受 `<li>` 子元素的组件。
485-
=======
486-
Note, that you cannot use TypeScript to describe that the children are a certain type of JSX elements, so you cannot use the type-system to describe a component which only accepts `<li>` children.
487-
>>>>>>> b6450e8f2d89235350932e332195f8549dcf2391
488449

489450
你可以在这个 [TypeScript playground](https://www.typescriptlang.org/play?#code/JYWwDg9gTgLgBAJQKYEMDG8BmUIjgIilQ3wChSB6CxYmAOmXRgDkIATJOdNJMGAZzgwAFpxAR+8YADswAVwGkZMJFEzpOjDKw4AFHGEEBvUnDhphwADZsi0gFw0mDWjqQBuUgF9yaCNMlENzgAXjgACjADfkctFnYkfQhDAEpQgD44AB42YAA3dKMo5P46C2tbJGkvLIpcgt9-QLi3AEEwMFCItJDMrPTTbIQ3dKywdIB5aU4kKyQQKpha8drhhIGzLLWODbNs3b3s8YAxKBQAcwXpAThMaGWDvbH0gFloGbmrgQfBzYpd1YjQZbEYARkB6zMwO2SHSAAlZlYIBCdtCRkZpHIrFYahQYQD8UYYFA5EhcfjyGYqHAXnJAsIUHlOOUbHYhMIIHJzsI0Qk4P9SLUBuRqXEXEwAKKfRZcNA8PiCfxWACecAAUgBlAAacFm80W-CU11U6h4TgwUv11yShjgJjMLMqDnN9Dilq+nh8pD8AXgCHdMrCkWisVoAet0R6fXqhWKhjKllZVVxMcavpd4Zg7U6Qaj+2hmdG4zeRF10uu-Aeq0LBfLMEe-V+T2L7zLVu+FBWLdLeq+lc7DYFf39deFVOotMCACNOCh1dq219a+30uC8YWoZsRyuEdjkevR8uvoVMdjyTWt4WiSSydXD4NqZP4AymeZE072ZzuUeZQKheQgA) 中查看 `React.ReactNode``React.ReactElement` 的示例,并使用类型检查器进行验证。
490451

0 commit comments

Comments
 (0)