Skip to content

Commit 6d4e258

Browse files
authored
Merge pull request #15618 from ethereum/warning-patch
fix: react-hooks/exhaustive-deps
2 parents d89a219 + 91ea4ae commit 6d4e258

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/hooks/useRefWidth.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client"
22

3-
import { type RefObject, useEffect, useState } from "react"
3+
import { type RefObject, useCallback, useEffect, useState } from "react"
44

55
import { useEventListener } from "./useEventListener"
66

@@ -10,12 +10,12 @@ export const useRefWidth = (
1010
): number => {
1111
const [width, setWidth] = useState(0)
1212

13-
const updateWidth = () => {
13+
const updateWidth = useCallback(() => {
1414
if (ref.current) {
1515
const rect = ref.current.getBoundingClientRect()
1616
setWidth(Math.max(0, rect.width - padding))
1717
}
18-
}
18+
}, [ref, padding])
1919

2020
// Use the internal useEventListener for window resize
2121
useEventListener("resize", updateWidth)
@@ -33,7 +33,7 @@ export const useRefWidth = (
3333
return () => {
3434
resizeObserver.disconnect()
3535
}
36-
}, [ref, padding])
36+
}, [ref, padding, updateWidth])
3737

3838
return width
3939
}

0 commit comments

Comments
 (0)