NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
**例子** ``` import React from "react"; const TargetComponet = React.forwardRef((props,ref ) =>( <input type="text" ref={ ref } /> )); export default class Comp extends React.Component{ constructor(props) { super(props); this.ref = React.createRef(); } componentDidMount() { this.ref.current.value = 'ref get input' } render() { return <TargetComponet ref={this.ref} /> } } ``` **源码** ~~~ import {REACT_FORWARD_REF_TYPE, REACT_MEMO_TYPE} from 'shared/ReactSymbols'; export default function forwardRef<Props, ElementType: React$ElementType>( render: (props: Props, ref: React$Ref<ElementType>) => React$Node, ) { return { $$typeof: REACT_FORWARD_REF_TYPE, render, }; } ~~~ > 通过React.ReactElement创建的所有节点都是 REACT_ELEMENT_TYPE