-
카테고리
-
세부 분야
프론트엔드
-
해결 여부
미해결
안읽은메세지 표시
23.05.16 20:35 작성 조회수 343
0
안녕하세요 제로초님
mutate(0)으로 했는데도 콘솔찍어보니까 다시 1로 변합니다
channel부분만 이러네요
답변을 작성해보세요.
0
조현영
지식공유자2023.05.17
이게 결국 지금까지 내용을 종합적으로 봐야합니다. 네트워크탭에서 0으로 찍혔는데 왜 콘솔에서는 0이 나왔다가 19가 다시 나오는지를 봐야하는 거라서요.
0
장산
질문자2023.05.16
const { data: count, mutate } = useSWR<number>( // 채팅 갯수 가져오는 api , count:n개
userData ? `/api/workspaces/${workspace}/channels/${channel.name}/unreads?after=${date}` : null,
fetcher,
);
아 죄송합니다 제로초님 이 count입니다
import { IChannel, IUser } from '@typings/db';
import fetcher from '@utils/fetcher';
import React, { useEffect, VFC } from 'react';
import { useParams } from 'react-router';
import { NavLink, useLocation } from 'react-router-dom';
import useSWR from 'swr';
interface Props {
channel: IChannel;
}
const EachChannel: VFC<Props> = ({ channel }) => {
const { workspace } = useParams<{ workspace?: string }>();
const location = useLocation();
console.log('location', location.pathname);
const { data: userData } = useSWR<IUser>('/api/users', fetcher, {
dedupingInterval: 2000, // 2초
});
const date = localStorage.getItem(`${workspace}-${channel.name}`) || 0;
const { data: count, mutate } = useSWR<number>( // 채팅 갯수 가져오는 api , count:n개
userData ? `/api/workspaces/${workspace}/channels/${channel.name}/unreads?after=${date}` : null,
fetcher,
);
console.log('count', count);
useEffect(() => {
//location.pathname이 `/workspace/${workspace}/channel/${channel.name}`이랑 같으면 mutate가 0으로 재캐싱된다
if (location.pathname === `/workspace/${workspace}/channel/${channel.name}`) {
mutate(0);
}
}, [mutate, location.pathname, workspace, channel]);
return (
<NavLink key={channel.name} activeClassName="selected" to={`/workspace/${workspace}/channel/${channel.name}`}>
<span className={count !== undefined && count > 0 ? 'bold' : undefined}># {channel.name}</span>
{count !== undefined && count > 0 && <span className="count">{count}</span>}
</NavLink>
);
};
export default EachChannel;
조현영
지식공유자2023.05.17
채널 들어갈 때 여기서 타임스탬프가 업데이트되어야 하는데요. 타임스탬프가 업데이트되고 있지 않은 것으로 보입니다. 로컬스토리지 직접 확인해보세요. 채널 들어갈 때마다 타임스탬프 올라가는지
답변 2