Reactjs 如何获取props.children属性的ref以使用';测量';方法?
我正在寻找一种方法来度量组件的子属性。我尝试了React.createReference,将引用(ref)作为属性传递给组件B,从组件B的this.props.children读取属性(有人知道props.children的文档吗?),但都没有成功 幻觉代码:Reactjs 如何获取props.children属性的ref以使用';测量';方法?,reactjs,native,Reactjs,Native,我正在寻找一种方法来度量组件的子属性。我尝试了React.createReference,将引用(ref)作为属性传递给组件B,从组件B的this.props.children读取属性(有人知道props.children的文档吗?),但都没有成功 幻觉代码: class A extends Component { render(){ return(){ <B> <Text>Component to referen
class A extends Component {
render(){
return(){
<B>
<Text>Component to references</Text>
</B>
}
}
}
class B extends Component {
getChildBounds(){
this.props.children.measure((dx,dy)=>{
console.log(dx,dy);
}
)
}
render(){
this.getChildBounds();
return(){
<View>
{this.props.children}
</View>
}
}
}
A类扩展组件{
render(){
返回(){
组件到引用
}
}
}
类扩展组件{
getChildBounds(){
this.props.children.measure((dx,dy)=>{
console.log(dx,dy);
}
)
}
render(){
这个.getChildBounds();
返回(){
{this.props.children}
}
}
}
尝试将this.refs记录下来,然后查看您是否将其保存在那里或not@ShubhamAgarwal Bhewanewala this.refs是一个空对象。