Skip to content

Multiple instances of usePlacesAutocompleteService on same Page / Component gives error #236

Open
@malikk908

Description

@malikk908

I have an AddressSuggestion.js component which uses usePlacesAutocompleteService like this

import usePlacesService from "react-google-autocomplete/lib/usePlacesAutocompleteService";

const {
        placePredictions,
        getPlacePredictions,
        isPlacePredictionsLoading,
    } = usePlacesService({
        apiKey: process.env.REACT_APP_MAPS_API_KEY ?
            `${process.env.REACT_APP_MAPS_API_KEY}&loading=async` :
            "keyUnavailable",
        debounce: 500
    });

the problem is if I am trying to use the same component two times on a single page (single parent component), then I am getting this Uncaught runtime error:

usePlacesAutocompleteService.js:110 Uncaught (in promise) 
TypeError: Cannot read properties of undefined (reading 'AutocompleteService')
    at buildService (usePlacesAutocompleteService.js:110:1)
    at usePlacesAutocompleteService.js:118:1

although the component seems to work fine (in development though, haven't checked in production)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions