From 94b5b9c2e50f8c84df813f8161f7ac178618cffb Mon Sep 17 00:00:00 2001 From: yishuolin Date: Thu, 29 Jun 2023 15:03:55 +0800 Subject: [PATCH 1/2] docs: translate responding-to-events --- src/content/learn/responding-to-events.md | 210 +++++++++++----------- 1 file changed, 105 insertions(+), 105 deletions(-) diff --git a/src/content/learn/responding-to-events.md b/src/content/learn/responding-to-events.md index 4450c4613..7a59d7a57 100644 --- a/src/content/learn/responding-to-events.md +++ b/src/content/learn/responding-to-events.md @@ -1,24 +1,24 @@ --- -title: Responding to Events +title: 回應 Event --- -React lets you add *event handlers* to your JSX. Event handlers are your own functions that will be triggered in response to interactions like clicking, hovering, focusing form inputs, and so on. +React 允許你在 JSX 中加入 *event handler*。Event handler 是由你撰寫的函式,會在互動(例如點擊、hover、表單輸入欄位聚焦等)時被觸發。 -* Different ways to write an event handler -* How to pass event handling logic from a parent component -* How events propagate and how to stop them +* 撰寫 event handler 的不同方式 +* 如何從 parent component 傳遞處理事件的邏輯 +* 事件如何傳遞,以及如何停止它們 -## Adding event handlers {/*adding-event-handlers*/} +## 新增 event handler {/*adding-event-handlers*/} -To add an event handler, you will first define a function and then [pass it as a prop](/learn/passing-props-to-a-component) to the appropriate JSX tag. For example, here is a button that doesn't do anything yet: +要新增 event handler,首先你必須先定義一個函式,然後將它[當作 prop 傳遞](/learn/passing-props-to-a-component)給適當的 JSX 標籤。例如,這是一個目前還沒有做任何事情的按鈕: @@ -34,11 +34,12 @@ export default function Button() { -You can make it show a message when a user clicks by following these three steps: +根據以下三個步驟,你可以讓它在使用者點擊時顯示訊息: + +1. 在你的 `Button` component *中*宣告一個名為 `handleClick` 的函式。 +2. 在該函式中實作邏輯(使用 `alert` 來顯示訊息)。 +3. 將 `onClick={handleClick}` 加到 `