Skip to content

Commit 7122304

Browse files
authored
merge: 알림 오류 해결 및 useCallback사용
fix: 알림 오류 해결 및 useCallback사용
2 parents 624102d + 56dcad0 commit 7122304

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/components/Header/index.jsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,21 @@ const InnerRight = styled.div`
4343

4444
export const Header = ({ prev, title, info, complete, onComplete }) => {
4545
const navigate = useNavigate();
46+
const [isSeen, setIsSeen] = useState(true);
4647
const onClickPrev = () => {
4748
navigate(-1);
4849
};
49-
const [isSeen, setIsSeen] = useState(true);
50+
5051
const [token] = useLocalToken();
51-
const initNotifications = async () => {
52-
const fetchedNotifications = await getNotifications(token);
53-
setIsSeen(fetchedNotifications.data[0].seen);
54-
};
55-
initNotifications();
52+
useEffect(() => {
53+
const initNotifications = async () => {
54+
const fetchedNotifications = await getNotifications(token);
55+
setIsSeen(
56+
fetchedNotifications.data.length === 0 ? isSeen : fetchedNotifications.data[0].seen,
57+
);
58+
};
59+
initNotifications();
60+
}, [token, isSeen]);
5661

5762
return (
5863
<HeaderContainer top height={headerHeight}>

0 commit comments

Comments
 (0)