I have an svg map component which I want to update whenever the props change. Adding and subtract classes on some of the paths... that sort of thing.
Snap.svg seemed to be the way to go. If someone knows a better way I'd like to hear it!
So here's my render method, and the two lines marked with frowns are the ones I want to get working in a lifecycle method such as ComponentWillReceiveProps
render() {
var map = Snap('#map');
Snap.load("images/map.svg", function(data){
if (map) {
map.append(data);
const a2047 = map.select('#a2047'); <---- :(
a2047.attr({stroke:'yellow', strokeWidth:'6px'}) <---- :(
}
})
return (
<div className="map" id="map"/>
);
}
The problem is, map
won't work anywhere else except inside this Snap.load
callback. I tried several ways, using state
, window.map
, this.map
... and I get errors such as 'select is not a function'.
How to get access to the map in ComponentWillReceiveProps
?
Or is Snap.svg even the way to go for this application?