fix: memorize callback to reduce event registrations

This commit is contained in:
EnixCoda 2020-03-15 02:20:01 +08:00
parent 58a63bc77b
commit 712c56cbb8
No known key found for this signature in database
GPG key ID: 0C1A07377913A1DD

View file

@ -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 (
<div className={cx('gitako-position-wrapper', className)}>
<div className={'gitako-position-content'}>{children}</div>
{features.resize && (
<HorizontalResizeHandler
onResize={size => {
if (size < window.innerWidth - MINIMAL_CONTENT_VIEWPORT_WIDTH) setSize(size)
}}
size={size}
/>
)}
{features.resize && <HorizontalResizeHandler onResize={onResize} size={size} />}
</div>
)
}