Ehtojen käyttö JSX:ssä

Tehdään niin, että show-vakion sisällöstä riippuen näytölle tulostuu joko yksi tai toinen teksti:

jsxfunction App() {
  let text;
  const show = true;
  
  if (show) {
    text = 'text1';
  } else {
    text = 'text2';
  }
  
  return <div>
    {text}
  </div>;
}

Voidaan tehdä niin, että muuttuja sisältää ei tekstiä, vaan tagin:

jsxfunction App() {
  let text;
  const show = true;
  
  if (show) {
    text = <p>text1</p>;
  } else {
    text = <p>text2</p>;
  }
  
  return <div>
    {text}
  </div>;
}