Skip to content

Commit

Permalink
feat(map): Set keys to ensure ordering when new elements are added
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorgerhardt committed Sep 25, 2018
1 parent b2bc8ec commit bfd1bbb
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/components/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,13 @@ export default class Map extends PureComponent<Props, State> {
start,
zoom
} = this.props

// Index elements with keys to reset them when elements are added / removed
const poiKey = pointsOfInterest.length > 0 ? 1 : 0
const startKey = `${poiKey + 1}-start-key`
const endKey = `${startKey + 1}-end-key`
const selectKey = `${endKey + 1}-select-key`

const {
lastClickedLabel,
lastClickedPosition,
Expand Down Expand Up @@ -201,13 +208,15 @@ export default class Map extends PureComponent<Props, State> {
pointsOfInterest.length > 0 &&
<GeoJSON
data={poiToFeatures(pointsOfInterest)}
key={poiKey}
onClick={this._clickPoi}
/>}

{start &&
<Marker
draggable
icon={startIcon}
key={startKey}
onDragEnd={this._setStartWithEvent}
position={start.position}
>
Expand All @@ -220,6 +229,7 @@ export default class Map extends PureComponent<Props, State> {
<Marker
draggable
icon={endIcon}
key={endKey}
onDragEnd={this._setEndWithEvent}
position={end.position}
>
Expand All @@ -229,7 +239,11 @@ export default class Map extends PureComponent<Props, State> {
</Marker>}

{showSelectStartOrEnd &&
<Popup closeButton={false} position={lastClickedPosition}>
<Popup
closeButton={false}
key={selectKey}
position={lastClickedPosition}
>
<div className='Popup'>
{lastClickedLabel &&
<h3>
Expand Down

0 comments on commit bfd1bbb

Please sign in to comment.