This commit is contained in:
Alejandro Gomez 2023-02-12 22:26:43 +01:00 committed by Kieran
parent cca7c24770
commit 728472d7bc
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
2 changed files with 21 additions and 1 deletions

View File

@ -8,7 +8,7 @@ import Avatar from "Element/Avatar";
import Nip05 from "Element/Nip05";
import { HexKey } from "@snort/nostr";
import { MetadataCache } from "State/Users";
import useClientWidth from "Hooks/useClientWidth";
import usePageWidth from "Hooks/usePageWidth";
export interface ProfileImageProps {
pubkey: HexKey;

View File

@ -0,0 +1,20 @@
import { useRef, useState, useEffect } from "react";
export default function usePageWidth() {
const ref = useRef<HTMLDivElement | null>(document.querySelector(".page"));
const [width, setWidth] = useState(0);
useEffect(() => {
const updateSize = () => {
if (ref.current) {
setWidth(ref.current.offsetWidth);
}
};
window.addEventListener("resize", updateSize);
updateSize();
return () => window.removeEventListener("resize", updateSize);
}, [ref]);
return width;
}