Nosacījumu izmantošana JSX
Izveidosim tā, lai atkarībā no konstantes show satura
ekrānā tiktu parādīts vai nu viens, vai cits teksts:
function App() {
let text;
const show = true;
if (show) {
text = 'text1';
} else {
text = 'text2';
}
return <div>
{text}
</div>;
}
Var izveidot tā, lai mainīgajā glabātos nevis teksts, bet gan tags:
function App() {
let text;
const show = true;
if (show) {
text = <p>text1</p>;
} else {
text = <p>text2</p>;
}
return <div>
{text}
</div>;
}