Conditional Showing in React
You can make it so that the text is shown if show
contains true
, and not shown if it contains false
:
function App() {
let text;
const show = true;
if (show) {
text = <p>text</p>;
}
return <div>
{text}
</div>;
}
Let the constant isAdult
contain true
if the user is already 18
years old, and false
if not:
function App() {
const isAdult = true;
}
Make it so that depending on the value of isAdult
, either one paragraph of text or another appears on the screen.