We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
The text was updated successfully, but these errors were encountered:
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
Sorry, something went wrong.
I found another alternative, with useRef
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>
No branches or pull requests
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.
The text was updated successfully, but these errors were encountered: