Skip to content

Instantly share code, notes, and snippets.

@dkwingsmt
Last active May 2, 2018 21:23
Show Gist options
  • Select an option

  • Save dkwingsmt/341f27e36a8d0b7c4067dc689c982f09 to your computer and use it in GitHub Desktop.

Select an option

Save dkwingsmt/341f27e36a8d0b7c4067dc689c982f09 to your computer and use it in GitHub Desktop.
Mounting test
import React, { Component } from 'react';
class MountingTest extends Component {
componentDidMount() {
console.warn('mount', this.props.name);
}
componentWillUnmount() {
console.warn('unmount', this.props.name);
}
render() {
return <div>{this.props.name}</div>;
}
}
class App extends Component {
state = {
month: 1,
}
render() {
return (
<div>
<div>
<button onClick={() => this.setState(({month}) => ({month: month+1}))}>
+ Month {this.state.month}
</button>
</div>
{(this.state.month % 2) &&
<MountingTest name="foo" />
}
{!(this.state.month % 2) &&
<MountingTest name="bar" />
}
{(this.state.month % 2) ?
<MountingTest name="dog" /> :
<MountingTest name="cat" />
}
</div>
);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment