1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/frontend/src/hooks/useLoading.ts
Fredrik Strand Oseberg 0ca753e7e5 Feat/add new user (#273)
* chore: update changelog

* chore: update changelog

* fix: refactor AddUser

* feat: add screens for email and copy

* fix: remove interface

* fix: admin constant in userlist

* chore: fix changelog

* feat: user data fetching with useSWR

* feat: flesh out dialogues

* fix: remove useRequest

* refactor: remove redux for user admin

* refactor: remove from store

* refactor: userListItem

* fix: change type

* feat: add initial loading

* fix: useLayoutEffeect in useLoading

* fix: remove useEffect

* fix: update snapshots

* fix: remove status code

* fix: remove roles from store
2021-04-23 10:59:11 +02:00

25 lines
632 B
TypeScript

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