Primena uslova u JSX-u
Neka u zavisnosti od sadržaja konstante show
bude prikazan jedan ili drugi tekst:
function App() {
let text;
const show = true;
if (show) {
text = 'text1';
} else {
text = 'text2';
}
return <div>
{text}
</div>;
}
Može se postići da promenljiva sadrži ne tekst, već tag:
function App() {
let text;
const show = true;
if (show) {
text = <p>text1</p>;
} else {
text = <p>text2</p>;
}
return <div>
{text}
</div>;
}