mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-16 01:41:02 +08:00
1719748a29
* chore: eslint add consistent-type-imports * fix avatar * Update Item.tsx
25 lines
714 B
TypeScript
25 lines
714 B
TypeScript
import { useEffect, useRef } from 'react';
|
|
import useForceUpdate from '../../_util/hooks/useForceUpdate';
|
|
import type { ScreenMap } from '../../_util/responsiveObserve';
|
|
import ResponsiveObserve from '../../_util/responsiveObserve';
|
|
|
|
function useBreakpoint(refreshOnChange: boolean = true): ScreenMap {
|
|
const screensRef = useRef<ScreenMap>({});
|
|
const forceUpdate = useForceUpdate();
|
|
|
|
useEffect(() => {
|
|
const token = ResponsiveObserve.subscribe(supportScreens => {
|
|
screensRef.current = supportScreens;
|
|
if (refreshOnChange) {
|
|
forceUpdate();
|
|
}
|
|
});
|
|
|
|
return () => ResponsiveObserve.unsubscribe(token);
|
|
}, []);
|
|
|
|
return screensRef.current;
|
|
}
|
|
|
|
export default useBreakpoint;
|