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: src/content/learn/responding-to-events.md
+23-23Lines changed: 23 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,56 +1,56 @@
1
1
---
2
-
title: Responding to Events
2
+
title: Réagir aux événements
3
3
---
4
4
5
5
<Intro>
6
6
7
-
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.
7
+
React vous permet d’ajouter des *gestionnaires d’événements* à votre JSX. Les gestionnaires d’événements sont vos propres fonctions qui seront déclenchées en réponse aux interactions de l’utilisateur telles que des clics, survols, activations de champs de saisie de formulaires, etc.
8
8
9
9
</Intro>
10
10
11
11
<YouWillLearn>
12
12
13
-
*Different ways to write an event handler
14
-
*How to pass event handling logic from a parent component
15
-
*How events propagate and how to stop them
13
+
*Différentes façons d’écrire un gestionnaire d’événements
14
+
*Comment passer la logique de gestion d’événements depuis un composant parent
15
+
*Comment les événements se propagent et comment les arrêter
## Ajouter des gestionnaires d’événements {/*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
+
Pour ajouter un gestionnaire d’événements, vous devrez d’abord définir une fonction et [la passer en tant que prop](/learn/passing-props-to-a-component)à la balise JSX appropriée. Par exemple, voici un bouton qui ne fait rien pour le moment :
22
22
23
23
<Sandpack>
24
24
25
25
```js
26
26
exportdefaultfunctionButton() {
27
27
return (
28
28
<button>
29
-
I don't do anything
29
+
Je ne fais rien
30
30
</button>
31
31
);
32
32
}
33
33
```
34
34
35
35
</Sandpack>
36
36
37
-
You can make it show a message when a user clicks by following these three steps:
37
+
Vous pouvez faire afficher un message après un clic sur le bouton en suivant ces trois étapes :
38
38
39
-
1. Declare a function called `handleClick` *inside* your `Button` component.
40
-
2. Implement the logic inside that function (use `alert` to show the message).
41
-
3. Add `onClick={handleClick}` to the `<button>` JSX.
39
+
1.Déclarez une fonction appelée`handleClick`*dans* votre composant `Button`.
40
+
2.Implémentez la logique de cette fonction (utilisez`alert`pour afficher le message).
41
+
3.Ajoutez`onClick={handleClick}`au `<button>` en JSX.
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:
65
+
Vous avez défini la fonction `handleClick`puis l'avez [passée en tant que prop](/learn/passing-props-to-a-component)à`<button>`. `handleClick`est un**gestionnaire d'événements**. Les gestionnaires d'événements sont des fonctions qui :
66
66
67
-
* Are usually defined *inside* your components.
68
-
* Have names that start with `handle`, followed by the name of the event.
67
+
*Sont généralement définies à l'intérieur de vos composants.
68
+
*Ont des noms qui commencent par `handle`, suivi du nom de l'événement.
69
69
70
-
By convention, it is common to name event handlers as `handle` followed by the event name. You'll often see`onClick={handleClick}`, `onMouseEnter={handleMouseEnter}`, and so on.
70
+
Par convention, il est courant de nommer les gestionnaires d'événements en utilisant `handle`suivi du nom de l'événement. Vous verrez souvent`onClick={handleClick}`, `onMouseEnter={handleMouseEnter}`, et ainsi de suite.
71
71
72
-
Alternatively, you can define an event handler inline in the JSX:
72
+
Vous pouvez aussi définir un gestionnaire d'événements en ligne dans le JSX:
73
73
74
74
```jsx
75
75
<button onClick={functionhandleClick() {
76
-
alert('You clicked me!');
76
+
alert('Vous m’avez cliqué !');
77
77
}}>
78
78
```
79
79
80
-
Or, more concisely, using an arrow function:
80
+
Ou vous pouvez être plus concis en utilisant une fonction fléchée :
81
81
82
82
```jsx
83
83
<button onClick={() => {
84
-
alert('You clicked me!');
84
+
alert('Vous m’avez cliqué !');
85
85
}}>
86
86
```
87
87
88
-
All of these styles are equivalent. Inlineevent handlers are convenient for short functions.
88
+
Tous ces styles sont équivalents. Les gestionnaires d'événements en ligne sont pratiques pour les fonctions courtes.
0 commit comments