JSX'te Koşulların Kullanımı

İçeriği show sabitine bağlı olarak ekranda bir metnin veya başka bir metnin görünmesini sağlayalım:

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

Değişkende metin değil de bir etiketin tutulması sağlanabilir:

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