Conditional Rendering

  • 1. Step

    Solution 1: in view

    
    
                    const age=48;
                    return(
                      <button>{age > 18 ? "Watch Now" : "Not Available" }</button>
                    )
    
                

    Solution 2: using variable in componenet

    
    
                    let canWatch="Not Available";
                    if(age > 18 ) {
                       canWatch="Watch Now";
                    }
    
                    return(
                      <button>{canWatch}</button>
                    )
    
               

    Solution 3: using function in in componenet

    
    
                    const canWatch =() => {
                        if(age >18){
                            return "Watch Now";
                        }
                        else{
                            return "Not Available";
                        }
                    }
    
                    return(
                      <button>{canWatch()}</button>
                    )