Použití podmínek v JSX

Udělejme tak, aby v závislosti na obsahu konstanty show na obrazovce byl zobrazen buď jeden, nebo druhý text:

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

Lze to udělat tak, aby v proměnné byl uložen ne text, ale tag:

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