Files
Momento/memento-note/hooks/use-resize-observer.ts
Sepehr Ramezani e4d4e23dc7 chore: clean up repo for public release
- Remove BMAD framework, IDE configs, dev screenshots, test files,
  internal docs, and backup files
- Rename keep-notes/ to memento-note/
- Update all references from keep-notes to memento-note
- Add Apache 2.0 license with Commons Clause (non-commercial restriction)
- Add clean .gitignore and .env.docker.example
2026-04-20 22:48:06 +02:00

34 lines
824 B
TypeScript

'use client';
import { useEffect, useRef } from 'react';
export function useResizeObserver(callback: (entry: ResizeObserverEntry) => void) {
const ref = useRef<HTMLElement>(null);
const frameId = useRef<number>(0);
useEffect(() => {
const element = ref.current;
if (!element) return;
const observer = new ResizeObserver((entries) => {
// Cancel previous frame to avoid stacking updates
if (frameId.current) cancelAnimationFrame(frameId.current);
frameId.current = requestAnimationFrame(() => {
for (const entry of entries) {
callback(entry);
}
});
});
observer.observe(element);
return () => {
observer.disconnect();
if (frameId.current) cancelAnimationFrame(frameId.current);
};
}, [callback]);
return ref;
}