react-map-gl-geocoder icon indicating copy to clipboard operation
react-map-gl-geocoder copied to clipboard

How to get the current value?

Open gilmelamed opened this issue 3 years ago • 3 comments

Is there any way to keep the current value of Geocoder on the state? For example, creating a hook like setSearchQuery(Geocoder.input.current.value) ?

This is my Geocoder:

           <Geocoder
              mapRef={mapRef}
              containerRef={geocoderContainerRef}
              mapboxApiAccessToken={token}
              onViewportChange={handleGeocoderViewportChange}
              placeholder=""
              position="top-left"
              minLength={4}
              limit={3}
              trackProximity
              marker={false}
              enableEventLogging={false}
            />

Thanks!

gilmelamed avatar Nov 07 '21 22:11 gilmelamed

Hey @gmsy, you can use the onResult prop and cache the value of each query result. If you want to cache the value as the user is typing, you can use the onLoading prop. You'll probably actually need to use both.

SamSamskies avatar Nov 07 '21 23:11 SamSamskies

Thanks for your reply, @SamSamskies . Do you think there is also a way maybe to change styling for the Geocoder input only when the Geocoder input is focused?

gilmelamed avatar Nov 07 '21 23:11 gilmelamed

You'll have to hack it by importing styles with higher specificity for the styles that you want to override.

SamSamskies avatar Nov 07 '21 23:11 SamSamskies