بتل کد Battle Codeدارد باز می‌شود…

Make It Count چالش 1 از جلسه‌ی 12، آسان

state به اسم count ساخته شده و روی صفحه هم نشان داده می‌شود، ولی تابع handleClick خالی است. کاری کن که با هر کلیک count یکی زیاد شود.

<style>
body { font-family: sans-serif; text-align: center; padding: 16px; }
button, input, select { font-size: 16px; min-height: 40px; margin: 4px; }
.big { font-size: 40px; }
</style>

<div id="root" dir="ltr"></div>

<script type="text/jsx">
import { useState } from "react";
import { createRoot } from "react-dom/client";

function App() {
  const [count, setCount] = useState(0);

  function handleClick() {
  }

  return (
    <div>
      <p id="count" className="big">{count}</p>
      <button id="add" onClick={handleClick}>+1</button>
    </div>
  );
}

createRoot(document.getElementById("root")).render(<App />);
</script>

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 12: useState: حافظه‌ی قطعه · چالش بعدی: Show the Likes

بیشتر بخوان: جاوااسکریپت چیست؟ از دکمه‌ی وب تا Node.js