如何有条件地加载我的React组件? [英] How do i load my React component conditionally?
本文介绍了如何有条件地加载我的React组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在状态更改时有条件地加载我的React工具栏组件?
How do i load my React toolbar component conditionally on state change?
constructor(props) {
super(props);
this.state = {
currentpagenum: 0,
};
}
render(){
return(
<View>
{this.state.currentpagenum!==0 ? this.getToolbar(): null;}
</View>
);
}
getToolbar(){
return(
<ToolbarAndroid />
);
}
推荐答案
看起来你有一个错字在 null
之后添加;
的错误,这也是不必要的,你也可以摆脱 getToolbar函数
请尝试:
Looks like you got a typo error you added ;
after null
this is unneeded also you can get rid of the getToolbar function
Instead try:
constructor(props) {
super(props);
this.state = {
currentpagenum: 0,
};
}
render() {
return(
<View>
{this.state.currentpagenum !== 0 ? <ToolbarAndroid /> : null}
</View>
);
}
这篇关于如何有条件地加载我的React组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文