mirror of
https://github.com/aljazceru/landscape-template.git
synced 2026-01-16 21:04:22 +01:00
chore: refactor modals structure to support lazy loading when needed
This commit is contained in:
27
src/pages/ProjectPage/ProjectDetailsCard/index.tsx
Normal file
27
src/pages/ProjectPage/ProjectDetailsCard/index.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import React, { ComponentProps, ComponentType, Suspense } from 'react'
|
||||
import ProjectDetailsCardSkeleton from './ProjectDetailsCard.Skeleton'
|
||||
|
||||
|
||||
|
||||
function lazyFactory(Factory: () => Promise<{ default: ComponentType<any>; }>) {
|
||||
const C = React.lazy(Factory)
|
||||
const preload = Factory;
|
||||
const LazyComponent = ({ direction, ...props }: ComponentProps<typeof C>) => <Suspense
|
||||
fallback={
|
||||
// <ProjectDetailsCardSkeleton direction={direction} {...props} />
|
||||
<h2>Loading Modal</h2>
|
||||
}>
|
||||
<C {...props} />
|
||||
</Suspense>
|
||||
|
||||
return { LazyComponent, preload };
|
||||
}
|
||||
|
||||
export const {
|
||||
LazyComponent: ProjectDetailsCard,
|
||||
preload: projectDetailsCardPreload
|
||||
} = lazyFactory(() => import('./ProjectDetailsCard'))
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user