JavaScript/react/useImperativeHandle:修订间差异
来自康健生活
创建页面,内容为“== 标题文本 == 父组件 {{hc|head=parent.tsx|output=<syntaxhighlight lang="bash"> import React, { useRef, useEffect } from 'react'; import ChildCET from './child'; export default function Parent() { const childRef = useRef<{ target: HTMLSpanElement | null; option: HTMLSpanElement | null }>({ target: null, option: null, }); useEffect(() => { const target = childRef.current.target; // todo }) return (<PageInfoCET ref={chi…” |
|||
| 第61行: | 第61行: | ||
export default ChildCET; | export default ChildCET; | ||
</syntaxhighlight>}} | </syntaxhighlight>}} | ||
或者 | |||
<syntaxhighlight lang="javascript"> | |||
useImperativeHandle<Editor | null, Editor | null>(instance, () => instanceRef.current as Editor); | |||
</syntaxhighlight> | |||