⊗jsrtPmCdInr 25 of 112 menu

Using Conditions in JSX

Let's make it so that depending on the contents of the constant show, one or the other text is displayed on the screen:

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

You can make it so that the variable stores not the text, but the tag:

function App() { let text; const show = true; if (show) { text = <p>text1</p>; } else { text = <p>text2</p>; } return <div> {text} </div>; }
English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline