ScanSkill

Ternary Operator

The ternary operator is used to conditionally render the elements in React. It is similar to if...else statement.

Syntax

condition ? true : false

Example

function Example() {
  const show = true;
  return (
    <>
      {show ? (
        <h1>This is show component</h1>
      ) : (
        <h1>This is no show component</h1>
      )}
    </>
  );
}
ternary operator