From 6b12f0a270e3e452887f912e65fd54931bace616 Mon Sep 17 00:00:00 2001 From: exuanbo Date: Tue, 19 Dec 2023 18:50:02 +0000 Subject: [PATCH] refactor(common/ResizablePanel): combine functions --- src/common/components/ResizablePanel.tsx | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/common/components/ResizablePanel.tsx b/src/common/components/ResizablePanel.tsx index 1f73abb0..d4463047 100644 --- a/src/common/components/ResizablePanel.tsx +++ b/src/common/components/ResizablePanel.tsx @@ -39,7 +39,10 @@ const ResizablePanel: FC = ({ [], ) - const getInitialLeftChildWidth = useCallback(() => getTotalWidth() / 2, [getTotalWidth]) + const resetLeftChildWidth = useCallback( + () => setLeftChildWidth(getTotalWidth() / 2), + [getTotalWidth], + ) const getAvailableWidth = useCallback( () => getTotalWidth() - getOffsetWidth(rightChildRef), @@ -56,9 +59,9 @@ const ResizablePanel: FC = ({ useLayoutEffect(() => { if (!isReady) { - setLeftChildWidth(getInitialLeftChildWidth()) + resetLeftChildWidth() } - }, [getInitialLeftChildWidth, isReady]) + }, [isReady, resetLeftChildWidth]) useLayoutEffect(() => { if (leftChildWidth !== undefined) { @@ -79,7 +82,7 @@ const ResizablePanel: FC = ({ clickCountRef.current += 1 if (clickCountRef.current === 2) { - setLeftChildWidth(getInitialLeftChildWidth()) + resetLeftChildWidth() window.clearTimeout(clickTimeoutIdRef.current) clickCountRef.current = 0 } else {