/
CommentWrite.js
52 lines (43 loc) · 1.24 KB
/
CommentWrite.js
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
43
44
45
46
47
48
49
50
51
52
//components/CommentWrite.js
import React from "react";
import { Grid, Input, Button } from "../elements";
import { useDispatch } from "react-redux";
import { actionCreators as commentActions } from "../redux/modules/comment";
const CommentWrite = (props) => {
const dispatch = useDispatch();
const { post_id } = props;
const [comment_text, setCommentText] = React.useState("");
const onChange = (e) => {
setCommentText(e.target.value);
};
const write = () => {
if (comment_text === "") {
window.alert("댓글을 입력해주세요!");
return;
}
// 입력된 텍스트는 지우기!
setCommentText("");
// 파이어스토어에 추가합니다.
dispatch(commentActions.addCommentFB(post_id, comment_text));
};
return (
<React.Fragment>
<Grid padding="16px" is_flex>
<Input
placeholder="댓글 내용을 입력해주세요 :)"
_onChange={onChange}
value={comment_text}
onSubmit={write}
is_Submit
/>
<Button width="50px" margin="0px 2px 0px 2px" _onClick={write}>
작성
</Button>
</Grid>
</React.Fragment>
);
};
CommentWrite.defaultProps = {
post_id: "",
};
export default CommentWrite;