mirror of https://github.com/msgbyte/tailchat
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
813 B
TypeScript
35 lines
813 B
TypeScript
import React, { useMemo, useRef } from 'react';
|
|
import { Loading, LoadingProps } from './Loading';
|
|
|
|
interface LoadingOnFirstProps extends LoadingProps {
|
|
spinning: boolean;
|
|
className?: string;
|
|
style?: React.CSSProperties;
|
|
}
|
|
/**
|
|
* 类似于 <Loading /> 但是只会触发一次
|
|
*/
|
|
export const LoadingOnFirst: React.FC<LoadingOnFirstProps> = 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 (
|
|
<Loading {...props} spinning={spinning}>
|
|
{props.children}
|
|
</Loading>
|
|
);
|
|
}
|
|
);
|
|
LoadingOnFirst.displayName = 'LoadingOnFirst';
|