채팅방 입장 시 메시지 불러오기
const wsConnectSubscribe = React.useCallback(() => {
try {
ws.connect({},async () => {
ws.subscribe(
`/sub/chat/room/${roomId}`,
(data) => {
const newMessage = JSON.parse(data.body);
console.log(userInfo);
dispatch(getMessage(newMessage));
},
{ token, userEmail: userInfo.email },
);
});
// 그냥 이전 메시지 로드하는 디스패치 한줄 추가 했다.
dispatch(loadMessagesToAxios(roomId))
} catch (error) {
console.log(error);
}
}, [dispatch, userId, ws]);
이후에 더 테스트를 해보니 아직도 채팅방을 불러오는게 잘 안되는 것 같았다.
지금 생각되는 몇가지의 원인은 아래와 같다.
Opening Web Socket...
메시지가 뜨자마자 이전 메시지를 가져오는 dispatch를 실행 하는데 맨 아래 보이는 SUBSCRIBE가 끝난 이후에 dispatch를 실행 해야하는건가?