diff --git a/src/datamap.jsx b/src/datamap.jsx index a71b2f3..ccf755b 100644 --- a/src/datamap.jsx +++ b/src/datamap.jsx @@ -1,6 +1,10 @@ import React from 'react'; import Datamaps from 'datamaps'; +const MAP_CLEARING_PROPS = [ + 'setProjection', 'scope', 'height', 'width' +] + export default class Datamap extends React.Component { static propTypes = { @@ -22,10 +26,7 @@ export default class Datamap extends React.Component { } componentWillReceiveProps(newProps) { - if ( - this.props.height !== newProps.height - || this.props.width !== newProps.width - ) { + if (this.propChangeRequiresMapClear(newProps, this.props)) { this.clear(); } } @@ -38,6 +39,10 @@ export default class Datamap extends React.Component { this.clear(); } + propChangeRequiresMapClear(newProps, oldProps) { + return Object.keys(newProps).filter((prop) => MAP_CLEARING_PROPS.indexOf(prop) !== -1).filter((prop) => oldProps[prop] !== newProps[prop]).length > 0 + } + clear() { const { container } = this.refs;