작성
·
681
0
DM을 보내면 이모티콘과 영문은 한번씩 가지만
한글로 보낼 경우 2개씩 중복해서 보내집니다
무엇이 잘못된 걸까요?
import ChatBox from '@components/ChatBox';
import ChatList from '@components/ChatList';
import { Container, Header } from '@pages/Channel/styles';
import { IDM } from '@typings/db';
import fetcher from '@utils/fetcher';
import React, { useCallback } from 'react';
import gravatar from 'gravatar';
import { useParams } from 'react-router';
import useSWR from 'swr';
import useInput from '@hooks/useInput';
import axios from 'axios';
const DirectMessage = () => {
const { workspace, id } = useParams<{ workspace: string; id: string }>();
const { data: userData } = useSWR(`/api/workspaces/${workspace}/users/${id}`, fetcher);
const { data: myData } = useSWR('/api/users', fetcher);
const [chat, onChangeChat, setChat] = useInput('');
const {
data: chatData,
mutate: mutateChat,
revalidate,
} = useSWR<IDM[]>(`/api/workspaces/${workspace}/dms/${id}/chats?perPage=20&page=1`, fetcher);
const onSubmitForm = useCallback(
(e) => {
e.preventDefault();
console.log(chat);
if (chat?.trim()) {
axios
.post(`/api/workspaces/${workspace}/dms/${id}/chats`, {
content: chat,
})
.then(() => {
revalidate();
setChat('');
})
.catch(console.error);
}
},
[chat, chatData],
);
if (!userData || !myData) {
return null;
}
return (
<Container>
<Header>
<img src={gravatar.url(userData.email, { s: '24px', d: 'retro' })} alt={userData.nickname} />
</Header>
<ChatList chatData={chatData} />
<ChatBox chat={chat} onChangeChat={onChangeChat} onSubmitForm={onSubmitForm} />
</Container>
);
};
export default DirectMessage;
답변 3
0
마찬가지로 sleact.nodebird.com에서는 되는지 확인해주세요. 된다면 제 깃헙 코드를 쓰셔야 할 것 같습니다.