0

I'm wondering how I can access the actual value in a <StandaloneSearchBox ..> component after the user selected it from the autocomplete dropdown menu. I basically want to make it a controlled component.

I tried getPlaces() but that does not give me the actual value visible on the page but rather a bunch of structured data. enter image description here

Take the example from the official docs (https://react-google-maps-api-docs.netlify.app/#standalonesearchbox), I basically want to do something like:



...
const [inputFieldValue, setInputFieldValue] = useState ("")



const onPlacesChanged = () => {
...
const value = ... // 1. access value
setInputFieldValue (value) // 2. store in state

}

...

<input
        type="text"
        placeholder="Customized your placeholder"
        style={{...}}
         value= {inputFieldValue}
      />
...

yumba
  • 1,056
  • 2
  • 16
  • 31

1 Answers1

0

I can suggest getting the value of the input box:

const onPlaceChange = e =>{
        console.log(e?.target?.value)
    }
    
        ...
    
    <input
        ...
        onBlur={onPlaceChange}
        ...
          />
    ...