From 712c56cbb83e8cb43f70959843cc437742697190 Mon Sep 17 00:00:00 2001 From: EnixCoda Date: Sun, 15 Mar 2020 02:20:01 +0800 Subject: [PATCH] fix: memorize callback to reduce event registrations --- src/components/Resizable.tsx | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/components/Resizable.tsx b/src/components/Resizable.tsx index 3be0296..cb274c1 100644 --- a/src/components/Resizable.tsx +++ b/src/components/Resizable.tsx @@ -49,17 +49,13 @@ export function Resizable({ baseSize, className, children }: React.PropsWithChil size, ) + const onResize = React.useCallback((size: number) => { + if (size < window.innerWidth - MINIMAL_CONTENT_VIEWPORT_WIDTH) setSize(size) + }, []) return (
{children}
- {features.resize && ( - { - if (size < window.innerWidth - MINIMAL_CONTENT_VIEWPORT_WIDTH) setSize(size) - }} - size={size} - /> - )} + {features.resize && }
) }