Skip to content

Instantly share code, notes, and snippets.

@jackparmer
Created August 27, 2018 05:56
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 jackparmer/4753d7d71896b097156cd5e6b338e588 to your computer and use it in GitHub Desktop.
Save jackparmer/4753d7d71896b097156cd5e6b338e588 to your computer and use it in GitHub Desktop.
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