Skip to content

Instantly share code, notes, and snippets.

@dainelmawer
Created October 11, 2018 08:35
Show Gist options
  • Save dainelmawer/b5d62f6b572d07f9c29b44306c503428 to your computer and use it in GitHub Desktop.
Save dainelmawer/b5d62f6b572d07f9c29b44306c503428 to your computer and use it in GitHub Desktop.
import React, {Component} from 'react';
class Test extends Component {
constructor(props) {
super(props);
this.state = {
posts: {}
}
}
componentDidMount() {
console.log('Make an API call!');
}
componentDidUpdate(prevProps) {
if(this.props.featured !== prevProps.featured) {
console.log('Looks like props changed');
}
}
componentWillUnmount() {
console.log('Close API call connection');
}
render() {
const { posts } = this.state;
const { author, time, featured } = this.props;
const featuredCls = featured ? 'featured' : '';
return(
<div className={featuredCls}>
<time>{time}</time>
<span>{author}</span>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment