-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Remove useResizeObserver hack (#2981)
We're past TypeScript 4.2, so we're removing the `useResizeObserver` hacks. [category:Components]
- Loading branch information
1 parent
9f6eea6
commit 487e829
Showing
5 changed files
with
7 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,3 @@ | ||
import React from 'react'; | ||
import useResizeObserver from 'use-resize-observer'; | ||
|
||
import useResizeObserverOriginal from 'use-resize-observer'; | ||
import ResizeObserver from 'resize-observer-polyfill'; | ||
|
||
if (typeof window !== 'undefined' && !(window as any).ResizeObserver) { | ||
(window as any).ResizeObserver = ResizeObserver; | ||
} | ||
|
||
// `useResizeObserver` contains this fix in 8.0.0: | ||
// https://github.com/ZeeCoder/use-resize-observer/commit/bd0f3c8597bac0d853b88cf585256aac1bd4f554 | ||
// v8.0.0 requires TS4.2. So we'll manually patch until we're ready for TS4.2+ | ||
export const useResizeObserver: typeof useResizeObserverOriginal = (params = {}) => { | ||
const widthRef = React.useRef<number | undefined>(); | ||
const heightRef = React.useRef<number | undefined>(); | ||
const onResize = params.onResize | ||
? (data: {width: number | undefined; height: number | undefined}) => { | ||
if (widthRef.current !== data.width || heightRef.current !== data.height) { | ||
widthRef.current = data.width; | ||
heightRef.current = data.height; | ||
params.onResize!(data); | ||
} | ||
} | ||
: undefined; | ||
return useResizeObserverOriginal({...params, onResize}); | ||
}; | ||
|
||
// When the dependency is moved up to v8.0.0, remove the above function and export below instead | ||
// export {useResizeObserver}; | ||
export {useResizeObserver}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters