Skip to content

Commit eecca5a

Browse files
committed
translate lazy page
1 parent c78beb2 commit eecca5a

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

src/content/reference/react/lazy.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: lazy
44

55
<Intro>
66

7-
`lazy` lets you defer loading component's code until it is rendered for the first time.
7+
`lazy` vous permet de différer le chargement du composant jusqu'à son affichage pour la première fois.
88

99
```js
1010
const SomeComponent = lazy(load)
@@ -16,72 +16,72 @@ const SomeComponent = lazy(load)
1616

1717
---
1818

19-
## Reference {/*reference*/}
19+
## Référence {/*reference*/}
2020

2121
### `lazy(load)` {/*lazy*/}
2222

23-
Call `lazy` outside your components to declare a lazy-loaded React component:
23+
Appelez `lazy` en dehors de vos composants pour déclarer un composant React lazy-loaded:
2424

2525
```js
2626
import { lazy } from 'react';
2727

2828
const MarkdownPreview = lazy(() => import('./MarkdownPreview.js'));
2929
```
3030

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

33-
#### Parameters {/*parameters*/}
33+
#### Paramètres {/*parameters*/}
3434

35-
* `load`: A function that returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) or another *thenable* (a Promise-like object with a `then` method). React will not call `load` until the first time you attempt to render the returned component. After React first calls `load`, it will wait for it to resolve, and then render the resolved value as a React component. Both the returned Promise and the Promise's resolved value will be cached, so React will not call `load` more than once. If the Promise rejects, React will `throw` the rejection reason for the nearest Error Boundary to handle.
35+
* `load`: Une fonction qui renvoie une [Promesse](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) ou d'autres *thenable* (un objet de promesse résolue avec la méthode `then`). React n'appelera pas `load` avant la première fois que vous tentez d'afficher le composant renvoyé. Après que React ait appelé `load` pour la première fois, il patientera pour qu'il soit résolu, et ensuite affichera la valeur résolue comme un composant React. La promesse renvoyée et la promesse résolue seront toutes deux mises en cache, et React n'appelera pas `load` plus d'une fois. Si la promesse est rejetée, React `levera` la raison du rejet pour la limite d'erreur la plus proche à gérer.
3636

37-
#### Returns {/*returns*/}
37+
#### Renvois {/*returns*/}
3838

39-
`lazy` returns a React component you can render in your tree. While the code for the lazy component is still loading, attempting to render it will *suspend.* Use [`<Suspense>`](/reference/react/Suspense) to display a loading indicator while it's loading.
39+
`lazy` renvoi un composant React que vous pouvez faire le rendu dans votre arborescence. Pendant que le code du composant lazy est en cours de chargement, la tentative de l'afficher sera *suspendue*. Utilisez [`<Suspense>`](/reference/react/Suspense) pour afficher un indicateur de chargement pendant le chargement.
4040

4141
---
4242

43-
### `load` function {/*load*/}
43+
### La fonction `load` {/*load*/}
4444

45-
#### Parameters {/*load-parameters*/}
45+
#### Paramètres {/*load-parameters*/}
4646

47-
`load` receives no parameters.
47+
`load` ne reçoit pas de paramètres.
4848

49-
#### Returns {/*load-returns*/}
49+
#### Renvois {/*load-returns*/}
5050

51-
You need to return a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) or some other *thenable* (a Promise-like object with a `then` method). It needs to eventually resolve to a valid React component type, such as a function, [`memo`](/reference/react/memo), or a [`forwardRef`](/reference/react/forwardRef) component.
51+
Vous aurez besoin de renvoyer une [Promesse](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) ou d'autres *thenable* (un objet de promesse résolue avec la méthode `then`). il doit finalement se comporter comme un composant React valide, tel une qu'une fonction, [`memo`](/reference/react/memo), ou un composant [`forwardRef`](/reference/react/forwardRef).
5252

5353
---
5454

55-
## Usage {/*usage*/}
55+
## Mode d’utilisation {/*usage*/}
5656

57-
### Lazy-loading components with Suspense {/*suspense-for-code-splitting*/}
57+
### Composants Lazy-loading avec Suspense {/*suspense-for-code-splitting*/}
5858

59-
Usually, you import components with the static [`import`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) declaration:
59+
En général, vous importez vos composants avec la déclaration statique [`import`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import) :
6060

6161
```js
6262
import MarkdownPreview from './MarkdownPreview.js';
6363
```
6464

65-
To defer loading this component's code until it's rendered for the first time, replace this import with:
65+
Pour différer le chargement du code de ce composant jusqu'à ce qu'il affiche pour la première fois, remplacez cette importation avec :
6666

6767
```js
6868
import { lazy } from 'react';
6969

