Skip to content

Instantly share code, notes, and snippets.

@mrcthms
Created July 1, 2020 13:09
Show Gist options
  • Save mrcthms/b7a83eb33516a0b45c781de1acda0c22 to your computer and use it in GitHub Desktop.
Save mrcthms/b7a83eb33516a0b45c781de1acda0c22 to your computer and use it in GitHub Desktop.
class MyComponent extends Component {
componentDidMount() {
this.doSideEffect(this.props.foo)
}
componentDidUpdate(prev) {
if (prev.foo !== this.props.foo) {
this.doSideEffect(this.props.foo)
}
}
doSideEffect = (foo) => {
console.log(foo)
}
render() {
return <div>Hello, world</div>
}
}
<MyComponent foo={WHATEVER} />
class MyComponent extends Component {
componentDidMount() {
this.doSideEffect(this.props.foo)
}
doSideEffect = (foo) => {
console.log(foo)
}
render() {
return <div>Hello, world</div>
}
}
<MyComponent foo={WHATEVER} />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment