Skip to content

Commit 356da3c

Browse files
committed
doc(responding_to_events): translate in french
1 parent de2e000 commit 356da3c

File tree

1 file changed

+36
-32
lines changed

1 file changed

+36
-32
lines changed

src/content/learn/responding-to-events.md

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,56 @@
11
---
2-
title: Responding to Events
2+
title: Réagir aux événements
33
---
44

55
<Intro>
66

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.
88

99
</Intro>
1010

1111
<YouWillLearn>
1212

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
1616

1717
</YouWillLearn>
1818

19-
## Adding event handlers {/*adding-event-handlers*/}
19+
## Ajouter des gestionnaires d’événements {/*adding-event-handlers*/}
2020

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 :
2222

2323
<Sandpack>
2424

2525
```js
2626
export default function Button() {
2727
return (
2828
<button>
29-
I don't do anything
29+
Je ne fais rien
3030
</button>
3131
);
3232
}
3333
```
3434

3535
</Sandpack>
3636

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 :
3838

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.
4242

4343
<Sandpack>
4444

4545
```js
4646
export default function Button() {
4747
function handleClick() {
48-
alert('You clicked me!');
48+
alert('Vous m’avez cliqué !');
4949
}
5050

5151
return (
5252
<button onClick={handleClick}>
53-
Click me
53+
Cliquez-moi
5454
</button>
5555
);
5656
}
@@ -62,61 +62,65 @@ button { margin-right: 10px; }
6262

6363
</Sandpack>
6464

65-
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 :
6666

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.
6969

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.
7171

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 :
7373

7474
```jsx
7575
<button onClick={function handleClick() {
76-
alert('You clicked me!');
76+
alert('Vous m’avez cliqué !');
7777
}}>
7878
```
7979

80-
Or, more concisely, using an arrow function:
80+
Ou vous pouvez être plus concis en utilisant une fonction fléchée :
8181

8282
```jsx
8383
<button onClick={() => {
84-
alert('You clicked me!');
84+
alert('Vous m’avez cliqué !');
8585
}}>
8686
```
8787

88-
All of these styles are equivalent. Inline event 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.
8989

9090
<Pitfall>
9191

92-
Functions passed to event handlers must be passed, not called. For example:
92+
Vous devez passer une fonction comme gestionnaire d'événements plutôt que de l'appeler. Par exemple :
9393

94-
| passing a function (correct) | calling a function (incorrect) |
94+
| Passer une fonction (correct) | Appeler une fonction (incorrect) |
9595
| -------------------------------- | ---------------------------------- |
9696
| `<button onClick={handleClick}>` | `<button onClick={handleClick()}>` |
9797

98-
The difference is subtle. In the first example, the `handleClick` function is passed as an `onClick` event handler. This tells React to remember it and only call your function when the user clicks the button.
98+
La différence est subtile. Dans le premier exemple, on passe la fonction `handleClick` comme gestionnaire d'événements à `onClick`. Ça indique à React de la mémoriser et d'appeler votre fonction uniquement lorsque l'utilisateur clique sur le bouton.
9999

100-
In the second example, the `()` at the end of `handleClick()` fires the function *immediately* during [rendering](/learn/render-and-commit), without any clicks. This is because JavaScript inside the [JSX `{` and `}`](/learn/javascript-in-jsx-with-curly-braces) executes right away.
100+
Dans le deuxième exemple, on appelle la fonction `handleClick()` avec `()` à la fin, ce qui déclenche la fonction immédiatement pendant [le rendu](/learn/render-and-commit), sans aucun clic. C'est dû au fait que le code JavaScript à l'intérieur des [balises `{` et `}` du JSX](/learn/javascript-in-jsx-with-curly-braces) s'exécute immédiatement.
101101

102102
When you write code inline, the same pitfall presents itself in a different way:
103103

104-
| passing a function (correct) | calling a function (incorrect) |
104+
Quand vous écrivez du code en ligne, le même écueil se présente de manière différente :
105+
106+
| Passer une fonction (correct) | Appeler une fonction (incorrect) |
105107
| --------------------------------------- | --------------------------------- |
106108
| `<button onClick={() => alert('...')}>` | `<button onClick={alert('...')}>` |
107109

108110

109-
Passing inline code like this won't fire on click—it fires every time the component renders:
111+
Le code suivant passé en ligne à `onClick` ne se déclenchera pas lors du clic, mais à chaque fois que le composant se rendra :
110112

111113
```jsx
112-
// This alert fires when the component renders, not when clicked!
113-
<button onClick={alert('You clicked me!')}>
114+
// La méthode alert se déclenchera à chaque rendu, mais pas au clic du bouton !
115+
<button onClick={alert('Vous m’avez cliqué !')}>
114116
```
115117

116118
If you want to define your event handler inline, wrap it in an anonymous function like so:
117119

120+
Si vous souhaitez définir votre gestionnaire d'événements en ligne, enrobez-le dans une fonction anonyme de la manière suivante :
121+
118122
```jsx
119-
<button onClick={() => alert('You clicked me!')}>
123+
<button onClick={() => alert('Vous m’avez cliqué !')}>
120124
```
121125

122126
Rather than executing the code inside with every render, this creates a function to be called later.

0 commit comments

Comments
 (0)