Created
February 27, 2018 13:03
-
-
Save atmd83/a05edd0eb4924481ecde6269efcebf05 to your computer and use it in GitHub Desktop.
medium
This file contains 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
import React from 'react'; | |
import PubSub from 'pubsub-js'; | |
export default class Thing extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
message: 'The value is' | |
} | |
} | |
componentDidMount() { | |
PubSub.publish('thing.did.mount'); | |
} | |
componentWillReceiveProps(nextProps, nextState) { | |
PubSub.publish('thing.will.receive.props'); | |
return true | |
} | |
shouldComponentUpdate(nextProps, nextState) { | |
if (this.props.value !== nextProps.value || this.state.message !== nextState.message) { | |
PubSub.publish('thing.should.update'); | |
return true; | |
} | |
return false; | |
} | |
componentWillUpdate(nextProps, nextState) { | |
PubSub.publish('thing.will.update'); | |
return true; | |
} | |
componentWillUnmount() { | |
PubSub.publish('thing.will.unmount'); | |
} | |
render() { | |
return (<h1>{`${this.state.message} ${this.props.value}`}</h1>); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment