[英]react-native calling custom view
我有一个自定义header
视图,并且在类中调用了此视图,但由于某种原因,它没有显示。
export default class App extends Component<Props> {
customHeader(){
<View style={{height:80, width:'100%', backgroundColor: 'blue'}}>
<TouchableOpacity>
<Text>Header</Text>
</TouchableOpacity>
</View>
}
render() {
return (
<View style={styles.container}>
//Calling my custom header
{this.customHeader()}
</View>
);
}
}
我觉得我的代码是正确的,但是标题没有显示。 知道为什么吗?
您的customHeader
函数必须返回某些内容。 现在,它只运行jsx,什么也不返回。 像这样修复它:
customHeader(){
return (
<View style={{height:80, width:'100%', backgroundColor: 'blue'}}>
<TouchableOpacity>
<Text>Header</Text>
</TouchableOpacity>
</View>
)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.