File tree Expand file tree Collapse file tree 2 files changed +26
-24
lines changed Expand file tree Collapse file tree 2 files changed +26
-24
lines changed Original file line number Diff line number Diff line change @@ -7,30 +7,7 @@ import {
77 useParsedPvConnection ,
88} from "../pv/util" ;
99import 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)
Original file line number Diff line number Diff line change 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+ } ;
You can’t perform that action at this time.
0 commit comments