Kopie van https://gitlab.com/studieverenigingvia/ict/centurion met een paar aanpassingen
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
781 B
34 lines
781 B
import { useEffect, useState } from "react";
|
|
|
|
export function useUpdateAfterDelay(delay: number) {
|
|
const [, timedUpdateSet] = useState(0);
|
|
useEffect(() => {
|
|
const timeoutId = setTimeout(() => {
|
|
timedUpdateSet((v) => v + 1);
|
|
}, delay);
|
|
return () => clearTimeout(timeoutId);
|
|
});
|
|
}
|
|
|
|
export function useResize() {
|
|
const [dimensions, setDimensions] = useState({
|
|
height: window.innerHeight,
|
|
width: window.innerWidth,
|
|
});
|
|
|
|
useEffect(() => {
|
|
const listener = (ev: UIEvent) => {
|
|
setDimensions({
|
|
height: window.innerHeight,
|
|
width: window.innerWidth,
|
|
});
|
|
};
|
|
window.addEventListener("resize", listener);
|
|
|
|
return () => {
|
|
window.removeEventListener("resize", listener);
|
|
};
|
|
});
|
|
|
|
return dimensions;
|
|
}
|
|
|