Skip to content

Invariant Violation: You need to provide libraries={["places"]} prop to <LoadScript /> component undefined #3418

@karan-wiz

Description

@karan-wiz

"use client";
import React, { useState, useCallback, useEffect, useRef } from "react";
import {
GoogleMap,
useLoadScript,
Marker,
Autocomplete,
} from "@react-google-maps/api";

const LIBRARIES = ["places"];

const isMobile =
typeof window !== "undefined" &&
window.innerWidth > 250 &&
window.innerWidth < 600;

const mapContainerStyle = {
width: isMobile ? "100%" : "50%", // 640px corresponds to 'sm' size in Tailwind
height: "400px",
};

const defaultCenter = {
lat: 40.712776,
lng: -74.005974,
};

const GoogleMapComponent = ({
paddress,
setPaddress,
latlong,
setLatlong,
serachError,
onLocationSearch,
}) => {
const { isLoaded, loadError } = useLoadScript({
googleMapsApiKey: process.env.NEXT_PUBLIC_MAPS_KEY,
libraries: LIBRARIES,
});

const [marker, setMarker] = useState(null);
const [localAddress, setLocalAddress] = useState(paddress || "");

useEffect(() => {
if (latlong.latitude && latlong.longitude) {
setMarker({
lat: Number(latlong.latitude),
lng: Number(latlong.longitude),
});
}
}, [latlong]);

const [autocomplete, setAutocomplete] = useState(null);
const mapRef = useRef();

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