(feat:transitions) custom hook to loading state

This commit is contained in:
ManishMadan2882
2025-02-13 17:16:17 +05:30
parent d08861fb30
commit 181bf69994
5 changed files with 108 additions and 147 deletions

View File

@@ -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];
}