File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -79,7 +79,7 @@ export default function Form() {
7979
80801 . 使用 ` useRef ` Hook 声明 ` inputRef ` 。
81812 . 像 ` <input ref={inputRef}> ` 这样传递它。这告诉 React ** 将这个 ` <input> ` 的 DOM 节点放入 ` inputRef.current ` 。**
82- 3 . 在 ` handleClick ` 函数中,从 ` inputRef.current ` 读取 input DOM 节点并使用 ` inputRef.current.focus() ` 调用它的 [ ` focus() ` ] ( https://developer.mozilla.org/zh-CN /docs/Web/API/HTMLElement/focus ) 。
82+ 3 . 在 ` handleClick ` 函数中,从 ` inputRef.current ` 读取 input DOM 节点并使用 ` inputRef.current.focus() ` 调用它的 [ ` focus() ` ] ( https://developer.mozilla.org/en-US /docs/Web/API/HTMLElement/focus ) 。
83834 . 用 ` onClick ` 将 ` handleClick ` 事件处理器传递给 ` <button> ` 。
8484
8585虽然 DOM 操作是 ref 最常见的用例,但 ` useRef ` Hook 可用于存储 React 之外的其他内容,例如计时器 ID 。与 state 类似,ref 能在渲染之间保留。你甚至可以将 ref 视为设置它们时不会触发重新渲染的 state 变量!你可以在[ 使用 Ref 引用值] ( /learn/referencing-values-with-refs ) 中了解有关 ref 的更多信息。
You can’t perform that action at this time.
0 commit comments