🎥 Make videos programmatically with React
fix ssr
Jonny Burger40f0d86aec92
diff --git a/packages/docs/src/helpers/use-el-size.ts b/packages/docs/src/helpers/use-el-size.tsindex 198fd413f8..af2243eee3 100644--- a/packages/docs/src/helpers/use-el-size.ts+++ b/packages/docs/src/helpers/use-el-size.ts@@ -5,19 +5,25 @@ export type Size = {height: number;};-export const useElementSize = (ref: HTMLElement): Size | null => {+export const useElementSize = (ref: HTMLElement | null): Size | null => {const [size, setSize] = useState<Size | null>(null);- const observer = useMemo(- () =>- new ResizeObserver((entries) => {- setSize({- width: entries[0].contentRect.width,- height: entries[0].contentRect.height,- });- }),- []- );+ const observer = useMemo(() => {+ if (typeof ResizeObserver === "undefined") {+ return;+ }++ return new ResizeObserver((entries) => {+ setSize({+ width: entries[0].contentRect.width,+ height: entries[0].contentRect.height,+ });+ });+ }, []);const updateSize = useCallback(() => {+ if (ref === null) {+ return;+ }+const rect = ref.getClientRects();setSize({width: rect[0].width as number,@@ -27,9 +33,14 @@ export const useElementSize = (ref: HTMLElement): Size | null => {useEffect(() => {updateSize();+ if (!observer) {+ return;+ }+if (ref) {observer.observe(ref);}+return (): void => {if (ref) {observer.unobserve(ref);diff --git a/packages/docs/src/pages/showcase/index.tsx b/packages/docs/src/pages/showcase/index.tsxindex c0ad9b1cc3..8e8405c01b 100644--- a/packages/docs/src/pages/showcase/index.tsx+++ b/packages/docs/src/pages/showcase/index.tsx@@ -28,10 +28,16 @@ const flex1: React.CSSProperties = {};const Showcase = () => {- const containerSize = useElementSize(document.body);+ const containerSize = useElementSize(+ typeof document === "undefined" ? null : document.body+ );const mobileLayout = (containerSize?.width ?? Infinity) < 1200;const [video, setVideo] = useState<ShowcaseVideo | null>(() => {+ if (typeof window === "undefined") {+ return null;+ }+if (!window.location.hash) {return null;}