繁体   English   中英

React Native 中自定义组件的简写?

[英]shorthand for custom components in 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>)
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM