Skip to content

Instantly share code, notes, and snippets.

@joe-oli
Last active March 20, 2020 12:33
Show Gist options
  • Save joe-oli/b31d78c8c0bb1cfa2c8679759353a252 to your computer and use it in GitHub Desktop.
Save joe-oli/b31d78c8c0bb1cfa2c8679759353a252 to your computer and use it in GitHub Desktop.
React - Class vs Functional component
//--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