Skip to content

Commit 072eaee

Browse files
authored
Merge pull request #80 from DiamondLightSource/79-Separate_exports
79 separate exports
2 parents 7299061 + 6c75526 commit 072eaee

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

src/components/OavVideoStream.tsx

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,7 @@ import {
77
useParsedPvConnection,
88
} from "../pv/util";
99
import React from "react";
10-
11-
export const useContainerDimensions = (
12-
ref: React.MutableRefObject<HTMLHeadingElement | null>,
13-
) => {
14-
const [dimensions, setDimensions] = React.useState({ width: 0, height: 0 });
15-
React.useEffect(() => {
16-
const getDimensions = () => ({
17-
width: ref.current?.offsetWidth || 0,
18-
height: ref.current?.offsetWidth || 0,
19-
});
20-
const handleResize = () => {
21-
setDimensions(getDimensions());
22-
};
23-
if (ref.current) {
24-
setDimensions(getDimensions());
25-
}
26-
window.addEventListener("resize", handleResize);
27-
return () => {
28-
window.removeEventListener("resize", handleResize);
29-
};
30-
}, [ref]);
31-
32-
return dimensions;
33-
};
10+
import { useContainerDimensions } from "./OavVideoStreamHelper";
3411

3512
/*
3613
* A viewer which allows overlaying a crosshair (takes numbers which could be the values from a react useState hook)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { useState, useEffect } from "react";
2+
3+
export const useContainerDimensions = (
4+
ref: React.MutableRefObject<HTMLHeadingElement | null>,
5+
) => {
6+
const [dimensions, setDimensions] = useState({ width: 0, height: 0 });
7+
useEffect(() => {
8+
const getDimensions = () => ({
9+
width: ref.current?.offsetWidth || 0,
10+
height: ref.current?.offsetWidth || 0,
11+
});
12+
const handleResize = () => {
13+
setDimensions(getDimensions());
14+
};
15+
if (ref.current) {
16+
setDimensions(getDimensions());
17+
}
18+
window.addEventListener("resize", handleResize);
19+
return () => {
20+
window.removeEventListener("resize", handleResize);
21+
};
22+
}, [ref]);
23+
24+
return dimensions;
25+
};

0 commit comments

Comments
 (0)