Submit.tsx
1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import React from 'react';
import TextArea from 'antd/lib/input/TextArea';
import { Button } from 'antd';
import { useMutation } from '@apollo/client';
import { CREATE_COMMENT } from '@src/gql/create-comment';
export default function Submit({ title, postId, addCommentList }) {
const [content, setContent] = React.useState('');
const [createComment] = useMutation(CREATE_COMMENT);
const handleChange = (e) => {
setContent(e.target.value);
};
const handleSubmit = async () => {
const { data } = await createComment({
variables: { input: { content, post_id: postId } },
});
setContent('');
data && addCommentList(data.createComment);
};
return (
<>
<TextArea
value={content}
onChange={handleChange}
placeholder={'댓글을 입력하세요'}
autoSize={{ minRows: 3, maxRows: 5 }}
className={'comments-textarea'}
/>
<Button
type={'primary'}
size={'large'}
onClick={handleSubmit}
className={'comments-submit-button'}
>
{title}
</Button>
</>
);
}