Skip to content

Commit b63dcb3

Browse files
committed
Only set marker on children who can have a marker as their anchor, fixing type checks too
1 parent 2ded8be commit b63dcb3

File tree

1 file changed

+13
-4
lines changed
  • packages/react-google-maps-api/src/components/drawing

1 file changed

+13
-4
lines changed

packages/react-google-maps-api/src/components/drawing/Marker.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,20 @@ export class Marker extends React.PureComponent<MarkerProps, MarkerState> {
249249
}
250250

251251
render(): React.ReactNode {
252-
let children: ReactNode[]|null = null
252+
interface HasMarkerAnchor {
253+
anchor?: google.maps.Marker | null
254+
}
255+
256+
let children: ReactNode | null = null
253257
if(this.props.children) {
254-
children = React.Children.toArray(this.props.children).map(
255-
(e) => {return React.cloneElement(e, {anchor: this.state.marker})}
256-
)
258+
children = React.Children.map(this.props.children, child => {
259+
if(!React.isValidElement<HasMarkerAnchor>(child)) {
260+
return child;
261+
}
262+
263+
let elementChild: React.ReactElement<HasMarkerAnchor> = child;
264+
return React.cloneElement(elementChild, {anchor: this.state.marker});
265+
})
257266
}
258267
return children || null
259268
}

0 commit comments

Comments
 (0)