mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-06 02:15:35 +08:00
18400fbdee
* Add XXXL size * Update index.zh-CN.md * Update components/list/index.zh-CN.md Co-authored-by: Amumu <yoyo837@hotmail.com> * Try to use `useToken` for building responsiveMap * Try useResponsiveObserve * Fix useResponsiveObserve * Some try * Some try * Some try * Remove impossible test * Remove impossible test * Fix token.screenXSMax * Try to put test back as token.screenXSMax is fixed * Remove impossible test now * Subscribers, subuid and screen are no longer static * reorganize def * chore: not affect no-related file * chore: not affect no-related file * test: update test case * chore: adjust memo logic Co-authored-by: Amumu <yoyo837@hotmail.com> Co-authored-by: 二货机器人 <smith3816@gmail.com>
26 lines
771 B
TypeScript
26 lines
771 B
TypeScript
import { useEffect, useRef } from 'react';
|
|
import useForceUpdate from '../../_util/hooks/useForceUpdate';
|
|
import type { ScreenMap } from '../../_util/responsiveObserve';
|
|
import useResponsiveObserve from '../../_util/responsiveObserve';
|
|
|
|
function useBreakpoint(refreshOnChange: boolean = true): ScreenMap {
|
|
const screensRef = useRef<ScreenMap>({});
|
|
const forceUpdate = useForceUpdate();
|
|
const responsiveObserve = useResponsiveObserve();
|
|
|
|
useEffect(() => {
|
|
const token = responsiveObserve.subscribe((supportScreens) => {
|
|
screensRef.current = supportScreens;
|
|
if (refreshOnChange) {
|
|
forceUpdate();
|
|
}
|
|
});
|
|
|
|
return () => responsiveObserve.unsubscribe(token);
|
|
}, []);
|
|
|
|
return screensRef.current;
|
|
}
|
|
|
|
export default useBreakpoint;
|