You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: beta/src/pages/learn/index.md
+20-1Lines changed: 20 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -191,6 +191,25 @@ export default function Profile() {
191
191
192
192
</Sandpack>
193
193
194
-
195
194
Here, `style={{ }}` is not a special syntax, but a regular object inside the JSX curlies.
196
195
196
+
## Responding to events {/*responding-to-events*/}
197
+
198
+
You can respond to events by declaring event handler functions inside your components:
199
+
200
+
```js {2-4,7}
201
+
function MyButton() {
202
+
function handleClick() {
203
+
alert('You clicked me!');
204
+
}
205
+
206
+
return (
207
+
<button onClick={handleClick}>
208
+
Click me
209
+
</button>
210
+
);
211
+
}
212
+
```
213
+
214
+
Notice how `onClick={handleClick}` has no parentheses at the end. You don't need to _call_ your event handler, you need to _pass_ the event handler itself. React will call your handler when the user clicks the button.
0 commit comments