mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-06 02:15:35 +08:00
9f602aa710
* fix: Table render twice * chore: clean up * test: Fix test case
24 lines
665 B
TypeScript
24 lines
665 B
TypeScript
import { useEffect, useRef } from 'react';
|
|
import useForceUpdate from '../../_util/hooks/useForceUpdate';
|
|
import ResponsiveObserve, { ScreenMap } 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;
|