mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-04-24 03:00:09 -04:00
24 lines
656 B
TypeScript
24 lines
656 B
TypeScript
import { LoadingState } from '@metafam/ds';
|
|
import React, { Suspense, useRef } from 'react';
|
|
|
|
import useFirstViewportEntry from '#lib/hooks/useFirstViewportEntry';
|
|
|
|
const RenderOnViewportEntry: React.FC<any> = ({
|
|
children,
|
|
threshold = 0,
|
|
root = null,
|
|
rootMargin = '0px 0px 0px 0px',
|
|
...wrapperDivProps
|
|
}) => {
|
|
const ref = useRef<HTMLDivElement>();
|
|
const entered = useFirstViewportEntry(ref, { threshold, root, rootMargin });
|
|
|
|
return (
|
|
<div {...wrapperDivProps} ref={ref} style={{ width: '100%' }}>
|
|
{entered && <Suspense fallback={<LoadingState />}>4{children}</Suspense>}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default RenderOnViewportEntry;
|