1+ import { lazy , Suspense } from 'react'
2+
13import { useEffect , useState } from 'react'
24import { Link } from '../types/api'
35import { getAllLinks , deleteLink } from '../api/client'
@@ -22,7 +24,7 @@ import {
2224 DialogFooter ,
2325} from "@/components/ui/dialog"
2426
25- import { StatisticsModal } from " ./StatisticsModal"
27+ const StatisticsModal = lazy ( ( ) => import ( ' ./StatisticsModal' ) )
2628
2729interface LinkListProps {
2830 refresh ?: number ;
@@ -85,13 +87,13 @@ export function LinkList({ refresh = 0 }: LinkListProps) {
8587 const baseUrl = window . location . origin
8688 navigator . clipboard . writeText ( `${ baseUrl } /${ shortCode } ` )
8789 toast ( {
88- description : (
89- < >
90- Link copied to clipboard
91- < br />
92- You can add ?source=TextHere to the end of the link to track the source of clicks
93- </ >
94- ) ,
90+ description : (
91+ < >
92+ Link copied to clipboard
93+ < br />
94+ You can add ?source=TextHere to the end of the link to track the source of clicks
95+ </ >
96+ ) ,
9597 } )
9698 }
9799
@@ -186,11 +188,15 @@ export function LinkList({ refresh = 0 }: LinkListProps) {
186188 </ div >
187189 </ CardContent >
188190 </ Card >
189- < StatisticsModal
190- isOpen = { statsModal . isOpen }
191- onClose = { ( ) => setStatsModal ( { isOpen : false , linkId : null } ) }
192- linkId = { statsModal . linkId ! }
193- />
191+ { statsModal . isOpen && (
192+ < Suspense fallback = { < div > Loading...</ div > } >
193+ < StatisticsModal
194+ isOpen = { statsModal . isOpen }
195+ onClose = { ( ) => setStatsModal ( { isOpen : false , linkId : null } ) }
196+ linkId = { statsModal . linkId ! }
197+ />
198+ </ Suspense >
199+ ) }
194200 </ >
195201 )
196202}
0 commit comments