mirror of
https://github.com/labring/FastGPT.git
synced 2025-12-30 00:32:50 +00:00
20 lines
549 B
TypeScript
20 lines
549 B
TypeScript
import { useState, useCallback } from 'react';
|
|
import LoadingComponent from '@/components/Loading';
|
|
|
|
export const useLoading = (props?: { defaultLoading: boolean }) => {
|
|
const [isLoading, setIsLoading] = useState(props?.defaultLoading || false);
|
|
|
|
const Loading = useCallback(
|
|
({ loading, fixed = true }: { loading?: boolean; fixed?: boolean }): JSX.Element | null => {
|
|
return isLoading || loading ? <LoadingComponent fixed={fixed} /> : null;
|
|
},
|
|
[isLoading]
|
|
);
|
|
|
|
return {
|
|
isLoading,
|
|
setIsLoading,
|
|
Loading
|
|
};
|
|
};
|