Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/content/blog/2025/02/14/sunsetting-create-react-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,15 @@ This error message will only be shown once per install.

针对现有应用,以下指南将协助你迁移至构建工具:

<<<<<<< HEAD
* [Create React App 到 Vite 迁移指南](https://www.robinwieruch.de/vite-create-react-app/)
* [Create React App 到 Parcel 迁移指南](https://stackoverflow.com/a/49605484)
* [Create React App 到 Rsbuild 迁移指南](https://rsbuild.dev/guide/migration/cra)
=======
* [Vite Create React App migration guide](https://www.robinwieruch.de/vite-create-react-app/)
* [Parcel Create React App migration guide](https://parceljs.org/migration/cra/)
* [Rsbuild Create React App migration guide](https://rsbuild.dev/guide/migration/cra)
>>>>>>> a42121e4793f3144a2f00b5862de974bc2da87a3

为帮助开发者快速上手 Vite、Parcel 或 Rsbuild,我们新增了 [从零开始构建 React 应用](/learn/build-a-react-app-from-scratch) 文档。

Expand Down
24 changes: 24 additions & 0 deletions src/content/learn/manipulating-the-dom-with-refs.md
Original file line number Diff line number Diff line change
Expand Up @@ -646,12 +646,21 @@ button {

<Recap>

<<<<<<< HEAD
- Refs 是一个通用概念,但大多数情况下你会使用它们来保存 DOM 元素。
- 你通过传递 `<div ref={myRef}>` 指示 React 将 DOM 节点放入 `myRef.current`。
- 通常,你会将 refs 用于非破坏性操作,例如聚焦、滚动或测量 DOM 元素。
- 默认情况下,组件不暴露其 DOM 节点。 你可以通过使用 `forwardRef` 并将第二个 `ref` 参数传递给特定节点来暴露 DOM 节点。
- 避免更改由 React 管理的 DOM 节点。
- 如果你确实修改了 React 管理的 DOM 节点,请修改 React 没有理由更新的部分。
=======
- Refs are a generic concept, but most often you'll use them to hold DOM elements.
- You instruct React to put a DOM node into `myRef.current` by passing `<div ref={myRef}>`.
- Usually, you will use refs for non-destructive actions like focusing, scrolling, or measuring DOM elements.
- A component doesn't expose its DOM nodes by default. You can opt into exposing a DOM node by using the `ref` prop.
- Avoid changing DOM nodes managed by React.
- If you do modify DOM nodes managed by React, modify parts that React has no reason to update.
>>>>>>> a42121e4793f3144a2f00b5862de974bc2da87a3

</Recap>

Expand Down Expand Up @@ -1051,7 +1060,11 @@ img {

<Hint>

<<<<<<< HEAD
你需要 `forwardRef` 来主动从你自己的组件中暴露一个 DOM 节点,比如 `SearchInput`。
=======
You'll need to pass `ref` as a prop to opt into exposing a DOM node from your own component like `SearchInput`.
>>>>>>> a42121e4793f3144a2f00b5862de974bc2da87a3

</Hint>

Expand Down Expand Up @@ -1136,6 +1149,7 @@ export default function SearchButton({ onClick }) {
```

```js src/SearchInput.js
<<<<<<< HEAD
import { forwardRef } from 'react';

export default forwardRef(
Expand All @@ -1148,6 +1162,16 @@ export default forwardRef(
);
}
);
=======
export default function SearchInput({ ref }) {
return (
<input
ref={ref}
placeholder="Looking for something?"
/>
);
}
>>>>>>> a42121e4793f3144a2f00b5862de974bc2da87a3
```

```css
Expand Down
2 changes: 1 addition & 1 deletion src/content/reference/react-dom/client/hydrateRoot.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ The <CodeStep step={1}>onCaughtError</CodeStep> option is a function called with
1. The <CodeStep step={2}>error</CodeStep> that was thrown.
2. An <CodeStep step={3}>errorInfo</CodeStep> object that contains the <CodeStep step={4}>componentStack</CodeStep> of the error.

Together with `onUncaughtError` and `onRecoverableError`, you can can implement your own error reporting system:
Together with `onUncaughtError` and `onRecoverableError`, you can implement your own error reporting system:

<Sandpack>

Expand Down
Loading