Skip to content

Commit

Permalink
Fix: useEffect를 이용해 새로고침해도 URL에 따라 아이콘색이 유지
Browse files Browse the repository at this point in the history
  • Loading branch information
pp449 committed Apr 9, 2023
1 parent b8cfc7f commit 428a9c8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/components/FooterTab/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Icon from '@components/Icon';
import styled from '@emotion/styled';
import { useState } from 'react';
import { useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';

type IconKind =
Expand All @@ -26,9 +26,13 @@ const footerIcons = [
] as const;

const FooterTab = () => {
const [activeIcon, setActiveIcon] = useState('home');
const [activeIcon, setActiveIcon] = useState('/');
const navigate = useNavigate();

useEffect(() => {
setActiveIcon(window.location.pathname);
}, [window.location.pathname]);

const handleIconClick = (kind: IconKind, path: string) => {
setActiveIcon(kind);
navigate(path);
Expand All @@ -45,7 +49,7 @@ const FooterTab = () => {
<Icon
key={kind}
kind={kind}
color={activeIcon === kind ? PRIMARY_COLOR : BLACK_COLOR}
color={activeIcon === path ? PRIMARY_COLOR : BLACK_COLOR}
/>
</IconContainer>
))}
Expand Down

0 comments on commit 428a9c8

Please sign in to comment.