JustFly1984 / react-google-maps-api

React Google Maps API
MIT License
1.78k stars 437 forks source link

i can't change mode with custom button #2995

Closed amirhosein-rafeie closed 2 years ago

amirhosein-rafeie commented 2 years ago

Issue template

If you want to ask question, please ask it in Github Discussions, Spectrum.chat or Slack channel

Please do not post unformatted code into issues, and please do not ask questions. Only real issues, PR's or feature requests are allowed. Minimal reproduction in codesandbox.io is required.

Please provide an explanation of the issue

Your Environment

os: windows

node --16.13.0

react version 17.0.2

@react-google-maps/api version 2.8.1

How does it behave?

we don't have acccess to setDrawingModes by ref

How should it behave correctly?

we should be able to change drawingModes by Ref

Basic implementation of incorrect behavior in codesandbox.com

const drawingRef = useRef();

<DrawingManager ref={drawingRef} drawingMode="polygon" onLoad={(e) => console.log(e)} options={{ drawingControl: true, drawingControlOptions: { drawingModes: ["polygon"], }, polygonOptions: { editable: true, draggable: true, strokeColor: "red", strokeWeight: 2, }, }} /> <button onClick={()=>{ drawingRef.current.setDrawingMode(null); //it doesnt work }}>Change Mode

JustFly1984 commented 2 years ago

@amirhosein-rafeie There is no ref prop on components. use onLoad prop function to receive an instance in arguments.

ref is old way to receive instance used by unmaintained npm react-google-maps-api@9.4.5 library

This library never had a ref property!