Find the Bugs چالش 6 از جلسهی 21، سخت
با هر کلیک روی #add باید #board امتیاز و #stars دو برابر آن را نشان بدهد. ولی این صفحه دو اشتباه دارد. هر دو را درست کن.
راهنمایی: Board از امتیاز کپی گرفته است، و به اسم propها در App نگاه کن.
<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 Board({ score }) {
const [shown, setShown] = useState(score);
return <p id="board">Score: {shown}</p>;
}
function Stars({ score }) {
return <p id="stars">Stars: {score * 2}</p>;
}
function App() {
const [score, setScore] = useState(0);
return (
<div>
<Board score={score} />
<Stars points={score} />
<button id="add" onClick={() => setScore(score + 1)}>+1</button>
</div>
);
}
createRoot(document.getElementById("root")).render(<App />);
</script>
راهنما و جواب این چالش · برگشت به درس جلسهی 21: state را بالا ببر
بیشتر بخوان: جاوااسکریپت چیست؟ از دکمهی وب تا Node.js