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: docs/src/learn/responding-to-events.md
+31-23Lines changed: 31 additions & 23 deletions
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ title: Responding to Events 🚧
6
6
7
7
<pclass="intro"markdown>
8
8
9
-
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.
9
+
React lets you add _event handlers_ to your PSX. Event handlers are your own functions that will be triggered in response to interactions like clicking, hovering, focusing form inputs, and so on.
10
10
11
11
</p>
12
12
@@ -18,35 +18,43 @@ React lets you add _event handlers_ to your JSX. Event handlers are your own fun
18
18
19
19
## Adding event handlers
20
20
21
-
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:
21
+
To add an event handler, you will first define a function and then [pass it as a prop](../learn/passing-props-to-a-component.md) to the appropriate PSX tag. For example, here is a button that doesn't do anything yet:
22
22
23
-
```js
24
-
exportdefaultfunctionButton() {
25
-
return<button>I don't do anything</button>;
26
-
}
27
-
```
23
+
=== "app.py"
24
+
25
+
```python
26
+
{% include "../../examples/python/responding_to_events/simple_button.py" start="# start" %}
27
+
```
28
+
29
+
=== ":material-play: Run"
30
+
31
+
```python
32
+
# TODO
33
+
```
28
34
29
35
You can make it show a message when a user clicks by following these three steps:
30
36
31
-
1. Declare a function called `handleClick` _inside_ your `Button` component.
32
-
2. Implement the logic inside that function (use `alert` to show the message).
33
-
3. Add `on_click={handleClick}` to the `<button>` JSX.
37
+
1. Declare a function called `handle_click`_inside_ your `#!python def button():` component.
38
+
2. Implement the logic inside that function (use `print` to show the message).
39
+
3. Add `on_click=handle_click` to the `html.button` PSX.
{% include "../../examples/python/responding_to_events/simple_button_event.py" end="# end" %}
45
+
```
44
46
45
-
```css
46
-
button {
47
-
margin-right: 10px;
48
-
}
49
-
```
47
+
=== "styles.css"
48
+
49
+
```css
50
+
{% include "../../examples/css/responding_to_events/simple_button_event.css" %}
51
+
```
52
+
53
+
=== ":material-play: Run"
54
+
55
+
```python
56
+
# TODO
57
+
```
50
58
51
59
You defined the `handleClick` function and then [passed it as a prop](/learn/passing-props-to-a-component) to `<button>`. `handleClick` is an **event handler.** Event handler functions:
0 commit comments