MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / LazyComponent

Function LazyComponent

apps/start/src/components/lazy-component.tsx:47–79  ·  view source on GitHub ↗
({
  lazy = true,
  children,
  fallback = null,
  className,
  viewportOptions,
  disconnectOnLeave = true,
}: LazyComponentProps)

Source from the content-addressed store, hash-verified

45 * Uses intersection observer under the hood for efficient viewport detection.
46 */
47export const LazyComponent = ({
48 lazy = true,
49 children,
50 fallback = null,
51 className,
52 viewportOptions,
53 disconnectOnLeave = true,
54}: LazyComponentProps) => {
55 const ref = useRef<HTMLDivElement>(null);
56 const once = useRef(false);
57
58 const { inViewport } = useInViewport(
59 ref as RefObject<HTMLElement>,
60 viewportOptions,
61 {
62 disconnectOnLeave,
63 },
64 );
65
66 useEffect(() => {
67 if (inViewport) {
68 once.current = true;
69 }
70 }, [inViewport]);
71
72 const shouldRender = lazy ? once.current || inViewport : true;
73
74 return (
75 <div ref={ref} className={className}>
76 {shouldRender ? children : (fallback ?? <div />)}
77 </div>
78 );
79};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected