Fix ResizeObserver polyfilling
This commit is contained in:
parent
64f59ea817
commit
1e9ec824ae
3 changed files with 7 additions and 3 deletions
|
|
@ -257,8 +257,6 @@ export default tseslint.config(
|
||||||
'Response.json',
|
'Response.json',
|
||||||
// document-register-element
|
// document-register-element
|
||||||
'document.registerElement',
|
'document.registerElement',
|
||||||
// resize-observer-polyfill
|
|
||||||
'ResizeObserver',
|
|
||||||
// fast-text-encoding
|
// fast-text-encoding
|
||||||
'TextEncoder',
|
'TextEncoder',
|
||||||
// intersection-observer
|
// intersection-observer
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import AppBar, { type AppBarProps } from '@mui/material/AppBar';
|
import AppBar, { type AppBarProps } from '@mui/material/AppBar';
|
||||||
import useScrollTrigger from '@mui/material/useScrollTrigger';
|
import useScrollTrigger from '@mui/material/useScrollTrigger';
|
||||||
import React, { useLayoutEffect, useRef, useState, type FC, type PropsWithChildren } from 'react';
|
import React, { useLayoutEffect, useRef, useState, type FC, type PropsWithChildren } from 'react';
|
||||||
|
import ResizeObserver from 'resize-observer-polyfill';
|
||||||
|
|
||||||
/** The default height of an AppBar. */
|
/** The default height of an AppBar. */
|
||||||
const DEFAULT_APP_BAR_HEIGHT = 64;
|
const DEFAULT_APP_BAR_HEIGHT = 64;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { MutableRefObject, useLayoutEffect, useRef, useState } from 'react';
|
import { MutableRefObject, useLayoutEffect, useRef, useState } from 'react';
|
||||||
import useResizeObserver from '@react-hook/resize-observer';
|
import useResizeObserver from '@react-hook/resize-observer';
|
||||||
|
import ResizeObserver from 'resize-observer-polyfill';
|
||||||
|
|
||||||
interface Size {
|
interface Size {
|
||||||
width: number;
|
width: number;
|
||||||
|
|
@ -19,7 +20,11 @@ export default function useElementSize<
|
||||||
target.current && setSize(target.current.getBoundingClientRect());
|
target.current && setSize(target.current.getBoundingClientRect());
|
||||||
}, [target]);
|
}, [target]);
|
||||||
|
|
||||||
useResizeObserver(target, (entry) => setSize(entry.contentRect));
|
useResizeObserver(
|
||||||
|
target,
|
||||||
|
(entry) => setSize(entry.contentRect),
|
||||||
|
{ polyfill: ResizeObserver }
|
||||||
|
);
|
||||||
|
|
||||||
return [target, size];
|
return [target, size];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue