Skip to content

Commit

Permalink
feat: useDeviceState 추가 및 적용 (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
selfishAltruism committed Mar 18, 2024
1 parent 38aed9b commit b5b354e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './useAuthRedirect';
export * from './usePageUiStore';
export * from './useDeviceState';
8 changes: 8 additions & 0 deletions src/hooks/useDeviceState.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useMediaQuery } from 'react-responsive';

export const useDeviceState = () => {
const isMobile = useMediaQuery({
query: '(max-width:550px)',
});
return [isMobile];
};
5 changes: 3 additions & 2 deletions src/pages/circle/home/CircleHomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as Circle from './components';
import { H2 } from './styled';

import { BodyScreen, GNB, Header, PageBody, PageStoreHOC } from '@/components';
import { usePageUiStore } from '@/hooks';
import { usePageUiStore, useDeviceState } from '@/hooks';

const WEB_WIDTH_CONDITION = 550;
const RESIZE_DELAY = 300;
Expand All @@ -15,6 +15,7 @@ let timer: string | number | NodeJS.Timeout | undefined;
const CircleHomePage: React.FC = observer(() => {
const { fetch, circles, joinedCircles } = usePageUiStore<PageUiStore.CircleHome>();
const [screenWidth, setScreenWidth] = useState(window.innerWidth);
const [isMobile] = useDeviceState();

useEffect(() => {
fetch();
Expand All @@ -41,7 +42,7 @@ const CircleHomePage: React.FC = observer(() => {
<Circle.ListFrame
items={circles}
emptyText={'아직 등록된 동아리가 없어요!'}
ListComponent={screenWidth > WEB_WIDTH_CONDITION ? Circle.WebSlider : Circle.Slider}
ListComponent={!isMobile ? Circle.WebSlider : Circle.Slider}
/>
<H2>내 동아리</H2>
<Circle.ListFrame
Expand Down

0 comments on commit b5b354e

Please sign in to comment.