ref 指向对象本身
    React.forwardRef 转发ref属性:通过组件向子组件自动引用ref。
    如:

    1. import React, { Component, createRef, forwardRef } from 'react';
    2. const FocusInput = forwardRef((props, ref) => (
    3. <input type="text" ref={ref} />
    4. ));
    5. class ForwardRef extends Component {
    6. constructor(props) {
    7. super(props);
    8. this.ref = createRef();
    9. }
    10. componentDidMount() {
    11. const { current } = this.ref;
    12. current.focus();
    13. }
    14. render() {
    15. return (
    16. <div>
    17. <p>forward ref</p>
    18. <FocusInput ref={this.ref} />
    19. </div>
    20. );
    21. }
    22. }
    23. export default ForwardRef;