In React, we can use if
operator to conditionally render the components.
if(condition){
return true;
}
else {
return false;
}
function Test() {
const show = true;
if (show) {
return <h1>This is show component</h1>;
}else
return <h1>This is no show component</h1>;
}
Here, The show component that is set to be rendered while the condition is true is rendered.