Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
리액트 심화 과정 - 4강 댓글 작성하기, 엔터키로 댓글 작성하기, 댓글 갯수 카운트 늘리기
- Loading branch information
Showing
5 changed files
with
116 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,52 @@ | ||
//components/CommentWrite.js | ||
import React from "react"; | ||
|
||
import { Grid, Input, Button } from "../elements"; | ||
|
||
const CommentWrite = () => { | ||
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="댓글 내용을 입력해주세요 :)" /> | ||
<Button width="50px" margin="0px 2px 1px 2px"> | ||
<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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters