forked from Github/frigate
test(web): CameraImage (basic)
Testing Image and Canvas calls requires a lot of heavy dependencies, so this skips that part of the tests
This commit is contained in:
committed by
Blake Blackshear
parent
a202c44a0f
commit
1aa9a7a093
30
web/src/hooks/index.jsx
Normal file
30
web/src/hooks/index.jsx
Normal file
@@ -0,0 +1,30 @@
|
||||
import { useEffect, useMemo, useState } from 'preact/hooks';
|
||||
|
||||
export function useResizeObserver(...refs) {
|
||||
const [dimensions, setDimensions] = useState(
|
||||
new Array(refs.length).fill({ width: 0, height: 0, x: -Infinity, y: -Infinity })
|
||||
);
|
||||
const resizeObserver = useMemo(
|
||||
() =>
|
||||
new ResizeObserver((entries) => {
|
||||
window.requestAnimationFrame(() => {
|
||||
setDimensions(entries.map((entry) => entry.contentRect));
|
||||
});
|
||||
}),
|
||||
[]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
refs.forEach((ref) => {
|
||||
resizeObserver.observe(ref.current);
|
||||
});
|
||||
|
||||
return () => {
|
||||
refs.forEach((ref) => {
|
||||
resizeObserver.unobserve(ref.current);
|
||||
});
|
||||
};
|
||||
}, [refs, resizeObserver]);
|
||||
|
||||
return dimensions;
|
||||
}
|
||||
Reference in New Issue
Block a user