We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6888a17 commit dffd0dfCopy full SHA for dffd0df
src/hooks/useRect.ts
@@ -3,10 +3,19 @@ import React from 'react'
3
export default function useRect(
4
element: Element | null | undefined,
5
enabled: boolean
6
-) {
+): DOMRect {
7
const rerender = React.useReducer(() => ({}), [])[1]
8
9
- const rectRef = React.useRef<DOMRect>()
+ const rectRef = React.useRef<DOMRect>({
10
+ width: 0,
11
+ height: 0,
12
+ x: 0,
13
+ y: 0,
14
+ left: 0,
15
+ top: 0,
16
+ right: 0,
17
+ bottom: 0,
18
+ } as DOMRect)
19
20
const measure = React.useCallback(() => {
21
if (element) {
@@ -43,7 +52,7 @@ export default function useRect(
43
52
measure()
44
53
rerender()
45
54
46
- const observer = new ResizeObserver(entries => {
55
+ const observer = new ResizeObserver(() => {
47
56
48
57
49
58
})
0 commit comments