wrap updateBounds into useCallback
avoids call on every rerender
This commit is contained in:
parent
28f422162d
commit
baed5ba267
|
@ -1,4 +1,4 @@
|
||||||
import React, {useEffect, useState} from 'react'
|
import React, {useCallback, useEffect, useState} from 'react'
|
||||||
import 'leaflet'
|
import 'leaflet'
|
||||||
import 'leaflet/dist/leaflet.css'
|
import 'leaflet/dist/leaflet.css'
|
||||||
|
|
||||||
|
@ -18,11 +18,16 @@ type LeafletMapProps = {onBoundsChange?: (bounds: L.LatLngBounds) => void}
|
||||||
|
|
||||||
const BoundsChangeListener = ({onBoundsChange}: {onBoundsChange?: (bounds: L.LatLngBounds) => void}) => {
|
const BoundsChangeListener = ({onBoundsChange}: {onBoundsChange?: (bounds: L.LatLngBounds) => void}) => {
|
||||||
const map = useMap()
|
const map = useMap()
|
||||||
const updateBounds = () => {
|
|
||||||
|
const updateBounds = useCallback(
|
||||||
|
() => {
|
||||||
onBoundsChange && onBoundsChange(
|
onBoundsChange && onBoundsChange(
|
||||||
map.getBounds()
|
map.getBounds()
|
||||||
)
|
)
|
||||||
}
|
},
|
||||||
|
[map],
|
||||||
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
updateBounds()
|
updateBounds()
|
||||||
}, [map, updateBounds])
|
}, [map, updateBounds])
|
||||||
|
|
Loading…
Reference in New Issue
Block a user