Javascript 如何有条件地加载React组件?
如何在状态更改时有条件地加载React工具栏组件Javascript 如何有条件地加载React组件?,javascript,reactjs,conditional,components,Javascript,Reactjs,Conditional,Components,如何在状态更改时有条件地加载React工具栏组件 constructor(props) { super(props); this.state = { currentpagenum: 0, }; } render(){ return( <View> {this.state.currentpagenum!==0 ? this.getToolbar(): null;}
constructor(props) {
super(props);
this.state = {
currentpagenum: 0,
};
}
render(){
return(
<View>
{this.state.currentpagenum!==0 ? this.getToolbar(): null;}
</View>
);
}
getToolbar(){
return(
<ToolbarAndroid />
);
}
构造函数(道具){
超级(道具);
此.state={
currentpagenum:0,
};
}
render(){
返回(
{this.state.currentpagenum!==0?this.getToolbar():null;}
);
}
getToolbar(){
返回(
);
}
看起来您添加了一个打字错误
afternull
这是不必要的,您也可以放弃getToolbar函数
,改为尝试:
constructor(props) {
super(props);
this.state = {
currentpagenum: 0,
};
}
render() {
return(
<View>
{this.state.currentpagenum !== 0 ? <ToolbarAndroid /> : null}
</View>
);
}
构造函数(道具){
超级(道具);
此.state={
currentpagenum:0,
};
}
render(){
返回(
{this.state.currentpagenum!==0?:null}
);
}
看起来您添加了一个打字错误
afternull
这是不必要的,您也可以放弃getToolbar函数
,改为尝试:
constructor(props) {
super(props);
this.state = {
currentpagenum: 0,
};
}
render() {
return(
<View>
{this.state.currentpagenum !== 0 ? <ToolbarAndroid /> : null}
</View>
);
}
构造函数(道具){
超级(道具);
此.state={
currentpagenum:0,
};
}
render(){
返回(
{this.state.currentpagenum!==0?:null}
);
}
另一种有条件地呈现内容的方法是:
render() {
return(
<View>
{this.state.currentpagenum !== 0 && <ToolbarAndroid />}
</View>
);
}
render(){
返回(
{this.state.currentpagenum!==0&&}
);
}
当然,由于“真实性”在javascript中的工作原理,这意味着您可以将其进一步缩短为:
render() {
return(
<View>
{this.state.currentpagenum && <ToolbarAndroid />}
</View>
);
}
render(){
返回(
{this.state.currentpagenum&&}
);
}
另一种有条件地呈现内容的方法是:
render() {
return(
<View>
{this.state.currentpagenum !== 0 && <ToolbarAndroid />}
</View>
);
}
render(){
返回(
{this.state.currentpagenum!==0&&}
);
}
当然,由于“真实性”在javascript中的工作原理,这意味着您可以将其进一步缩短为:
render() {
return(
<View>
{this.state.currentpagenum && <ToolbarAndroid />}
</View>
);
}
render(){
返回(
{this.state.currentpagenum&&}
);
}
您获取Null后的结尾处删除分号的错误是什么谢谢就是这样您获取Null后的结尾处删除分号的错误是什么谢谢就是这样