ttbkk-univ / ttbkk-web

ttbkk.com react client
https://ttbkk.com
4 stars 0 forks source link

useCallback으로 선언하여 removeListener에 바로 넣어서 사용 가능하게 하자 #2

Closed siner308 closed 3 years ago

siner308 commented 3 years ago

https://github.com/siner308/ttbkk-web/blob/726f4fb308e82ae6ed8077ad088c16d5ed989150/src/components/Toolbar/CreatePlaceButton.tsx#L15

siner308 commented 3 years ago

  useEffect(() => {
    if(!window.kakao || !window.map) {
      return;
    }
      const clickEvent = (e: any): void => {
    setCreatePlaceLatLng({
      latitude: e.latLng.getLat(),
      longitude: e.latLng.getLng(),
    });
  };
    if (createPlaceButtonClicked) {
      events.push(clickEvent);
      window.map.setCursor('crosshair');
      window.kakao.maps.event.addListener(window.map, 'click', clickEvent);
    } else {
      window.map?.setCursor('grab');
      window.kakao?.maps.event.removeListener(window.map, 'click', events.pop());
    }
  }, [createPlaceButtonClicked]);