Skip to content

Instantly share code, notes, and snippets.

@sag1v
Created November 17, 2018 17:15
Show Gist options
  • Save sag1v/6434be7d4fbd55de88879c37e250a663 to your computer and use it in GitHub Desktop.
Save sag1v/6434be7d4fbd55de88879c37e250a663 to your computer and use it in GitHub Desktop.
react integration with other applications article
class App extends Component {
state = { showCounter: false }
componentDidUpdate(prevProps, prevState) {
const { showCounter } = this.state;
if (prevState.showCounter !== showCounter) {
if(showCounter){
window.ReactCounter.mount();
} else{
window.ReactCounter.unmount();
}
}
}
toggleCounter = () => this.setState(({ showCounter }) => ({ showCounter: !showCounter }));
render() {
return (
<div className="App">
<header className="App-header">
<img onClick={this.toggleCounter} src={logo} className="App-logo" alt="logo" />
<div id="counter-app"></div>
<p>
This is the main App.
</p>
</header>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment