知道有人可以检查ref属性的组件类型吗?
示例幻想反应本机代码:
class A extends Component {
render(){
return(
<ScrollView ref={(r)=>{this._parent = r}}>
<ChildComponent parent={this._parent}/>
</ScrollView>
);
}
}
class ChildComponent extends Component{
componentDidMount(){
if(this.property.parent && this.property.parent.type == 'ScrollView') {
... whatever
}
}
render(){
return(
...
)
}
}
答案 0 :(得分:0)
也许您可以尝试这样的比较:
this.property.parent instanceof ScrollView