File tree Expand file tree Collapse file tree 5 files changed +14
-17
lines changed Expand file tree Collapse file tree 5 files changed +14
-17
lines changed Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ This error message will only be shown once per install.
66
66
针对现有应用,以下指南将协助你迁移至构建工具:
67
67
68
68
* [ Create React App 到 Vite 迁移指南] ( https://www.robinwieruch.de/vite-create-react-app/ )
69
- * [ Create React App 到 Parcel 迁移指南] ( https://stackoverflow.com/a/49605484 )
69
+ * [ Create React App 到 Parcel 迁移指南] ( https://parceljs.org/migration/cra/ )
70
70
* [ Create React App 到 Rsbuild 迁移指南] ( https://rsbuild.dev/guide/migration/cra )
71
71
72
72
为帮助开发者快速上手 Vite、Parcel 或 Rsbuild,我们新增了 [ 从零开始构建 React 应用] ( /learn/build-a-react-app-from-scratch ) 文档。
Original file line number Diff line number Diff line change @@ -649,7 +649,7 @@ button {
649
649
- Refs 是一个通用概念,但大多数情况下你会使用它们来保存 DOM 元素。
650
650
- 你通过传递 ` <div ref={myRef}> ` 指示 React 将 DOM 节点放入 ` myRef.current ` 。
651
651
- 通常,你会将 refs 用于非破坏性操作,例如聚焦、滚动或测量 DOM 元素。
652
- - 默认情况下,组件不暴露其 DOM 节点。 你可以通过使用 ` forwardRef ` 并将第二个 ` ref ` 参数传递给特定节点来暴露 DOM 节点。
652
+ - 默认情况下,组件不暴露其 DOM 节点。 你可以通过使用 ` ref ` 属性来暴露 DOM 节点。
653
653
- 避免更改由 React 管理的 DOM 节点。
654
654
- 如果你确实修改了 React 管理的 DOM 节点,请修改 React 没有理由更新的部分。
655
655
@@ -1051,7 +1051,7 @@ img {
1051
1051
1052
1052
<Hint >
1053
1053
1054
- 你需要 ` forwardRef ` 来主动从你自己的组件中暴露一个 DOM 节点,比如 ` SearchInput ` 。
1054
+ 你需要使用 ` ref ` 属性来主动从你自己的组件中暴露一个 DOM 节点,比如 ` SearchInput ` 。
1055
1055
1056
1056
</Hint >
1057
1057
@@ -1136,18 +1136,14 @@ export default function SearchButton({ onClick }) {
1136
1136
```
1137
1137
1138
1138
``` js src/SearchInput.js
1139
- import { forwardRef } from ' react' ;
1140
-
1141
- export default forwardRef (
1142
- function SearchInput (props , ref ) {
1143
- return (
1144
- < input
1145
- ref= {ref}
1146
- placeholder= " 找什么呢?"
1147
- / >
1148
- );
1149
- }
1150
- );
1139
+ export default function SearchInput ({ ref }) {
1140
+ return (
1141
+ < input
1142
+ ref= {ref}
1143
+ placeholder= " 找什么呢?"
1144
+ / >
1145
+ );
1146
+ }
1151
1147
```
1152
1148
1153
1149
``` css
Original file line number Diff line number Diff line change @@ -402,7 +402,7 @@ The <CodeStep step={1}>onCaughtError</CodeStep> option is a function called with
402
402
1. The <CodeStep step={2}>error</CodeStep> that was thrown.
403
403
2. An <CodeStep step={3}>errorInfo</CodeStep> object that contains the <CodeStep step={4}>componentStack</CodeStep> of the error.
404
404
405
- Together with ` onUncaughtError` and ` onRecoverableError` , you can can implement your own error reporting system:
405
+ Together with ` onUncaughtError` and ` onRecoverableError` , you can implement your own error reporting system:
406
406
407
407
<Sandpack>
408
408
Original file line number Diff line number Diff line change @@ -214,7 +214,7 @@ export default function App() {
214
214
]);
215
215
async function sendMessage (formData ) {
216
216
const sentMessage = await deliverMessage (formData .get (" message" ));
217
- setMessages ([... messages, { text: sentMessage }]);
217
+ setMessages (( messages ) => [... messages, { text: sentMessage }]);
218
218
}
219
219
return < Thread messages= {messages} sendMessage= {sendMessage} / > ;
220
220
}
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ React 可以将 `<style>` 组件移动到文档的 `<head>` 中,去重相同
52
52
这种特殊处理带来两个注意事项:
53
53
54
54
* 在样式被渲染后,React 将忽略属性的更改(React 在开发环境中会对这种情况发出警告)。
55
+ * 当设置了 ` precedence ` 属性的时候,React 会丢弃除了 ` href ` 和 ` precedence ` 的之外所有无关属性。
55
56
* 即使渲染它的组件已被卸载,React 也可能将样式保留在 DOM 中。
56
57
57
58
---
You can’t perform that action at this time.
0 commit comments