Created
August 27, 2018 05:56
-
-
Save jackparmer/4753d7d71896b097156cd5e6b338e588 to your computer and use it in GitHub Desktop.
This file contains 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, { Component } from 'react'; | |
import Ideogram from 'ideogram'; | |
class ReactIdeogram extends Component { | |
clearDiv = () => { | |
let container = document.getElementById('ideogram-container'); | |
if (container) { | |
while (container.hasChildNodes()) { | |
container.removeChild(container.lastChild); | |
} | |
} | |
} | |
componentDidMount() { | |
// Now that the container Div has drawn, | |
// draw the Ideogram SVG inside the container | |
console.warn('>>> ', this.props.config); | |
new Ideogram(this.props.config); | |
} | |
componentDidUpdate () { | |
console.warn('CDU ', this.props); | |
this.clearDiv(); | |
let config = this.props.config; | |
setTimeout(function() { | |
new Ideogram(config); | |
}, 100); | |
} | |
componentWillReceiveProps() { | |
// Empty the container before redraw | |
console.warn('CWRP ', this.props); | |
this.clearDiv(); | |
} | |
render() { | |
return ( | |
<div id='ideogram-container'></div> | |
); | |
} | |
} | |
export default ReactIdeogram; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment