Skip to content

Commit

Permalink
fix: useRect TS errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Aug 4, 2022
1 parent 6888a17 commit dffd0df
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/hooks/useRect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@ import React from 'react'
export default function useRect(
element: Element | null | undefined,
enabled: boolean
) {
): DOMRect {
const rerender = React.useReducer(() => ({}), [])[1]

const rectRef = React.useRef<DOMRect>()
const rectRef = React.useRef<DOMRect>({
width: 0,
height: 0,
x: 0,
y: 0,
left: 0,
top: 0,
right: 0,
bottom: 0,
} as DOMRect)

const measure = React.useCallback(() => {
if (element) {
Expand Down Expand Up @@ -43,7 +52,7 @@ export default function useRect(
measure()
rerender()

const observer = new ResizeObserver(entries => {
const observer = new ResizeObserver(() => {
measure()
rerender()
})
Expand Down

0 comments on commit dffd0df

Please sign in to comment.