Skip to content
Snippets Groups Projects
Commit 67b3c382 authored by duncan's avatar duncan
Browse files

fix(resize): recalculates after window resize

parent e818ddc6
No related branches found
Tags v1.14.0
2 merge requests!135geo intergation,!129Feat/visManager
import React, { useEffect, useRef } from 'react';
import React, { useEffect, useRef, useState } from 'react';
type Props = {
children: React.ReactNode;
......@@ -31,6 +31,19 @@ export const Resizable = ({
const [firstSize, setFirstSize] = React.useState<number>(0);
const [secondSize, setSecondSize] = React.useState<number>(0);
const [dragging, setDragging] = React.useState<boolean>(false);
const [windowSize, setWindowSize] = useState({ width: window.innerWidth, height: window.innerHeight });
useEffect(() => {
const handleResize = () => {
setWindowSize({ width: window.innerWidth, height: window.innerHeight });
};
window.addEventListener('resize', handleResize);
return () => {
window.removeEventListener('resize', handleResize);
};
}, []);
useEffect(() => {
if (ref.current) {
......@@ -44,7 +57,7 @@ export const Resizable = ({
setSecondSize(rect.height * (1 / _defaultProportion) - divisorSize);
}
}
}, [ref.current]);
}, [ref.current, windowSize]);
function onMouseDown(e: React.MouseEvent<HTMLDivElement, MouseEvent>) {
setDragging(true);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment