Wednesday, 1 February 2017

What is the short way to display props on a parent component? ReactJS Interview Question

Instead listing the properties, use spread operator. {...comment}

_getComments() {
return this.state.comments.map((comment) => {
return <Comment
/*id={comment.id}
author={comment.author}
body={comment.body}
avatarUrl={comment.avatarUrl}*/
{...comment}//spreads out the properties, more dinamic
onDelete={this._deleteComment}
// this arrow function envoking the function need to pass parameters from our outer function we are calling
//onDelete={(commentID) => this._deleteComment(commentID)}
key={comment.id} />
});

WHAT OTHERS ARE READING/RELATED TO THIS:

0 comments:

Post a Comment