I've run into an issue where I'm unable to get the value I need from inside a callback that's passed to an instantiation of a JavaScript class.
let value;
const mutationObserver = new MutationObserver((mutations) => {
return values.map((mutation) => {
value = mutation.target.childElementCount;
return value;
})
})
console.log("value", value) <= undefined
const element = document.getElementsByClassName('pac-container')[0];
if (element) {
mutationObserver.observe(element, {
childList: true,
subtree: true
});
}
I'm using the MutationObserver because I'd like a way to know, in real-time, how the DOM is being mutated by the results from the googlePlaces API. Since I don't have control over that markup - this seems like the next best thing.
I have explored using the AutoCompleteService - but that would require us to re-implement the existing googlePlaces using the AutoCompleteService call, instead of the AutoComplete API endpoint.
The approach I'm using here is in perfect sync with the results.
I don't think I've run into before - and the difference here is that the value is set inside this instance of a class.
How do you allow the value retrieved inside the class to be defined outside the scope of the function inside the class where it's handled?
We're making the call to the googlePlaces API like this:
const autoComplete = new this.googleApi.places.Autocomplete(
this.props.inputRef,
INIT_OPTIONS
);
An object is returned after the call - and I can see the request being made - and there is new data after each search - but there is no clean JSON response - and the data is embedded in some optimized way deep in the object.