Skip to content

Commit

Permalink
update usecontrols - default values, rm unfired 'load' listener
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane98c committed Feb 14, 2024
1 parent 20cae37 commit 3d3ea9f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/use-controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { flushSync } from 'react-dom'
import { useMapbox } from './mapbox'

export const useControls = () => {
const [zoom, setZoom] = useState()
const [center, setCenter] = useState()
const { map } = useMapbox()
const [zoom, setZoom] = useState(map.getZoom())
const [center, setCenter] = useState(map.getCenter())

const updateControlsSync = useCallback(() => {
flushSync(() => {
Expand All @@ -15,10 +15,10 @@ export const useControls = () => {
}, [])

useEffect(() => {
setZoom(map.getZoom())
setCenter(map.getCenter())
map.on('load', updateControlsSync)
map.on('move', updateControlsSync)
return () => {
map.off('move', updateControlsSync)
}
}, [map])

return { center: center, zoom: zoom }
Expand Down

0 comments on commit 3d3ea9f

Please sign in to comment.