React is a popular JavaScript library. This tutorial will show you how to install our maps within a React component.
Download DemoTo use the map in a React component, follow these steps:
Choose the map you want to install:
Add the React library to our webpage. For simplicity, we use a CDN to embed React.
<script src="https://unpkg.com/react@16/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js" crossorigin></script>
Embed the map files directly onto the webpage.
<script src="mapdata.js"></script>
<script src="usmap.js"></script>
Disable the map's default auto loading.
<script>simplemaps_usmap_mapdata.main_settings.auto_load = 'no';</script>
Alternatively, you could do this within the mapdata.js file.
Add the following HTML to your webpage:
<div id="react_container"></div>
This is the container <div>
that React will control.
Add the following JavaScript to your webpage:
<script>
'use strict';
const e = React.createElement;
class SimpleMapsComponent extends React.Component {
render() {
return e('div', {id:'map'})
}
componentDidMount(){
simplemaps_usmap.load();
}
}
const domContainer = document.querySelector('#react_container');
ReactDOM.render(e(SimpleMapsComponent), domContainer);
</script>
This code creates a React component, populates it with a target div for the map (#map), and then manually loads the map once the component has been mounted.
Home | License | Privacy | Releases | Testimonials | Resources | Documentation | Order Lookup | All Maps | FAQs
Formerly FlashUSAmap.com and FlashWorldMap.com
SimpleMaps.com is a product of Pareto Software, LLC. © 2010-2024.