为了账号安全,请及时绑定邮箱和手机立即绑定

萌新求教!react如何不再使用三目运算各位有什么建议?

萌新求教!react如何不再使用三目运算各位有什么建议?

守着一只汪 2019-09-26 09:22:45
之前看了篇文章说react使用一个库就可以不再使用三目运算了,但是现在忘了怎么写的了
查看完整描述

2 回答

?
拉风的咖菲猫

TA贡献1995条经验 获得超2个赞

react-if
constrenderData=(data)=>{
valcomputed=/*expensivecomputation*/
returnHereistheresult:{computed};
};
constFoo=({data})=>(
{()=>
renderData(data)
}
Nothingtoseehere
Nobears
this.props.bears.length}>
Emptybearsarray
//Displaybears
)
                            
查看完整回答
反对 回复 2019-09-26
?
慕娘9325324

TA贡献1783条经验 获得超4个赞

自定义一个组件就好了
classContainerextendsReact.Component{
render(){
if(!this.props.condition){
returnnull;
}
returnthis.props.children;
}
}
Container.propTypes={
condition:ReactTypes.bool
};
使用
classUserextendsReact.Component{
render(){
return(
未登录
已登录
);
}
}
                            
查看完整回答
反对 回复 2019-09-26
  • 2 回答
  • 0 关注
  • 338 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号