react update components on state update code example
Example 1: set state
class App extends React.Component {
state = { count: 0 }
handleIncrement = () => {
this.setState({ count: this.state.count + 1 })
}
handleDecrement = () => {
this.setState({ count: this.state.count - 1 })
}
render() {
return (
{this.state.count}
)
}
}
Example 2: react lifecycle hooks
class ActivityItem extends React.Component {
render() {
const { activity } = this.props;
return (
{moment(activity.created_at).fromNow()}
{activity.actor.display_login} {activity.payload.action}
{activity.repo.name}
)
}
}