Skip to content

Commit

Permalink
fix: clean up dependency arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
tomzemp committed Aug 15, 2023
1 parent 6c705ec commit c9e9b8f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions shell/src/PluginLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,27 @@ const PluginInner = ({
})
resizeObserver.observe(divRef.current)
}
}, [])
}, [resizePluginHeight, resizePluginWidth])

let previousWidth
const previousWidth = useRef()

const resetWidth = () => {
const resetWidth = useCallback(() => {
const currentWidth = innerDivRef.current?.scrollWidth
if (resizePluginWidth && currentWidth) {
if (previousWidth && Math.abs(currentWidth - previousWidth) > 20) {
if (
previousWidth.current &&
Math.abs(currentWidth - previousWidth.current) > 20
) {
resizePluginWidth(currentWidth + 20)
}
previousWidth = currentWidth
previousWidth.current = currentWidth
}
requestAnimationFrame(resetWidth)
}
}, [resizePluginWidth])

useEffect(() => {
requestAnimationFrame(resetWidth)
}, [])
}, [resetWidth])

// inner div disables margin collapsing which would prevent computing correct height
return (
Expand Down

0 comments on commit c9e9b8f

Please sign in to comment.