Skip to content

Commit

Permalink
refactor: 카테고리 이동 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
hae-on committed Sep 15, 2023
1 parent f9b371b commit d6b0b9f
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions frontend/src/components/Common/CategoryTab/CategoryTab.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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 (
<CategoryMenuContainer>
{categories.map((menu) => {
Expand Down

0 comments on commit d6b0b9f

Please sign in to comment.