ant-design/components/grid/hooks/useBreakpoint.tsx
骗你是小猫咪 61d0d6b182
feat: useBreakpoint hook (#22226)
* feat: useBreakpoint hook

* update snapshots

* update snapshots

* update snapshots

* add useBreakpoint hook test
2020-03-15 20:53:23 +08:00

19 lines
466 B
TypeScript

import { useEffect, useState } from 'react';
import ResponsiveObserve, { ScreenMap } from '../../_util/responsiveObserve';
function useBreakpoint(): ScreenMap {
const [screens, setScreens] = useState<ScreenMap>({});
useEffect(() => {
const token = ResponsiveObserve.subscribe(supportScreens => {
setScreens(supportScreens);
});
return () => ResponsiveObserve.unsubscribe(token);
}, []);
return screens;
}
export default useBreakpoint;