React lazy components: Difference between revisions
From wikinotes
(Created page with " = Lazy Component Imports = <blockquote> A component import can be wrapped in a <code>React.lazy()</code>, which delays the component from loading until it is called.<br> While it is loading, the nearest parent <code>React.Suspense</code> component will be rendered in it's place (ex. loading-bar, spinner). <syntaxhighlight lang="javascript"> const MyComponent = React.lazy(() => import('./MyComponent')); function RootComponent() { return ( <React.Suspense fallbac...") |
No edit summary |
||
Line 1: | Line 1: | ||
Lazy component imports let you postpone an import,<br> | |||
and render a 'suspense' component in it's place until it has loaded. | |||
= Documentation = | |||
<blockquote> | |||
{| class="wikitable" | |||
|- | |||
| | |||
|- | |||
|} | |||
</blockquote><!-- Documentation --> | |||
= Lazy Component Imports = | = Lazy Component Imports = |
Revision as of 01:35, 11 December 2022
Lazy component imports let you postpone an import,
and render a 'suspense' component in it's place until it has loaded.
Documentation
Lazy Component Imports
A component import can be wrapped in a
React.lazy()
, which delays the component from loading until it is called.
While it is loading, the nearest parentReact.Suspense
component will be rendered in it's place (ex. loading-bar, spinner).const MyComponent = React.lazy(() => import('./MyComponent')); function RootComponent() { return ( <React.Suspense fallback={<Spinner />}> <div> <MyComponent /> </div> </React.Suspense> ) }