GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Polyline and Polygons do not re-render on props change · Issue #342 · fullstackreact/google-maps-react

Polyline and Polygons do not re-render on props change #342

New issue
Copy link
New issue
Copy link
Open
Open
Polyline and Polygons do not re-render on props change#342
Copy link

Description

@sselfridge
sselfridge
opened on Apr 27, 2019
Issue body actions

Polyline and Polygons both do not re-render if their props are changed (visibility, color).

Currently, only checks are if the map has changed or if the path is different but other changes to the component props do not trigger a re-render.

Fixed in PR: #341 - Added propsChanged() check that runs through the prev props and existing ones and triggers a re-render if they are different.

Reacted by Pablo

Activity

  1. PabloGancharov commented on May 14, 2019

    @PabloGancharov
    PabloGancharov
    on May 14, 2019
    More actions

    meanwhile here is a workaround:
    trigger a resize event after the

          polygon.setOptions({ fillColor: '#FF0000', fillOpacity: 0.35 });
          maps.event.trigger(map, 'resize')  // force map update
    
  2. abnersimoes commented on Sep 2, 2020

    @abnersimoes
    abnersimoes
    on Sep 2, 2020
    More actions

    I found another alternative, with useRef

    Create this component:

    import React, {useEffect, useRef} from 'react'
    import {Polygon} from 'google-maps-react'
    
    function PolygonMap({paths, color, ...props}) {
      const polygonRef = useRef()
    
      useEffect(() => {
        polygonRef.current.polygon.setOptions({
          paths,
          strokeColor: color,
          fillColor: color,
        })
      }, [color, paths])
    
      return (
        <Polygon
          ref={polygonRef}
          paths={paths}
          strokeColor={color}
          strokeOpacity={1}
          strokeWeight={3}
          fillColor={color}
          fillOpacity={0.5}
          {...props}
        />
      )
    }
    
    export default PolygonMap
    

    Then use it on the map:

    <Map {...}>
      <PolygonMap paths={paths} color={color} />
    </Map>
    
    Reacted by Carlos Eduardo Reis de Godoy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.