父组件调用子组件的时候 使用ref 报错

#1

子组件

_showMessage = (message) => {
    this.props.showMessage(message);
}

父组件

_handleClick(){
    this.setState({
        count:++this.state.count
    })
    this._dialogsMessage._showMessage("当前计数"+this.state.count);
}
render(){
    return(
        <div>
            this is home~........
            <br/>
            当前计数{this.state.count}
            <br/>
            <button onClick={()=>this._handleClick()}>自增</button>
            <DialogsMessage ref = {dialogsMessage => this._dialogsMessage = dialogsMessage}/>
        </div>
    );
}

使用后 后台报错

Uncaught TypeError: this._dialogsMessage._showMessage is not a function
#2

哥们,你的方法名的下划线

#3

我的方法名没有下划线也出现这个问题,好像自定义的组件会报错。有知道怎么解决的吗?

#4

this._dialogsMessage 没有找到_showMessage方法,再检查一下你写的代码。或者贴全一点看看