Skip to content

Commit

Permalink
Check if ResizeObserver is defined instead of checking window object
Browse files Browse the repository at this point in the history
  • Loading branch information
andriuss authored and plouc committed Feb 26, 2023
1 parent 1d8dcf4 commit 0cdfedf
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/core/src/hooks/useMeasure.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ export const useMeasure = () => {
})

const [observer] = useState(() => {
// Check if window is defined (so if in the browser or in node.js).
const isBrowser = typeof window !== 'undefined'
if (!isBrowser) return null

// Check if ResizeObserver is defined in current env (could be browser, node.js, jsdom etc.).
if (typeof ResizeObserver === 'undefined') return null

return new ResizeObserver(([entry]) => setBounds(entry.contentRect))
})

Expand Down

0 comments on commit 0cdfedf

Please sign in to comment.