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.
`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.
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.
Usually, you import components with the static [`import`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import)declaration:
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.
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:
@@ -81,7 +83,7 @@ Now that your component's code loads on demand, you also need to specify what sh
81
83
</Suspense>
82
84
```
83
85
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:
@@ -112,7 +114,7 @@ export default function MarkdownEditor() {
112
114
);
113
115
}
114
116
115
-
//Add a fixed delay so you can see the loading state
117
+
//添加一个固定的延迟时间,以便你可以看到加载状态
116
118
functiondelayForDemo(promise) {
117
119
returnnewPromise(resolve=> {
118
120
setTimeout(resolve, 2000);
@@ -175,34 +177,34 @@ body {
175
177
176
178
</Sandpack>
177
179
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.
0 commit comments