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.
6666针对现有应用,以下指南将协助你迁移至构建工具:
6767
6868* [ 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/ )
7070* [ Create React App 到 Rsbuild 迁移指南] ( https://rsbuild.dev/guide/migration/cra )
7171
7272为帮助开发者快速上手 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 {
649649- Refs 是一个通用概念,但大多数情况下你会使用它们来保存 DOM 元素。
650650- 你通过传递 ` <div ref={myRef}> ` 指示 React 将 DOM 节点放入 ` myRef.current ` 。
651651- 通常,你会将 refs 用于非破坏性操作,例如聚焦、滚动或测量 DOM 元素。
652- - 默认情况下,组件不暴露其 DOM 节点。 你可以通过使用 ` forwardRef ` 并将第二个 ` ref ` 参数传递给特定节点来暴露 DOM 节点。
652+ - 默认情况下,组件不暴露其 DOM 节点。 你可以通过使用 ` ref ` 属性来暴露 DOM 节点。
653653- 避免更改由 React 管理的 DOM 节点。
654654- 如果你确实修改了 React 管理的 DOM 节点,请修改 React 没有理由更新的部分。
655655
@@ -1051,7 +1051,7 @@ img {
10511051
10521052<Hint >
10531053
1054- 你需要 ` forwardRef ` 来主动从你自己的组件中暴露一个 DOM 节点,比如 ` SearchInput ` 。
1054+ 你需要使用 ` ref ` 属性来主动从你自己的组件中暴露一个 DOM 节点,比如 ` SearchInput ` 。
10551055
10561056</Hint >
10571057
@@ -1136,18 +1136,14 @@ export default function SearchButton({ onClick }) {
11361136```
11371137
11381138``` 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+ }
11511147```
11521148
11531149``` 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
4024021. The <CodeStep step={2}>error</CodeStep> that was thrown.
4034032. An <CodeStep step={3}>errorInfo</CodeStep> object that contains the <CodeStep step={4}>componentStack</CodeStep> of the error.
404404
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:
406406
407407<Sandpack>
408408
Original file line number Diff line number Diff line change @@ -214,7 +214,7 @@ export default function App() {
214214 ]);
215215 async function sendMessage (formData ) {
216216 const sentMessage = await deliverMessage (formData .get (" message" ));
217- setMessages ([... messages, { text: sentMessage }]);
217+ setMessages (( messages ) => [... messages, { text: sentMessage }]);
218218 }
219219 return < Thread messages= {messages} sendMessage= {sendMessage} / > ;
220220}
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ React 可以将 `<style>` 组件移动到文档的 `<head>` 中,去重相同
5252这种特殊处理带来两个注意事项:
5353
5454* 在样式被渲染后,React 将忽略属性的更改(React 在开发环境中会对这种情况发出警告)。
55+ * 当设置了 ` precedence ` 属性的时候,React 会丢弃除了 ` href ` 和 ` precedence ` 的之外所有无关属性。
5556* 即使渲染它的组件已被卸载,React 也可能将样式保留在 DOM 中。
5657
5758---
You can’t perform that action at this time.
0 commit comments