1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-01 00:08:27 +01:00
unleash.unleash/frontend/src/hooks/useLoading.ts
Jaanus Sellin bb5b322475
fix: now project overview has skeleton instead of placeholders (#5696)
Removed `ref` dependency from `useLoading` hook, it was being overly
reactive and breaking skeleton.
2023-12-20 14:59:41 +02:00

25 lines
677 B
TypeScript

import { createRef, useLayoutEffect } from 'react';
type refElement = HTMLDivElement;
const useLoading = (loading: boolean, selector = '[data-loading=true]') => {
const ref = createRef<refElement>();
useLayoutEffect(() => {
if (ref.current) {
const elements = ref.current.querySelectorAll(selector);
elements.forEach((element) => {
if (loading) {
element.classList.add('skeleton');
} else {
setTimeout(() => element.classList.remove('skeleton'), 10);
}
});
}
}, [loading]);
return ref;
};
export default useLoading;