class MyComponent extends Component {
roar () {
// 会打印 `miao, miao, miao~`
this.cat.miao()
}
refCat = (node) => this.cat = node // `this.cat` 会变成 `Cat` 组件实例的引用
render () {
return <Cat ref={this.refCat} />
}
}
class Cat extends Components {
miao () {
console.log(‘miao, miao, miao~‘)
}
render () {
return <View />
}
}
原文:https://www.cnblogs.com/cag2050/p/9930015.html