Pointed location: {this.state.pointedLocation}
@@ -87,7 +79,8 @@ class LinkMap extends React.Component {
onLocationMouseOut={this.handleLocationMouseOut}
onLocationClick={this.handleLocationClick}
onLocationFocus={this.handleLocationFocus}
- onLocationBlur={this.handleLocationBlur} />
+ onLocationBlur={this.handleLocationBlur}
+ />
);
diff --git a/examples/src/components/radio-map.jsx b/examples/src/components/radio-map.jsx
index aa41f5c..5be71a2 100644
--- a/examples/src/components/radio-map.jsx
+++ b/examples/src/components/radio-map.jsx
@@ -1,51 +1,41 @@
-import React from 'react';
-import Australia from '@svg-maps/australia';
-import { RadioSVGMap } from '../../../src/';
-import { getLocationName } from '../utils';
+import { PureComponent } from "react";
+import Australia from "@svg-maps/australia";
+import { RadioSVGMap } from "../../../src/";
+import { getLocationName } from "../utils";
-class RadioMap extends React.Component {
+class RadioMap extends PureComponent {
constructor(props) {
super(props);
-
this.state = {
pointedLocation: null,
focusedLocation: null,
- selectedLocation: null
+ selectedLocation: null,
};
-
- this.handleLocationMouseOver = this.handleLocationMouseOver.bind(this);
- this.handleLocationMouseOut = this.handleLocationMouseOut.bind(this);
- this.handleLocationFocus = this.handleLocationFocus.bind(this);
- this.handleLocationBlur = this.handleLocationBlur.bind(this);
- this.handleOnChange = this.handleOnChange.bind(this);
}
- handleLocationMouseOver(event) {
+ handleLocationMouseOver = event => {
const pointedLocation = getLocationName(event);
this.setState({ pointedLocation: pointedLocation });
- }
+ };
- handleLocationMouseOut() {
+ handleLocationMouseOut = () => {
this.setState({ pointedLocation: null });
- }
+ };
- handleLocationFocus(event) {
+ handleLocationFocus = event => {
const focusedLocation = getLocationName(event);
this.setState({ focusedLocation: focusedLocation });
- }
+ };
- handleLocationBlur() {
+ handleLocationBlur = () => {
this.setState({ focusedLocation: null });
- }
+ };
- handleOnChange(selectedNode) {
- this.setState(prevState => {
- return {
- ...prevState,
- selectedLocation: selectedNode.attributes.name.value
- };
+ handleOnChange = newLocation => {
+ this.setState({
+ selectedLocation: newLocation,
});
- }
+ };
render() {
return (
@@ -61,7 +51,7 @@ class RadioMap extends React.Component {
Focused location: {this.state.focusedLocation}
- Selected location: {this.state.selectedLocation}
+ Selected location: {this.state.selectedLocation?.name}
@@ -71,7 +61,10 @@ class RadioMap extends React.Component {
onLocationMouseOut={this.handleLocationMouseOut}
onLocationFocus={this.handleLocationFocus}
onLocationBlur={this.handleLocationBlur}
- onChange={this.handleOnChange} />
+ ref={this.mapRef}
+ onChange={this.handleOnChange}
+ value={this.state.selectedLocation}
+ />