جواب «The About Screen» چالش 1 از جلسهی 36
سؤال
دکمهها اسم صفحه را عوض میکنند، ولی صفحهی About هیچوقت دیده نمیشود. یک خط شرط اضافه کن تا وقتی screen برابر "about" است، <About /> نشان داده شود.
راهنما
زیر خط Home بنویس: {screen === "about" && <About />}
یک جواب درست
<style>
body { font-family: sans-serif; text-align: center; padding: 16px; }
button, input, select { font-size: 16px; min-height: 40px; margin: 4px; }
</style>
<div id="root" dir="ltr"></div>
<script type="text/jsx">
import { useState } from "react";
import { createRoot } from "react-dom/client";
function Home() {
return <h2 id="home">Home</h2>;
}
function About() {
return <h2 id="about">About</h2>;
}
function App() {
const [screen, setScreen] = useState("home");
return (
<div>
<button id="go-home" onClick={() => setScreen("home")}>Home</button>
<button id="go-about" onClick={() => setScreen("about")}>About</button>
{screen === "home" && <Home />}
{screen === "about" && <About />}
</div>
);
}
createRoot(document.getElementById("root")).render(<App />);
</script>
اول خودت امتحان کن؛ جوابهای دیگر هم قبول است. برگرد و خودت حلش کن