javascript - react native 中自定义组件的简写?
问题描述
我最近了解到您可以制作这样的自定义组件:
const CustomComp=()=>{
console.log('Created custom comp');
return(<View></View>);
}
export default function App(){
return(<View style={{flex:1}}>
<CustomComp />
</View>)
}
但是有可能以速记方式做到这一点,也许是这样的?
export default function App(){
return(<View style={{flex:1}}>
<(()=>{
console.log('Created custom comp');
return(<View></View>);
}) />
</View>)
}
这不准确,但我想您对我的查询有所了解
解决方案
您可以使用 IIFE 就地评估函数:
export default function App(){
return(<View style={{flex:1}}>
{(() => {
console.log('Created custom comp');
return(<View></View>);
})()}
</View>)
}
推荐阅读
- chart.js - 刻度回调不显示包含小数的字符串
- reactjs - 如何在 React 中的 url 字符串中插入数据?
- python-3.x - 如何从 Flask 发送两个系列以由 Chartist.js 绘制
- r - 使用 mutate_all 自动替换一系列变量上的缺失数据
- angular - Angular 9 mat-progress-buttons 错误:由于编译错误,无法编译入口点 mat-progress-buttons(es2015 为 esm2015)中的错误
- javascript - 是否有任何库可以将 SCSS 字符串转换为 CSS 字符串?
- delphi - 在运行时创建浮动 TToolbar 而不会闪烁
- nginx - Nginx 配置在 Tomcat 上无法正常工作
- gate - 带有阿拉伯语语言的 GATE 本体编辑器
- html - 如何使行中的所有按钮与具有动态高度的按钮对齐