Skip to content

Commit

Permalink
fix: use useRef for previous width
Browse files Browse the repository at this point in the history
  • Loading branch information
tomzemp committed Aug 22, 2023
1 parent 9863ae0 commit f6c07cf
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions shell/src/PluginLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ const PluginInner = ({
}
}, [resizePluginHeight])

let previousWidth
const previousWidth = useRef()

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])
Expand Down

0 comments on commit f6c07cf

Please sign in to comment.