React通过
refattribute提供了一个您要尝试执行的操作的接口。给组件分配一个
ref,其
current属性将是您的自定义组件:
class Parent extends React.Class { constructor(props) { this._child = React.createRef(); } componentDidMount() { console.log(this._child.current.someMethod()); // Prints 'bar' } render() { return ( <div> <Child ref={this._child} /> </div> ); }}


