Last active
March 20, 2020 12:33
-
-
Save joe-oli/b31d78c8c0bb1cfa2c8679759353a252 to your computer and use it in GitHub Desktop.
React - Class vs Functional component
This file contains hidden or 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
//--before | |
class Brief extend React.Component { | |
render() { | |
let {post} = this.props | |
return ( | |
<div className="brief"> | |
<Link to={`/apps/blog/posts/${post._id}`} className="title"> | |
<strong>{post.title}</strong> | |
</Link> | |
<p className="description">{post.blurb}</p> | |
</div> | |
) | |
} | |
} | |
static propTypes = { | |
post: React.PropTypes.object.isrequired | |
} | |
//--- replace with: | |
const Brief = ({post}) => { | |
<div className="brief"> | |
<Link to={`/apps/blog/posts/${post._id}`} className="title"> | |
<strong>{post.title}</strong> | |
</Link> | |
<p className="description">{post.blurb}</p> | |
</div> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment