From d6b0b9f9366f5731a6b8cb6e22de7dd4140fa7fd Mon Sep 17 00:00:00 2001 From: hae-on Date: Fri, 15 Sep 2023 10:49:11 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=9D=B4=EB=8F=99=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/Common/CategoryTab/CategoryTab.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/frontend/src/components/Common/CategoryTab/CategoryTab.tsx b/frontend/src/components/Common/CategoryTab/CategoryTab.tsx index 42e2ba02d..8796c65f1 100644 --- a/frontend/src/components/Common/CategoryTab/CategoryTab.tsx +++ b/frontend/src/components/Common/CategoryTab/CategoryTab.tsx @@ -1,4 +1,6 @@ import { Button, theme } from '@fun-eat/design-system'; +import { useEffect } from 'react'; +import { useLocation } from 'react-router-dom'; import type { CSSProp } from 'styled-components'; import styled from 'styled-components'; @@ -12,10 +14,21 @@ interface CategoryMenuProps { const CategoryTab = ({ menuVariant }: CategoryMenuProps) => { const { data: categories } = useCategoryQuery(menuVariant); + const { categoryIds } = useCategoryValueContext(); const { selectCategory } = useCategoryActionContext(); const currentCategoryId = categoryIds[menuVariant]; + const location = useLocation(); + const queryParams = new URLSearchParams(location.search); + const categoryIdFromURL = queryParams.get('category'); + + useEffect(() => { + if (categoryIdFromURL) { + selectCategory(menuVariant, parseInt(categoryIdFromURL)); + } + }, [location]); + return ( {categories.map((menu) => {