File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -66,10 +66,25 @@ export default function GraphView({
6666 const [ parentHeight , setParentHeight ] = useState ( 0 )
6767
6868 useEffect ( ( ) => {
69- if ( ! parentRef . current ) return
70- setParentWidth ( parentRef . current . clientWidth )
71- setParentHeight ( parentRef . current . clientHeight )
72- } , [ parentRef . current ?. clientWidth , parentRef . current ?. clientHeight ] )
69+ const handleResize = ( ) => {
70+ if ( ! parentRef . current ) return
71+ setParentWidth ( parentRef . current . clientWidth )
72+ setParentHeight ( parentRef . current . clientHeight )
73+ }
74+
75+ window . addEventListener ( 'resize' , handleResize )
76+
77+ const observer = new ResizeObserver ( handleResize )
78+
79+ if ( parentRef . current ) {
80+ observer . observe ( parentRef . current )
81+ }
82+
83+ return ( ) => {
84+ window . removeEventListener ( 'resize' , handleResize )
85+ observer . disconnect ( )
86+ }
87+ } , [ parentRef ] )
7388
7489 useEffect ( ( ) => {
7590 setCooldownTime ( 4000 )
You can’t perform that action at this time.
0 commit comments