ScanSkill

if statement

In React, we can use if operator to conditionally render the components.

Syntax

if(condition){
   return true;
}
else {
   return false;
}

Example

function Test() {
  const show = true;
  if (show) {
    return <h1>This is show component</h1>;
  }else
  return <h1>This is no show component</h1>;
}
if conditional rendering

Here, The show component that is set to be rendered while the condition is true is rendered.