Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu stays open #96

Closed
carolineleger opened this issue Jan 19, 2021 · 2 comments
Closed

Menu stays open #96

carolineleger opened this issue Jan 19, 2021 · 2 comments

Comments

@carolineleger
Copy link

carolineleger commented Jan 19, 2021

Hi,

I'm having the exact same issue as this one:
#81
With the menu reopening after searching, except that i'm not using bbox.

My geocoder search field is outside my map component, I also tried to put it in the same component, but with same results.
Any idea?

Thanks!

const Map = (props) => {
const mapRef = useRef();

const handleViewportChange = (view) => {
props.updateMap({...props.map, ...view})
}

const handleGeocoderViewportChange = (viewport) => {
const geocoderDefaultOverrides = { transitionDuration: 2000 };

return handleViewportChange({
  ...viewport,
  ...geocoderDefaultOverrides
});

};

return (


<MapGL
ref={mapRef}
{...props.map}
width="100%"
height="100%"
onViewportChange={handleViewportChange}
mapboxApiAccessToken={mapboxToken}
mapStyle='mapbox://styles/mapbox/streets-v11'
>


    <Geocoder
      mapRef={mapRef}
      containerRef={geocoderContainerRef}
      onViewportChange={handleGeocoderViewportChange}
      mapboxApiAccessToken={mapboxToken}
    />
  </MapGL>
</div>

)
}

@SamSamskies
Copy link
Owner

Hi @carolineleger, any props that are functions or objects need to be memoized to prevent this from happening. In your case you need to memoize your handleGeocoderViewportChange function. For more info check out issue #84.

@carolineleger
Copy link
Author

@SamSamskies Thanks, that helped :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants