Skip to content

Instantly share code, notes, and snippets.

@classiemilio
Last active March 3, 2018 01:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
const React = require(‘react’);
const ReactDOM = require(‘react-dom’);
const MyTooltipComponent = require('my-tooltip-component');
class MyGraphComponent extends React.Component {
componentDidMount() {
this.drawChart();
}
shouldComponentUpdate() {
return false;
}
componentWillUnmount() {
ReactDOM.unmountComponentAtNode(this.tooltipTarget);
}
drawChart() {
/*
D3 code to create our visualization by appending onto this.svg
*/
// At some point we render a child, say a tooltip
const tooltipData = ...
this.renderTooltip([50, 100], tooltipData);
}
render() {
return (
<div>
<div ref={(elem) => { this.tooltipTarget = elem; }} />
<svg ref={(elem) => { this.svg = elem; }}>
</svg>
</div>
);
}
renderTooltip(coordinates, tooltipData) {
const tooltipComponent = (
<MyTooltipComponent
coordinates={coordinates}
data={tooltipData} />
);
ReactDOM.render(tooltipComponent, this.tooltipTarget);
}
}
@klairetan
Copy link

Cool example! I might be missing something, but I was wondering how this would allow the chart to update in response to changes in its data?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment