javascript - React Native,在 Render 中调用另一个函数
问题描述
我有这个 SMN() 函数,并在其中创建了站点函数作为常量。所以我需要在 Render() 函数中调用 Site 函数。这是主要功能代码:
SMN() {
const Site = () => {
return (
<View style={{ height: 400 }}>
<WebView source={{ uri: 'https://www.google.com' }} style={{ marginTop: 20 }} />
</View>
);
}
});
这是 Render() 函数,我想从中调用 Site 函数,我使用过: this.SMN().Site ,这不会引发错误,但不会显示任何错误。
render() {
return (
</View>
<View>{this.SMN().Site}</View>
</View>
)
}
解决方案
将您的站点作为一个组件,就像这样:
const Site = () => {
return (
<View style={{ height: 400 }}>
<WebView
source={{ uri: 'https://www.google.com' }}
style={{ marginTop: 20 }} />
</View>
);
}
并在您的渲染函数中像这样使用它:
render() {
return (
</View>
<View><Site /></View>
</View>
)
}
推荐阅读
- c# - DataTrigger 在 RadioButton IsChecked 时更新 DatePicker
- node.js - 如何使用 aws-sdk 将文件同步上传到 S3?
- azure-cosmosdb - 我应该为子文档使用 _self SelfLink
- r - 根据另一个表中的并发日期范围划分列值?
- c++11 - 引用折叠规则是否适用于返回类型?
- python - 有没有办法在不定义布局的情况下将 QPushButton 对象动态添加到 QWidget?
- sql - 爆炸后如何从数组中删除一个元素
- ruby - 如何在 Ruby 中检查图像是否可热链接
- reactjs - 如何在 React 功能组件中正确使用 refs
- matlab - 置信区间位于组栏的中心