7070
const MarkdownPreview = lazy(() => import('./MarkdownPreview.js'));
7171
```
7272

73-
This code relies on [dynamic `import()`,](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) which might require support from your bundler or framework.
73+
Ce code s'appuie sur [l'importation dynamique `import()`,](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) ce qui peut nécessiter l'aide de votre bundler ou framework.
7474

75-
Now that your component's code loads on demand, you also need to specify what should be displayed while it is loading. You can do this by wrapping the lazy component or any of its parents into a [`<Suspense>`](/reference/react/Suspense) boundary:
75+
Maintenant que le code de votre composant se charge à la demande, vous aurez besoin de spécifier ce qui devra afficher pendant son chargement. Vous pouvez faire cela en enrobant le composant lazy ou l'un de ses parents dans une limitte [`<Suspense>`](/reference/react/Suspense) :
7676

7777
```js {1,4}
7878
<Suspense fallback={<Loading />}>
79-
<h2>Preview</h2>
79+
<h2>Aperçu</h2>
8080
<MarkdownPreview />
8181
</Suspense>
8282
```
8383

84-
In this example, the code for `MarkdownPreview` won't be loaded until you attempt to render it. If `MarkdownPreview` hasn't loaded yet, `Loading` will be shown in its place. Try ticking the checkbox:
84+
Dans cet exemple, le code de `MarkdownPreview` ne sera pas chargé jusqu'à ce que vous essayez de l'afficher. Si `MarkdownPreview` n'est pas encore chargé, `Loading` sera affiché à sa place. Essayez de cocher la case :
8585

8686
<Sandpack>
8787

@@ -93,26 +93,26 @@ const MarkdownPreview = lazy(() => delayForDemo(import('./MarkdownPreview.js')))
9393

9494
export default function MarkdownEditor() {
9595
const [showPreview, setShowPreview] = useState(false);
96-
const [markdown, setMarkdown] = useState('Hello, **world**!');
96+
const [markdown, setMarkdown] = useState('Bonjour, **monde**!');
9797
return (
9898
<>
9999
<textarea value={markdown} onChange={e => setMarkdown(e.target.value)} />
100100
<label>
101101
<input type="checkbox" checked={showPreview} onChange={e => setShowPreview(e.target.checked)} />
102-
Show preview
102+
Afficher l'aperçu
103103
</label>
104104
<hr />
105105
{showPreview && (
106106
<Suspense fallback={<Loading />}>
107-
<h2>Preview</h2>
107+
<h2>Aperçu</h2>
108108
<MarkdownPreview markdown={markdown} />
109109
</Suspense>
110110
)}
111111
</>
112112
);
113113
}
114114
115-
// Add a fixed delay so you can see the loading state
115+
// Ajouter un délai fixe pour voir l'état de chargement
116116
function delayForDemo(promise) {
117117
return new Promise(resolve => {
118118
setTimeout(resolve, 2000);
@@ -122,7 +122,7 @@ function delayForDemo(promise) {
122122
123123
```js Loading.js
124124
export default function Loading() {
125-
return <p><i>Loading...</i></p>;
125+
return <p><i>Chargement...</i></p>;
126126
}
127127
```
128128
@@ -175,34 +175,34 @@ body {
175175
176176
</Sandpack>
177177
178-
This demo loads with an artificial delay. The next time you untick and tick the checkbox, `Preview` will be cached, so there will be no loading state. To see the loading state again, click "Reset" on the sandbox.
178+
Cette démo se charge avec un retard artificiel. La prochaine fois que vous décochez et cochez la case, `Preview` sera mis en cache, il n'y aura donc pas d'état de chargement. Pour voir à nouveau l'état de chargement, Cliquez sur "Réinitialiser" dans le bac à sable.
179179
180-
[Learn more about managing loading states with Suspense.](/reference/react/Suspense)
180+
[En savoir plus sur la gestion des états de chargement avec Suspense](/reference/react/Suspense).
181181
182182
---
183183
184-
## Troubleshooting {/*troubleshooting*/}
184+
## Résolution des problèmes {/*troubleshooting*/}
185185
186-
### My `lazy` component's state gets reset unexpectedly {/*my-lazy-components-state-gets-reset-unexpectedly*/}
186+
### L'état de mon composant `lazy` se réinitialise de façon inattendue {/*my-lazy-components-state-gets-reset-unexpectedly*/}
187187
188-
Do not declare `lazy` components *inside* other components:
188+
Ne déclarez pas les composants `lazy` *à l'interieur* d'autres composants
189189
190190
```js {4-5}
191191
import { lazy } from 'react';
192192

193193
function Editor() {
194-
// 🔴 Bad: This will cause all state to be reset on re-renders
194+
// 🔴 Mauvais: Cela entraînera la réinitialisation de tous les états lors des réaffichages
195195
const MarkdownPreview = lazy(() => import('./MarkdownPreview.js'));
196196
// ...
197197
}
198198
```
199199
200-
Instead, always declare them at the top level of your module:
200+
Au lieu de cela, déclarez-les toujours au début de votre module :
201201
202202
```js {3-4}
203203
import { lazy } from 'react';
204204

205-
//Good: Declare lazy components outside of your components
205+
//Parfait: Déclarez les composants lazy en déhors de vos composants
206206
const MarkdownPreview = lazy(() => import('./MarkdownPreview.js'));
207207

208208
function Editor() {

0 commit comments

Comments
 (0)