Skip to content

Instantly share code, notes, and snippets.

@sag1v
Last active November 17, 2018 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sag1v/5c09e3c3aab3fb738ecd8b7d878f7e84 to your computer and use it in GitHub Desktop.
Save sag1v/5c09e3c3aab3fb738ecd8b7d878f7e84 to your computer and use it in GitHub Desktop.
react integration with other applications article
import React, {PureComponent} from 'react';
class ReactCounter extends PureComponent {
// create a ref so we can pass the element to mount and unmount
counterRef = React.createRef();
componentDidMount() {
// initial render with props
window.ReactCounter.mount(this.props, this.counterRef.current);
}
componentDidUpdate(prevProps) {
if(prevProps !== this.props){
window.ReactCounter.mount(this.props, this.counterRef.current);
}
}
componentWillUnmount(){
window.ReactCounter.unmount(this.counterRef.current);
}
render() {
return <div ref={this.counterRef}></div>
}
}
export default ReactCounter;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment