mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-18 19:39:51 +08:00
398f924740
* docs: load some components in viewport * chore: fix lint errors * chore: fix fallback
26 lines
722 B
TypeScript
26 lines
722 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;
|
|
children?: React.ReactNode;
|
|
};
|
|
|
|
const InViewSuspense: React.FC<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;
|