-
Notifications
You must be signed in to change notification settings - Fork 46
Description
I'm trying to use svgMap with Next.js and Typescript and I feel like I'm doing something wrong.
First of all, I can't find any '@types/svgmap' package when I try to install one, so I just need to force Typescript to ignore this.
Secondly, I am using the library as it is documented, but I get a 'window is not defined' error when I run the code. I have created a div element with the "svgMap" id with it as follows:
<div className="map-container w-full" id="svgMap"></div>
I imported the library, with its css.
// @ts-ignore
import svgMap from "svgmap";
import "svgmap/dist/svgMap.min.css"
and created a new svgMap when the component is mounted. I've also made sure that it's only run if 'window' is defined. Here's the code:
useEffect(() => {
new svgMap({
targetElementID: "svgMap",
data: {
data: {
gdp: {
name: "GDP per capita",
format: "{0} USD",
thousandSeparator: ",",
thresholdMax: 50000,
thresholdMin: 1000,
},
change: {
name: "Change to year before",
format: "{0} %",
},
},
applyData: "gdp",
values: {
AF: { gdp: 587, change: 4.73 },
AL: { gdp: 4583, change: 11.09 },
DZ: { gdp: 4293, change: 10.01 },
// ...
},
},
});
}, []);
That is an example map data that's stated in the documentation of the library, and as I said when I run it I get this:
Am I using the library in a wrong way? or Is it not compatible with React yet?