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 +81,7 @@ Now that your component's code loads on demand, you also need to specify what sh
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:
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