mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-30 00:53:14 +00:00
(feat:transitions) custom hook to loading state
This commit is contained in:
@@ -112,3 +112,23 @@ export function useDarkTheme() {
|
||||
|
||||
return [isDarkTheme, toggleTheme, componentMounted] as const;
|
||||
}
|
||||
|
||||
export function useLoaderState(
|
||||
initialState = false,
|
||||
delay = 500,
|
||||
): [boolean, (value: boolean) => void] {
|
||||
const [state, setState] = useState<boolean>(initialState);
|
||||
|
||||
const setLoaderState = (value: boolean) => {
|
||||
if (value) {
|
||||
setState(true);
|
||||
} else {
|
||||
// Only add delay when changing from true to false
|
||||
setTimeout(() => {
|
||||
setState(false);
|
||||
}, delay);
|
||||
}
|
||||
};
|
||||
|
||||
return [state, setLoaderState];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user