【发布时间】:2020-06-27 04:59:50
【问题描述】:
我正在创建一个简单的自定义组件,它将在文本中设置动态高度和宽度。
Class CustomComponent extends React.Component{
render(){
if(this.props.children){
if(this.state.isLoading){
console.log(this.props.children)
//Here i want to know what JSX is passing
return(
<View>
<ActivityIndicator size={'large'}/>
</View>
)
}
return(
<ImageBackground
source={this.props.source}
>
{this.props.children}
</ImageBackground>
)
} else if(this.state.isLoading){
return(
<View>
<ActivityIndicator size={'large'}/>
</View>
)
} else return(
<Image
source={this.props.source}
/>
)
}
}
//Use with text
<CustomComponent>
<View>
<Image {passing image} />
<Text>Sample</Text>
</View>
</CustomComponent>
但是现在我需要处理children 是否仅通过<Images/> 和<Text>,有什么建议吗?
【问题讨论】:
标签: javascript reactjs react-native dom custom-component