zcreativelabs / react-simple-maps

Beautiful React SVG maps with d3-geo and topojson using a declarative api.
https://www.react-simple-maps.io/
MIT License
3.12k stars 426 forks source link

Handling of input geographies may need improvement? #185

Open payamazadi opened 4 years ago

payamazadi commented 4 years ago

Right now if you want to implement the maps, we have:

<Geographies geography={url}> or maybe <Geographies geography={someObject}>

And when I check the code in the component, it ends up here:

if (isString(geography)) { fetchGeographies(geography).then(geos => { if (geos) setGeographies(getFeatures(geos, parseGeographies)) }) } else { setGeographies(getFeatures(geography, parseGeographies)) }

Is this the best implementation? It means that at the time I go to render the component I must already know the URL I'm going to use or have resolved the data object to pass in. But as a user I can't make this guarantee.

Maybe the code needs to be improved to also receive and handle a Promise, or something like that.

The goal would be that in my code I can use componentDidMount to resolve the data I need, place it in the state, and then pass in the state key to the component when I go to render.

Or am I thinking about this wrong?.. Any help would be appreciated..