refs的用法

constructor(props){
        super(props)
        this.myRefs = React.createRef();
    }
    refFun(){
        const node = this.myRefs.current
        node.style.color = "red"
    }
    render() {
        return ( 
            <div>
                <button ref={this.myRefs} onClick={this.refFun.bind(this)}>refs点击按钮</button>
            </div>
        )
    }

原文地址:https://www.cnblogs.com/chenlw/p/13231606.html