Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/476.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何有条件地加载React组件?_Javascript_Reactjs_Conditional_Components - Fatal编程技术网

Javascript 如何有条件地加载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;}

如何在状态更改时有条件地加载React工具栏组件

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(){
返回(
);
}

看起来您添加了一个打字错误
after
null
这是不必要的,您也可以放弃
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}
);
}

看起来您添加了一个打字错误
after
null
这是不必要的,您也可以放弃
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后的结尾处删除分号的错误是什么谢谢就是这样