Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply best practices for creating programmatic videos with Remotion and React
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/measuring-dom-nodes.md
1---2name: measuring-dom-nodes3description: Measuring DOM element dimensions in Remotion4metadata:5tags: measure, layout, dimensions, getBoundingClientRect, scale6---78# Measuring DOM nodes in Remotion910Remotion applies a `scale()` transform to the video container, which affects values from `getBoundingClientRect()`. Use `useCurrentScale()` to get correct measurements.1112## Measuring element dimensions1314```tsx15import { useCurrentScale } from "remotion";16import { useRef, useEffect, useState } from "react";1718export const MyComponent = () => {19const ref = useRef<HTMLDivElement>(null);20const scale = useCurrentScale();21const [dimensions, setDimensions] = useState({ width: 0, height: 0 });2223useEffect(() => {24if (!ref.current) return;25const rect = ref.current.getBoundingClientRect();26setDimensions({27width: rect.width / scale,28height: rect.height / scale,29});30}, [scale]);3132return <div ref={ref}>Content to measure</div>;33};34```35