Skip to content

Commit

Permalink
fix(useSize): make observer work without override
Browse files Browse the repository at this point in the history
  • Loading branch information
kripod committed Oct 25, 2019
1 parent ccedf58 commit b5884d8
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions packages/web-api-hooks/src/useSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ export default function useSize(
const [size, setSize] = useState<Readonly<[number, number]>>([0, 0]);

useEffect(() => {
if (!ResizeObserverOverride || !ref.current) return undefined;
const CustomResizeObserver = ResizeObserverOverride || ResizeObserver;
if (!CustomResizeObserver || !ref.current) return undefined;

const observer = new (ResizeObserverOverride || ResizeObserver)(
([entry]) => {
const { width, height } = entry.contentRect;
setSize([width, height]);
},
);
const observer = new CustomResizeObserver(([entry]) => {
const { width, height } = entry.contentRect;
setSize([width, height]);
});
observer.observe(ref.current);

return () => {
Expand Down

0 comments on commit b5884d8

Please sign in to comment.