import React, { useMemo, useRef } from 'react';
import { Loading, LoadingProps } from './Loading';
interface LoadingOnFirstProps extends LoadingProps {
spinning: boolean;
className?: string;
style?: React.CSSProperties;
}
/**
* 类似于 但是只会触发一次
*/
export const LoadingOnFirst: React.FC = React.memo(
(props) => {
const lockRef = useRef(false);
const spinning = useMemo(() => {
if (lockRef.current === true) {
return false;
}
if (props.spinning === true) {
lockRef.current = true;
}
return props.spinning;
}, [props.spinning]);
return (
{props.children}
);
}
);
LoadingOnFirst.displayName = 'LoadingOnFirst';