Skip to content

Commit dcead23

Browse files
committed
add french translation for findDOMNode
1 parent cad57d0 commit dcead23

File tree

1 file changed

+53
-52
lines changed

1 file changed

+53
-52
lines changed

src/content/reference/react-dom/findDOMNode.md

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ title: findDOMNode
44

55
<Deprecated>
66

7-
This API will be removed in a future major version of React. [See the alternatives.](#alternatives)
7+
Cette API sera retirée dans une future version majeure de React. [Voir les solutions alternatives](#alternatives).
88

99
</Deprecated>
1010

1111
<Intro>
1212

13-
`findDOMNode` finds the browser DOM node for a React [class component](/reference/react/Component) instance.
13+
`findDOMNode` trouve le nœud du navigateur pour une instance React à [composant à base de classe](/reference/react/Component).
1414

1515
```js
1616
const domNode = findDOMNode(componentInstance)
@@ -22,46 +22,47 @@ const domNode = findDOMNode(componentInstance)
2222

2323
---
2424

25-
## Reference {/*reference*/}
25+
## Référence {/*reference*/}
2626

2727
### `findDOMNode(componentInstance)` {/*finddomnode*/}
2828

29-
Call `findDOMNode` to find the browser DOM node for a given React [class component](/reference/react/Component) instance.
29+
Appeler `findDOMNode` pour trouver le nœud du navigateur pour une instance React à [composant à base de classe](/reference/react/Component) donnée.
3030

3131
```js
3232
import { findDOMNode } from 'react-dom';
3333

3434
const domNode = findDOMNode(componentInstance);
3535
```
3636

37-
[See more examples below.](#usage)
37+
[Voir les exemples ci-dessous](#usage).
3838

39-
#### Parameters {/*parameters*/}
39+
#### Paramètres {/*parameters*/}
4040

41-
* `componentInstance`: An instance of the [`Component`](/reference/react/Component) subclass. For example, `this` inside a class component.
41+
* `componentInstance` : Une instance de la sous-classe du [`Component`](/reference/react/Component). Par exemple `this` dans un composant à base de classe.
4242

4343

44-
#### Returns {/*returns*/}
44+
#### Valeur renvoyée {/*returns*/}
4545

46-
`findDOMNode` returns the first closest browser DOM node within the given `componentInstance`. When a component renders to `null`, or renders `false`, `findDOMNode` returns `null`. When a component renders to a string, `findDOMNode` returns a text DOM node containing that value.
46+
`findDOMNode` renvoie le plus proche nœud du DOM du navigateur dans une `componentInstance` donnée. Lorsqu'un composant fait le rendu à `null`, fait le rendu à `false`, `findDOMNode` renvoie `null`. Lorsqu'un composant fait le rendu d'une string, `findDOMNode` renvoie un nœud DOM sous forme de texte contenant cette valeur.
4747

48-
#### Caveats {/*caveats*/}
48+
#### Limitations {/*caveats*/}
4949

50-
* A component may return an array or a [Fragment](/reference/react/Fragment) with multiple children. In that case `findDOMNode`, will return the DOM node corresponding to the first non-empty child.
50+
* Un composant peut renvoyer un tableau ou un [Fragment](/reference/react/Fragment) avec plusieurs enfants. Dans ce cas `findDOMNode`, renverra le nœud du DOM correspondant au premier enfant non-vide.
5151

52-
* `findDOMNode` only works on mounted components (that is, components that have been placed in the DOM). If you try to call this on a component that has not been mounted yet (like calling `findDOMNode()` in `render()` on a component that has yet to be created), an exception will be thrown.
52+
* `findDOMNode` fonctionne seulement sur les composants montés (c'est-à-dire, les composants qui ont été placés dans le DOM). Si vous essayez d'appeler `this` sur un composant qui n'a pas encore été monté (comme l'appel de `findDOMNode()` dans `render()` sur un composant qui doit être crée), une exception sera levée.
5353

54-
* `findDOMNode` only returns the result at the time of your call. If a child component renders a different node later, there is no way for you to be notified of this change.
54+
* `findDOMNode` renvoie seulement le résultat au moment de votre appel. Si un composant enfant fait plutard le rendu d'un nœud différent, vous n'avez aucun moyen d'être informé de ce changement.
5555

56-
* `findDOMNode` accepts a class component instance, so it can't be used with function components.
56+
* `findDOMNode` accepte une instance de composant à base de classe, il ne peut être utilisé avec les fonctions composants.
5757

5858
---
5959

60-
## Usage {/*usage*/}
60+
## Utilisation {/*usage*/}
6161

62-
### Finding the root DOM node of a class component {/*finding-the-root-dom-node-of-a-class-component*/}
62+
### Trouver le nœud racine du DOM d'un composant à base de classe {/*finding-the-root-dom-node-of-a-class-component*/}
6363

64-
Call `findDOMNode` with a [class component](/reference/react/Component) instance (usually, `this`) to find the DOM node it has rendered.
64+
65+
Appeler `findDOMNode` avec une instance de [composant à base de classe](/reference/react/Component) (généralement, `this`) pour trouver le nœud du DOM qu'il a affiché.
6566

6667
```js {3}
6768
class AutoselectingInput extends Component {
@@ -71,12 +72,12 @@ class AutoselectingInput extends Component {
7172
}
7273

7374
render() {
74-
return <input defaultValue="Hello" />
75+
return <input defaultValue="Bonjour" />
7576
}
7677
}
7778
```
7879

79-
Here, the `input` variable will be set to the `<input>` DOM element. This lets you do something with it. For example, when clicking "Show example" below mounts the input, [`input.select()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/select) selects all text in the input:
80+
Ici, la variable de `input` sera défini sur l'élément DOM `<input>`. Cela vous permet de faire quelque chose avec. Par exemple, en cliquant « voir l'exemple » ci-dessous, le champ de saisi est monté, [`input.select()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/select) sélectionne tout le text dans le champ :
8081

8182
<Sandpack>
8283

@@ -89,7 +90,7 @@ export default function App() {
8990
return (
9091
<>
9192
<button onClick={() => setShow(true)}>
92-
Show example
93+
Voir l'exemple
9394
</button>
9495
<hr />
9596
{show && <AutoselectingInput />}
@@ -109,7 +110,7 @@ class AutoselectingInput extends Component {
109110
}
110111
111112
render() {
112-
return <input defaultValue="Hello" />
113+
return <input defaultValue="Bonjour" />
113114
}
114115
}
115116
@@ -122,9 +123,9 @@ export default AutoselectingInput;
122123
123124
## Alternatives {/*alternatives*/}
124125
125-
### Reading component's own DOM node from a ref {/*reading-components-own-dom-node-from-a-ref*/}
126+
### Lecture du nœud DOM à partir d'une ref {/*reading-components-own-dom-node-from-a-ref*/}
126127

127-
Code using `findDOMNode` is fragile because the connection between the JSX node and the code manipulating the corresponding DOM node is not explicit. For example, try wrapping this `<input />` into a `<div>`:
128+
Le code qui utilise `findDOMNode` est fragile parce que la connection entre le nœud JSX et le code manipulant le nœud du DOM correspondant n'est pas explicite. Par exemple, essayez d'enrober ce `<input />` dans un `<div>` :
128129

129130
<Sandpack>
130131

@@ -137,7 +138,7 @@ export default function App() {
137138
return (
138139
<>
139140
<button onClick={() => setShow(true)}>
140-
Show example
141+
Voir l'exemple
141142
</button>
142143
<hr />
143144
{show && <AutoselectingInput />}
@@ -156,7 +157,7 @@ class AutoselectingInput extends Component {
156157
input.select()
157158
}
158159
render() {
159-
return <input defaultValue="Hello" />
160+
return <input defaultValue="Bonjour" />
160161
}
161162
}
162163
@@ -165,9 +166,9 @@ export default AutoselectingInput;
165166

166167
</Sandpack>
167168

168-
This will break the code because now, `findDOMNode(this)` finds the `<div>` DOM node, but the code expects an `<input>` DOM node. To avoid these kinds of problems, use [`createRef`](/reference/react/createRef) to manage a specific DOM node.
169+
Le code sera interrompu maintenant, `findDOMNode(this)` trouve le nœud `<div>` du DOM, mais le code attend un nœud DOM `<input>`. Pour éviter ce genre de problèmes, utilisez [`createRef`](/reference/react/createRef) pour gérer un nœud DOM spécifique.
169170

170-
In this example, `findDOMNode` is no longer used. Instead, `inputRef = createRef(null)` is defined as an instance field on the class. To read the DOM node from it, you can use `this.inputRef.current`. To attach it to the JSX, you render `<input ref={this.inputRef} />`. This connects the code using the DOM node to its JSX:
171+
Dans cet exemple, `findDOMNode` n'est plus utilisé. Par contre, `inputRef = createRef(null)` est défini comme champ d'instance de la classe. Pour lire le nœud du DOM à partir de celui-ci, vous pouvez utiliser `this.inputRef.current`. Pour le rattacher au JSX, vous faites le rendu `<input ref={this.inputRef} />`. Cela connecte le code utilisant le nœud DOM à son JSX :
171172

172173
<Sandpack>
173174

@@ -180,7 +181,7 @@ export default function App() {
180181
return (
181182
<>
182183
<button onClick={() => setShow(true)}>
183-
Show example
184+
Afficher l'exemple
184185
</button>
185186
<hr />
186187
{show && <AutoselectingInput />}
@@ -202,7 +203,7 @@ class AutoselectingInput extends Component {
202203
203204
render() {
204205
return (
205-
<input ref={this.inputRef} defaultValue="Hello" />
206+
<input ref={this.inputRef} defaultValue="Bonjour" />
206207
);
207208
}
208209
}
@@ -212,7 +213,7 @@ export default AutoselectingInput;
212213

213214
</Sandpack>
214215

215-
In modern React without class components, the equivalent code would call [`useRef`](/reference/react/useRef) instead:
216+
Dans les versions modernes de React sans les composants à base de classe, le code équivalent appelerait [`useRef`](/reference/react/useRef) à la place :
216217

217218
<Sandpack>
218219

@@ -225,7 +226,7 @@ export default function App() {
225226
return (
226227
<>
227228
<button onClick={() => setShow(true)}>
228-
Show example
229+
Voir l'exemple
229230
</button>
230231
<hr />
231232
{show && <AutoselectingInput />}
@@ -245,19 +246,19 @@ export default function AutoselectingInput() {
245246
input.select();
246247
}, []);
247248
248-
return <input ref={inputRef} defaultValue="Hello" />
249+
return <input ref={inputRef} defaultValue="Bonjour" />
249250
}
250251
```
251252

252253
</Sandpack>
253254

254-
[Read more about manipulating the DOM with refs.](/learn/manipulating-the-dom-with-refs)
255+
[En savoir plus sur la manipulation du DOM avec les refs](/learn/manipulating-the-dom-with-refs).
255256

256257
---
257258

258-
### Reading a child component's DOM node from a forwarded ref {/*reading-a-child-components-dom-node-from-a-forwarded-ref*/}
259+
### Lecture d'un nœud DOM d'un composant enfant à partir d'un ref transmis {/*reading-a-child-components-dom-node-from-a-forwarded-ref*/}
259260
260-
In this example, `findDOMNode(this)` finds a DOM node that belongs to another component. The `AutoselectingInput` renders `MyInput`, which is your own component that renders a browser `<input>`.
261+
Dans cet exemple, `findDOMNode(this)` trouve un nœud DOM qui appartient à un autre composant. Le composant `AutoselectingInput` fait le rendu de `MyInput`, qui est votre propre composant qui affiche un navigateur `<input>`.
261262
262263
<Sandpack>
263264
@@ -270,7 +271,7 @@ export default function App() {
270271
return (
271272
<>
272273
<button onClick={() => setShow(true)}>
273-
Show example
274+
Voir l'exemple
274275
</button>
275276
<hr />
276277
{show && <AutoselectingInput />}
@@ -299,20 +300,20 @@ export default AutoselectingInput;
299300

300301
```js MyInput.js
301302
export default function MyInput() {
302-
return <input defaultValue="Hello" />;
303+
return <input defaultValue="Bonjour" />;
303304
}
304305
```
305306

306307
</Sandpack>
307308

308-
Notice that calling `findDOMNode(this)` inside `AutoselectingInput` still gives you the DOM `<input>`--even though the JSX for this `<input>` is hidden inside the `MyInput` component. This seems convenient for the above example, but it leads to fragile code. Imagine that you wanted to edit `MyInput` later and add a wrapper `<div>` around it. This would break the code of `AutoselectingInput` (which expects to find an `<input>`).
309+
Notez que l'appel de `findDOMNode(this)` à l'intérieur de `AutoselectingInput` vous donne toujours le DOM `<input>` - même si le JSX de ce `<input>` est masqué à l'intérieur du composant `MyInput`. Cela semble pratique dans l'exemple ci-dessus, mais il conduit à un code fragile. Imaginez que vous voulez modifier `MyInput` plutard et l'enrober autour d'un `<div>`. Cela ne respectera pas le code de `AutoselectingInput` (qui attend de trouver un `<input>`).
309310

310-
To replace `findDOMNode` in this example, the two components need to coordinate:
311+
Pour remplacer `findDOMNode` dans cet exemple, les deux composants doivent être coordonnés :
311312

312-
1. `AutoSelectingInput` should declare a ref, like [in the earlier example](#reading-components-own-dom-node-from-a-ref), and pass it to `<MyInput>`.
313-
2. `MyInput` should be declared with [`forwardRef`](/reference/react/forwardRef) to take that ref and forward it down to the `<input>` node.
313+
1. `AutoSelectingInput` doit déclarer un ref, comme dans [l'exemple précédent](#reading-components-own-dom-node-from-a-ref), et le founir à `<MyInput>`.
314+
2. `MyInput` doit être déclaré avec [`forwardRef`](/reference/react/forwardRef) pour prendre ce ref et le transmettre au nœud `<input>`.
314315

315-
This version does that, so it no longer needs `findDOMNode`:
316+
C'est ce que fait cette version, qui n'a donc plus besoin de `findDOMNode` :
316317

317318
<Sandpack>
318319

@@ -325,7 +326,7 @@ export default function App() {
325326
return (
326327
<>
327328
<button onClick={() => setShow(true)}>
328-
Show example
329+
Afficher l'exemple
329330
</button>
330331
<hr />
331332
{show && <AutoselectingInput />}
@@ -360,15 +361,15 @@ export default AutoselectingInput;
360361
import { forwardRef } from 'react';
361362
362363
const MyInput = forwardRef(function MyInput(props, ref) {
363-
return <input ref={ref} defaultValue="Hello" />;
364+
return <input ref={ref} defaultValue="Bonjour" />;
364365
});
365366
366367
export default MyInput;
367368
```
368369
369370
</Sandpack>
370371
371-
Here is how this code would look like with function components instead of classes:
372+
Voici à quoi ressemblerait ce code avec les fonctions composants au lieu de classes :
372373
373374
<Sandpack>
374375
@@ -381,7 +382,7 @@ export default function App() {
381382
return (
382383
<>
383384
<button onClick={() => setShow(true)}>
384-
Show example
385+
Afficher l'exemple
385386
</button>
386387
<hr />
387388
{show && <AutoselectingInput />}
@@ -402,15 +403,15 @@ export default function AutoselectingInput() {
402403
input.select();
403404
}, []);
404405

405-
return <MyInput ref={inputRef} defaultValue="Hello" />
406+
return <MyInput ref={inputRef} defaultValue="Bonjour" />
406407
}
407408
```
408409

409410
```js MyInput.js
410411
import { forwardRef } from 'react';
411412

412413
const MyInput = forwardRef(function MyInput(props, ref) {
413-
return <input ref={ref} defaultValue="Hello" />;
414+
return <input ref={ref} defaultValue="Bonjour" />;
414415
});
415416

416417
export default MyInput;
@@ -420,16 +421,16 @@ export default MyInput;
420421

421422
---
422423

423-
### Adding a wrapper `<div>` element {/*adding-a-wrapper-div-element*/}
424+
### Ajout d'un élement `<div>` enrobant {/*adding-a-wrapper-div-element*/}
424425

425-
Sometimes a component needs to know the position and size of its children. This makes it tempting to find the children with `findDOMNode(this)`, and then use DOM methods like [`getBoundingClientRect`](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect) for measurements.
426+
Souvent un composant a besoin de connaître la position et la taille de ses enfants. Il est donc tentant de trouver l'enfant avec `findDOMNode(this)`, et utiliser la méthode du DOM comme [`getBoundingClientRect`](https://developer.mozilla.org/fr/docs/Web/API/Element/getBoundingClientRect) pour des mesures.
426427

427-
There is currently no direct equivalent for this use case, which is why `findDOMNode` is deprecated but is not yet removed completely from React. In the meantime, you can try rendering a wrapper `<div>` node around the content as a workaround, and getting a ref to that node. However, extra wrappers can break styling.
428+
Il n'existe actuellement aucun équivalent direct pour ce cas d'utilisation, c'est pourquoi `findDOMNode` est déprécié mais n'a pas encore été retiré complètement de React. En attendant, vous pouvez essayez d'afficher un nœud `<div>` enrobant le contenu comme solution de contournement, et d'obtenir un ref à ce nœud. Cependant, les enveloppes supplémentaires peuvent nuire à la stylisation.
428429

429430
```js
430431
<div ref={someRef}>
431432
{children}
432433
</div>
433434
```
434435

435-
This also applies to focusing and scrolling to arbitrary children.
436+
Cela s'applique également à la focalisation et au défilement vers des enfants arbitraires.

0 commit comments

Comments
 (0)