lazy in react code example
Example 1: suspense react
import React, {Suspense} from 'react;
const ProfilePage = React.lazy(() => import('./ProfilePage'));
<Suspense fallback={<Spinner />}>
<ProfilePage />
</Suspense>
Example 2: lazy react
import React, { Suspense } from 'react';
const OtherComponent = React.lazy(() => import('./OtherComponent'));
function MyComponent() {
return (
<div>
<Suspense fallback={<div>Loading...</div>}>
<OtherComponent />
</Suspense>
</div>
);
}
Example 3: lazy react
import("./math").then(math => {
console.log(math.add(16, 26));
});