Files
FastGPT/packages/web/hooks/useLoading.tsx
Archer 4d66e0f828 4.6.9-production (#952)
* move components to web package (#37)

* move components

* fix

* fix: cq connection

* fix pagination (#41)

* doc

* openapi config

* fix team share app lose (#42)

* fix: ts

* doc

* doc

---------

Co-authored-by: heheer <71265218+newfish-cmyk@users.noreply.github.com>
Co-authored-by: yst <77910600+yu-and-liu@users.noreply.github.com>
2024-03-08 13:33:45 +08:00

32 lines
713 B
TypeScript

import { useState, useCallback } from 'react';
import LoadingComponent from '../components/common/MyLoading';
export const useLoading = (props?: { defaultLoading: boolean }) => {
const [isLoading, setIsLoading] = useState(props?.defaultLoading || false);
const Loading = useCallback(
({
loading,
fixed = true,
text = '',
zIndex
}: {
loading?: boolean;
fixed?: boolean;
text?: string;
zIndex?: number;
}): JSX.Element | null => {
return isLoading || loading ? (
<LoadingComponent fixed={fixed} text={text} zIndex={zIndex} />
) : null;
},
[isLoading]
);
return {
isLoading,
setIsLoading,
Loading
};
};