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
*`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/docs/Web/JavaScript/Reference/Global_Objects/Promise)ou un*thenable* (un objet doté d'une méthode`then`compatible). React n'appellera pas `load`tant que vous ne tenterez pas d'afficher le composant renvoyé. Après que React a appelé`load` pour la première fois, il patientera pour que la promesse s'établisse, puis affichera la valeur accomplie comme composant React. Tant la promesse renvoyée que sa valeur accomplie seront mises en cache, et React ne rappellera pas`load`. Si la promesse rejette, React lèvera (`throw`) la raison du rejet (généralement une `Error`) pour que le périmètre d'erreur le plus proche la gère.
36
36
37
-
#### Returns {/*returns*/}
37
+
#### Valeur renvoyée {/*returns*/}
38
38
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`renvoie un composant React que vous pouvez afficher dans votre arborescence. Pendant que le code du composant chargé à la demande se charge, toute tentative de l'afficher *suspend*. Utilisez[`<Suspense>`](/reference/react/Suspense)pour afficher un indicateur de chargement pendant ce temps-là.
40
40
41
41
---
42
42
43
-
### `load` function {/*load*/}
43
+
### La fonction `load` {/*load*/}
44
44
45
-
#### Parameters {/*load-parameters*/}
45
+
#### Paramètres {/*load-parameters*/}
46
46
47
-
`load`receives no parameters.
47
+
`load`ne prend aucun paramètre.
48
48
49
-
#### Returns {/*load-returns*/}
49
+
#### Valeur renvoyée {/*load-returns*/}
50
50
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/docs/Web/JavaScript/Reference/Global_Objects/Promise)ou un *thenable* (un objet doté d'une méthode`then`compatible). La valeur accomplie doit finalement se comporter comme un composant React valide, tel une qu'une fonction, un composant [`memo`](/reference/react/memo), ou un composant [`forwardRef`](/reference/react/forwardRef).
52
52
53
53
---
54
54
55
-
## Usage {/*usage*/}
55
+
## Utilisation {/*usage*/}
56
56
57
-
### Lazy-loading components with Suspense {/*suspense-for-code-splitting*/}
57
+
### Charger des composants à la demande avec Suspense {/*suspense-for-code-splitting*/}
58
58
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/docs/Web/JavaScript/Reference/Statements/import):
60
60
61
61
```js
62
62
importMarkdownPreviewfrom'./MarkdownPreview.js';
63
63
```
64
64
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 :
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/docs/Web/JavaScript/Reference/Operators/import), ce qui peut nécessiter une prise en charge de votre *bundler* ou framework.
74
74
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 devrait être affiché pendant son chargement. Vous pouvez le faire en enrobant le composant chargé à la demande ou l'un de ses parents dans un périmètre [`<Suspense>`](/reference/react/Suspense):
76
76
77
77
```js {1,4}
78
78
<Suspense fallback={<Loading />}>
79
-
<h2>Preview</h2>
79
+
<h2>Aperçu</h2>
80
80
<MarkdownPreview />
81
81
</Suspense>
82
82
```
83
83
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 essayiez de l'afficher. Si`MarkdownPreview`n'est pas encore chargé, `Loading`sera affiché à sa place. Essayez de cocher la case :
//Add a fixed delay so you can see the loading state
115
+
//Ajouter un délai fixe pour voir l’état de chargement
116
116
functiondelayForDemo(promise) {
117
117
returnnewPromise(resolve=> {
118
118
setTimeout(resolve, 2000);
@@ -122,7 +122,7 @@ function delayForDemo(promise) {
122
122
123
123
```js Loading.js
124
124
exportdefaultfunctionLoading() {
125
-
return<p><i>Loading...</i></p>;
125
+
return<p><i>Chargement...</i></p>;
126
126
}
127
127
```
128
128
@@ -175,34 +175,34 @@ body {
175
175
176
176
</Sandpack>
177
177
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.
179
179
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).
181
181
182
182
---
183
183
184
-
## Troubleshooting {/*troubleshooting*/}
184
+
## Dépannage {/*troubleshooting*/}
185
185
186
-
### My `lazy`component's state gets reset unexpectedly {/*my-lazy-components-state-gets-reset-unexpectedly*/}
186
+
### L'état de mon composant `lazy`est réinitialisé de façon inattendue {/*my-lazy-components-state-gets-reset-unexpectedly*/}
187
187
188
-
Do not declare `lazy`components *inside* other components:
188
+
Ne déclarez pas les composants `lazy`*à l'intérieur* d'autres composants :
189
189
190
190
```js {4-5}
191
191
import { lazy } from'react';
192
192
193
193
functionEditor() {
194
-
// 🔴 Bad: This will cause all state to be reset on re-renders
194
+
// 🔴 Erroné : ça entraînera la réinitialisation de tous les états lors des réaffichages
0 commit comments