ant-design/.dumi/theme/slots/Content/InViewSuspense.tsx
lijianan ddf70283ed
site: update site type { children: React.ReactNode } => React.PropsWithChildren (#48770)
* site: update site type React.ReactNode => React.PropsWithChildren

* fix: fix

* fix: fix
2024-05-06 15:28:52 +08:00

25 lines
717 B
TypeScript

import React, { Suspense } from 'react';
import { Skeleton } from 'antd';
import { InView } from 'react-intersection-observer';
import type { IntersectionObserverProps } from 'react-intersection-observer';
type InViewSuspenseProps = Pick<IntersectionObserverProps, 'delay'> & {
fallback?: React.ReactNode;
};
const InViewSuspense: React.FC<React.PropsWithChildren<InViewSuspenseProps>> = ({
children,
fallback = <Skeleton.Input active size="small" />,
delay = 200,
}) => (
<InView triggerOnce delay={delay}>
{({ inView, ref }) => (
<div ref={ref}>
<Suspense fallback={fallback}>{inView ? children : <span />}</Suspense>
</div>
)}
</InView>
);
export default InViewSuspense;