Skip to content

Commit

Permalink
clear event listeners correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
barbalex committed Jun 17, 2024
1 parent d1c9d1e commit 8cb1dce
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/components/Projekte/Karte/layers/Pop/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext, useEffect, useState } from 'react'
import React, { useContext, useEffect, useState, useCallback } from 'react'
import { observer } from 'mobx-react-lite'
import MarkerClusterGroup from '@changey/react-leaflet-markercluster'
import { useQuery } from '@apollo/client'
Expand Down Expand Up @@ -60,20 +60,18 @@ const Pop = () => {

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [refetchProvoker, setRefetchProvoker] = useState(1)
const refetch = useCallback(() => {
setRefetchProvoker(Math.random())
}, [])
useEffect(() => {
// DO NOT use:
// leafletMap.on('zoomend dragend', refetch
// see: https://github.com/apollographql/apollo-client/issues/1291#issuecomment-367911441
// Also: leafletMap.on('zoomend dragend', ()=> refetch()) never refetches!!??
// Also: use dragend, not moveend because moveend fires on zoomend as well
map.on('zoomend dragend', () => {
// console.log('zoomend dragend')
setRefetchProvoker(Math.random())
})
map.on('zoomend dragend', refetch)
return () => {
map.off('zoomend dragend', () => {
setRefetchProvoker(Math.random())
})
map.off('zoomend dragend', refetch)
}
}, [map])

Expand Down

0 comments on commit 8cb1dce

Please sign in to comment.