Skip to content

Commit

Permalink
update comment-app2,3
Browse files Browse the repository at this point in the history
  • Loading branch information
huzidaha committed Mar 31, 2017
1 parent 8760a6d commit 4d79d8f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
4 changes: 3 additions & 1 deletion comment-app2-hoc/src/CommentApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class CommentApp extends Component {

constructor (props) {
super(props)
this.state = { comments: props.data }
this.state = {
comments: props.data || []
}
}

handleSubmitComment (comment) {
Expand Down
7 changes: 5 additions & 2 deletions comment-app2-hoc/src/CommentList.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ class CommentList extends Component {
onDeleteComment: PropTypes.func
}

static defaultProps = {
comments: []
}

handleDeleteComment (index) {
if (this.props.onDeleteComment) {
this.props.onDeleteComment(index)
}
}

render() {
const comments = this.props.comments || []
return (
<div>
{comments.map((comment, i) =>
{this.props.comments.map((comment, i) =>
<Comment
comment={comment}
key={i}
Expand Down
4 changes: 3 additions & 1 deletion comment-app3/src/CommentApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class CommentApp extends Component {

constructor (props) {
super(props)
this.state = { comments: props.data }
this.state = {
comments: props.data || []
}
}

handleSubmitComment (comment) {
Expand Down
7 changes: 5 additions & 2 deletions comment-app3/src/CommentList.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ class CommentList extends Component {
onDeleteComment: PropTypes.func
}

static defaultProps = {
comments: []
}

handleDeleteComment (index) {
if (this.props.onDeleteComment) {
this.props.onDeleteComment(index)
}
}

render() {
const comments = this.props.comments || []
return (
<div>
{comments.map((comment, i) =>
{this.props.comments.map((comment, i) =>
<Comment
comment={comment}
key={i}
Expand Down

0 comments on commit 4d79d8f

Please sign in to comment.