if-else statement inside jsx: ReactJS

前端 未结 12 1044
广开言路
广开言路 2020-11-22 08:48

I need to change render function and run some sub render function when a specific state given,

For example:

render() {
    return (   
        

        
12条回答
  •  渐次进展
    2020-11-22 09:29

    I do like this and its working fine.

    constructor() {
       super();
    
       this.state ={
         status:true
       }
    }
    
    render() {
       return( 
    
         { this.state.status === true ?
               this.hideView()}>
                 
                   Ok Fine :)
                 
              
               :
               Ok Fine.
         }
      );
    }
    
    hideView(){
      this.setState({
        home:!this.state.status
      });
    }
    

提交回复
热议问题