Last active
November 17, 2018 19:52
-
-
Save sag1v/5c09e3c3aab3fb738ecd8b7d878f7e84 to your computer and use it in GitHub Desktop.
react integration with other applications article
This file contains hidden or 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, {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