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

大佬们遇到过这个问题吗?react如何不再使用三目运算十分感谢

大佬们遇到过这个问题吗?react如何不再使用三目运算十分感谢

饮歌长啸 2019-06-20 09:52:59
之前看了篇文章说react使用一个库就可以不再使用三目运算了,但是现在忘了怎么写的了
查看完整描述

2 回答

?
慕虎7371278

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

react-if
constrenderData=(data)=>{
valcomputed=/*expensivecomputation*/
returnHereistheresult:{computed};
};
constFoo=({data})=>(
{()=>
renderData(data)
}
Nothingtoseehere
Nobears
this.props.bears.length}>
Emptybearsarray
//Displaybears
)
                            
查看完整回答
反对 回复 2019-06-20
?
Smart猫小萌

TA贡献1911条经验 获得超7个赞

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

添加回答

举报

0/150
提交
取消
微信客服

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

帮助反馈 APP下载

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

公众号

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