【初心者】Reactのイベント処理の書き方

HTMLとの違い

例)クリックするとアラートがでるボタン

▼HTML

<html>
  <script>
    const buttonAlert = () => {
      alert();
    }
  </script>
  <body>
    <button onclick="buttonAlert()">ボタン</button>
  </body>
</html>

▼React

const App = () => {
  const buttonAlert = () => {
    alert();
  }

  return(
    <button onClick={buttonAlert}>ボタン</button>
  );
}

Reactのイベント処理の特徴

  • camelCase
  • 関数