Skip to content

Commit 91ea4ae

Browse files
committed
fix: react-hooks/exhaustive-deps
Fixes: `React Hook useEffect has a missing dependency: 'updateWidth'. Either include it or remove the dependency array. react-hooks/exhaustive-deps`
1 parent 42b83a9 commit 91ea4ae

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)