# extendify/3.0.6/src/Agent/hooks/useIframeScale.js

Extendify, version 3.0.6. 27 lines.

- Page: https://pluginprobe.com/plugins/extendify/3.0.6/code/src/Agent/hooks/useIframeScale.js
- Raw: https://pluginprobe.com/plugins/extendify/3.0.6/raw/src/Agent/hooks/useIframeScale.js
- Modified: 2026-05-19T15:40:58+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/extendify/3.0.6/code/src/Agent/hooks/useIframeScale.js#L10-L20`.

```javascript
import { useLayoutEffect, useRef, useState } from '@wordpress/element';

export const useIframeScale = ({ viewportWidth }) => {
	const containerRef = useRef(null);
	const [scale, setScale] = useState(1);
	const [contentHeight, setContentHeight] = useState(null);

	useLayoutEffect(() => {
		const el = containerRef.current;
		if (!el) return;
		const obs = new ResizeObserver(([entry]) => {
			setScale(entry.contentRect.width / viewportWidth);
		});
		obs.observe(el);
		return () => obs.disconnect();
	}, []);

	const handleIframeLoad = (e) => {
		const iframeDoc = e.target.contentDocument;
		if (!iframeDoc?.body) return;
		const height = iframeDoc.body.scrollHeight;
		if (height) setContentHeight(height);
	};

	return { containerRef, scale, contentHeight, handleIframeLoad };
};

```
