Skip to content

armgit / mapcn

Public Imported from GitHub
0

Beautiful map components. 100% Free, Zero config, one command setup.

TypeScript

Standalone popup fic

Anmoldeep Singhe4182aa47b1e
diff --git a/package-lock.json b/package-lock.json
index 5c059f8..355061c 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -16,7 +16,7 @@
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"lucide-react": "^0.562.0",
- "maplibre-gl": "^4.7.1",
+ "maplibre-gl": "^5.15.0",
"next": "16.1.1",
"next-themes": "^0.4.6",
"react": "19.2.3",
@@ -1633,9 +1633,9 @@
}
},
"node_modules/@mapbox/point-geometry": {
- "version": "0.1.0",
- "resolved": "https://registry.npmjs.org/@mapbox/point-geometry/-/point-geometry-0.1.0.tgz",
- "integrity": "sha512-6j56HdLTwWGO0fJPlrZtdU/B13q8Uwmo18Ck2GnGgN9PCFyKTZ3UbXeEdRFh18i9XQ92eH2VdtpJHpBD3aripQ==",
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/@mapbox/point-geometry/-/point-geometry-1.1.0.tgz",
+ "integrity": "sha512-YGcBz1cg4ATXDCM/71L9xveh4dynfGmcLDqufR+nQQy3fKwsAZsWd/x4621/6uJaeB9mwOHE6hPeDgXz9uViUQ==",
"license": "ISC"
},
"node_modules/@mapbox/tiny-sdf": {
@@ -1651,12 +1651,14 @@
"license": "BSD-2-Clause"
},
"node_modules/@mapbox/vector-tile": {
- "version": "1.3.1",
- "resolved": "https://registry.npmjs.org/@mapbox/vector-tile/-/vector-tile-1.3.1.tgz",
- "integrity": "sha512-MCEddb8u44/xfQ3oD+Srl/tNcQoqTw3goGk2oLsrFxOTc3dUp+kAnby3PvAeeBYSMSjSPD1nd1AJA6W49WnoUw==",
+ "version": "2.0.4",
+ "resolved": "https://registry.npmjs.org/@mapbox/vector-tile/-/vector-tile-2.0.4.tgz",
+ "integrity": "sha512-AkOLcbgGTdXScosBWwmmD7cDlvOjkg/DetGva26pIRiZPdeJYjYKarIlb4uxVzi6bwHO6EWH82eZ5Nuv4T5DUg==",
"license": "BSD-3-Clause",
"dependencies": {
- "@mapbox/point-geometry": "~0.1.0"
+ "@mapbox/point-geometry": "~1.1.0",
+ "@types/geojson": "^7946.0.16",
+ "pbf": "^4.0.1"
}
},
"node_modules/@mapbox/whoots-js": {
@@ -1669,16 +1671,16 @@
}
},
"node_modules/@maplibre/maplibre-gl-style-spec": {
- "version": "20.4.0",
- "resolved": "https://registry.npmjs.org/@maplibre/maplibre-gl-style-spec/-/maplibre-gl-style-spec-20.4.0.tgz",
- "integrity": "sha512-AzBy3095fTFPjDjmWpR2w6HVRAZJ6hQZUCwk5Plz6EyfnfuQW1odeW5i2Ai47Y6TBA2hQnC+azscjBSALpaWgw==",
+ "version": "24.4.1",
+ "resolved": "https://registry.npmjs.org/@maplibre/maplibre-gl-style-spec/-/maplibre-gl-style-spec-24.4.1.tgz",
+ "integrity": "sha512-UKhA4qv1h30XT768ccSv5NjNCX+dgfoq2qlLVmKejspPcSQTYD4SrVucgqegmYcKcmwf06wcNAa/kRd0NHWbUg==",
"license": "ISC",
"dependencies": {
"@mapbox/jsonlint-lines-primitives": "~2.0.2",
"@mapbox/unitbezier": "^0.0.1",
"json-stringify-pretty-compact": "^4.0.0",
"minimist": "^1.2.8",
- "quickselect": "^2.0.0",
+ "quickselect": "^3.0.0",
"rw": "^1.3.3",
"tinyqueue": "^3.0.0"
},
@@ -1688,11 +1690,29 @@
"gl-style-validate": "dist/gl-style-validate.mjs"
}
},
- "node_modules/@maplibre/maplibre-gl-style-spec/node_modules/quickselect": {
- "version": "2.0.0",
- "resolved": "https://registry.npmjs.org/quickselect/-/quickselect-2.0.0.tgz",
- "integrity": "sha512-RKJ22hX8mHe3Y6wH/N3wCM6BWtjaxIyyUIkpHOvfFnxdI4yD4tBXEBKSbriGujF6jnSVkJrffuo6vxACiSSxIw==",
- "license": "ISC"
+ "node_modules/@maplibre/mlt": {
+ "version": "1.1.2",
+ "resolved": "https://registry.npmjs.org/@maplibre/mlt/-/mlt-1.1.2.tgz",
+ "integrity": "sha512-SQKdJ909VGROkA6ovJgtHNs9YXV4YXUPS+VaZ50I2Mt951SLlUm2Cv34x5Xwc1HiFlsd3h2Yrs5cn7xzqBmENw==",
+ "license": "(MIT OR Apache-2.0)",
+ "dependencies": {
+ "@mapbox/point-geometry": "^1.1.0"
+ }
+ },
+ "node_modules/@maplibre/vt-pbf": {
+ "version": "4.2.0",
+ "resolved": "https://registry.npmjs.org/@maplibre/vt-pbf/-/vt-pbf-4.2.0.tgz",
+ "integrity": "sha512-bxrk/kQUwWXZgmqYgwOCnZCMONCRi3MJMqJdza4T3E4AeR5i+VyMnaJ8iDWtWxdfEAJRtrzIOeJtxZSy5mFrFA==",
+ "license": "MIT",
+ "dependencies": {
+ "@mapbox/point-geometry": "^1.1.0",
+ "@mapbox/vector-tile": "^2.0.4",
+ "@types/geojson-vt": "3.2.5",
+ "@types/supercluster": "^7.1.3",
+ "geojson-vt": "^4.0.2",
+ "pbf": "^4.0.1",
+ "supercluster": "^8.0.1"
+ }
},
"node_modules/@modelcontextprotocol/sdk": {
"version": "1.25.1",
@@ -3372,23 +3392,6 @@
"dev": true,
"license": "MIT"
},
- "node_modules/@types/mapbox__point-geometry": {
- "version": "0.1.4",
- "resolved": "https://registry.npmjs.org/@types/mapbox__point-geometry/-/mapbox__point-geometry-0.1.4.tgz",
- "integrity": "sha512-mUWlSxAmYLfwnRBmgYV86tgYmMIICX4kza8YnE/eIlywGe2XoOxlpVnXWwir92xRLjwyarqwpu2EJKD2pk0IUA==",
- "license": "MIT"
- },
- "node_modules/@types/mapbox__vector-tile": {
- "version": "1.3.4",
- "resolved": "https://registry.npmjs.org/@types/mapbox__vector-tile/-/mapbox__vector-tile-1.3.4.tgz",
- "integrity": "sha512-bpd8dRn9pr6xKvuEBQup8pwQfD4VUyqO/2deGjfpe6AwC8YRlyEipvefyRJUSiCJTZuCb8Pl1ciVV5ekqJ96Bg==",
- "license": "MIT",
- "dependencies": {
- "@types/geojson": "*",
- "@types/mapbox__point-geometry": "*",
- "@types/pbf": "*"
- }
- },
"node_modules/@types/mdast": {
"version": "4.0.4",
"resolved": "https://registry.npmjs.org/@types/mdast/-/mdast-4.0.4.tgz",
@@ -3408,12 +3411,6 @@
"undici-types": "~6.21.0"
}
},
- "node_modules/@types/pbf": {
- "version": "3.0.5",
- "resolved": "https://registry.npmjs.org/@types/pbf/-/pbf-3.0.5.tgz",
- "integrity": "sha512-j3pOPiEcWZ34R6a6mN07mUkM4o4Lwf6hPNt8eilOeZhTFbxFXmKhvXl9Y28jotFPaI1bpPDJsbCprUoNke6OrA==",
- "license": "MIT"
- },
"node_modules/@types/react": {
"version": "19.2.7",
"resolved": "https://registry.npmjs.org/@types/react/-/react-19.2.7.tgz",
@@ -6658,44 +6655,6 @@
"node": ">=10.13.0"
}
},
- "node_modules/global-prefix": {
- "version": "4.0.0",
- "resolved": "https://registry.npmjs.org/global-prefix/-/global-prefix-4.0.0.tgz",
- "integrity": "sha512-w0Uf9Y9/nyHinEk5vMJKRie+wa4kR5hmDbEhGGds/kG1PwGLLHKRoNMeJOyCQjjBkANlnScqgzcFwGHgmgLkVA==",
- "license": "MIT",
- "dependencies": {
- "ini": "^4.1.3",
- "kind-of": "^6.0.3",
- "which": "^4.0.0"
- },
- "engines": {
- "node": ">=16"
- }
- },
- "node_modules/global-prefix/node_modules/isexe": {
- "version": "3.1.1",
- "resolved": "https://registry.npmjs.org/isexe/-/isexe-3.1.1.tgz",
- "integrity": "sha512-LpB/54B+/2J5hqQ7imZHfdU31OlgQqx7ZicVlkm9kzg9/w8GKLEcFfJl/t7DCEDueOyBAD6zCCwTO6Fzs0NoEQ==",
- "license": "ISC",
- "engines": {
- "node": ">=16"
- }
- },
- "node_modules/global-prefix/node_modules/which": {
- "version": "4.0.0",
- "resolved": "https://registry.npmjs.org/which/-/which-4.0.0.tgz",
- "integrity": "sha512-GlaYyEb07DPxYCKhKzplCWBJtvxZcZMrL+4UkrTSJHHPyZU4mYYTv3qaOe77H7EODLSSopAUFAc6W8U4yqvscg==",
- "license": "ISC",
- "dependencies": {
- "isexe": "^3.1.1"
- },
- "bin": {
- "node-which": "bin/which.js"
- },
- "engines": {
- "node": "^16.13.0 || >=18.0.0"
- }
- },
"node_modules/globals": {
"version": "14.0.0",
"resolved": "https://registry.npmjs.org/globals/-/globals-14.0.0.tgz",
@@ -6993,26 +6952,6 @@
"url": "https://opencollective.com/express"
}
},
- "node_modules/ieee754": {
- "version": "1.2.1",
- "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
- "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==",
- "funding": [
- {
- "type": "github",
- "url": "https://github.com/sponsors/feross"
- },
- {
- "type": "patreon",
- "url": "https://www.patreon.com/feross"
- },
- {
- "type": "consulting",
- "url": "https://feross.org/support"
- }
- ],
- "license": "BSD-3-Clause"
- },
"node_modules/ignore": {
"version": "5.3.2",
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz",
@@ -7057,15 +6996,6 @@
"dev": true,
"license": "ISC"
},
- "node_modules/ini": {
- "version": "4.1.3",
- "resolved": "https://registry.npmjs.org/ini/-/ini-4.1.3.tgz",
- "integrity": "sha512-X7rqawQBvfdjS10YU1y1YVreA3SsLrW9dX2CewP2EbBJM4ypVNLDkO5y04gejPwKIY9lR+7r9gn3rFPt/kmWFg==",
- "license": "ISC",
- "engines": {
- "node": "^14.17.0 || ^16.13.0 || >=18.0.0"
- }
- },
"node_modules/internal-slot": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.1.0.tgz",
@@ -7863,15 +7793,6 @@
"json-buffer": "3.0.1"
}
},
- "node_modules/kind-of": {
- "version": "6.0.3",
- "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz",
- "integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==",
- "license": "MIT",
- "engines": {
- "node": ">=0.10.0"
- }
- },
"node_modules/kleur": {
"version": "4.1.5",
"resolved": "https://registry.npmjs.org/kleur/-/kleur-4.1.5.tgz",
@@ -8293,37 +8214,34 @@
}
},
"node_modules/maplibre-gl": {
- "version": "4.7.1",
- "resolved": "https://registry.npmjs.org/maplibre-gl/-/maplibre-gl-4.7.1.tgz",
- "integrity": "sha512-lgL7XpIwsgICiL82ITplfS7IGwrB1OJIw/pCvprDp2dhmSSEBgmPzYRvwYYYvJGJD7fxUv1Tvpih4nZ6VrLuaA==",
+ "version": "5.15.0",
+ "resolved": "https://registry.npmjs.org/maplibre-gl/-/maplibre-gl-5.15.0.tgz",
+ "integrity": "sha512-pPeu/t4yPDX/+Uf9ibLUdmaKbNMlGxMAX+tBednYukol2qNk2TZXAlhdohWxjVvTO3is8crrUYv3Ok02oAaKzA==",
"license": "BSD-3-Clause",
"dependencies": {
"@mapbox/geojson-rewind": "^0.5.2",
"@mapbox/jsonlint-lines-primitives": "^2.0.2",
- "@mapbox/point-geometry": "^0.1.0",
- "@mapbox/tiny-sdf": "^2.0.6",
+ "@mapbox/point-geometry": "^1.1.0",
+ "@mapbox/tiny-sdf": "^2.0.7",
"@mapbox/unitbezier": "^0.0.1",
- "@mapbox/vector-tile": "^1.3.1",
+ "@mapbox/vector-tile": "^2.0.4",
"@mapbox/whoots-js": "^3.1.0",
- "@maplibre/maplibre-gl-style-spec": "^20.3.1",
- "@types/geojson": "^7946.0.14",
+ "@maplibre/maplibre-gl-style-spec": "^24.4.1",
+ "@maplibre/mlt": "^1.1.2",
+ "@maplibre/vt-pbf": "^4.2.0",
+ "@types/geojson": "^7946.0.16",
"@types/geojson-vt": "3.2.5",
- "@types/mapbox__point-geometry": "^0.1.4",
- "@types/mapbox__vector-tile": "^1.3.4",
- "@types/pbf": "^3.0.5",
"@types/supercluster": "^7.1.3",
- "earcut": "^3.0.0",
+ "earcut": "^3.0.2",
"geojson-vt": "^4.0.2",
- "gl-matrix": "^3.4.3",
- "global-prefix": "^4.0.0",
+ "gl-matrix": "^3.4.4",
"kdbush": "^4.0.2",
"murmurhash-js": "^1.0.0",
- "pbf": "^3.3.0",
- "potpack": "^2.0.0",
+ "pbf": "^4.0.1",
+ "potpack": "^2.1.0",
"quickselect": "^3.0.0",
"supercluster": "^8.0.1",
- "tinyqueue": "^3.0.0",
- "vt-pbf": "^3.1.3"
+ "tinyqueue": "^3.0.0"
},
"engines": {
"node": ">=16.14.0",
@@ -9331,12 +9249,11 @@
"license": "MIT"
},
"node_modules/pbf": {
- "version": "3.3.0",
- "resolved": "https://registry.npmjs.org/pbf/-/pbf-3.3.0.tgz",
- "integrity": "sha512-XDF38WCH3z5OV/OVa8GKUNtLAyneuzbCisx7QUCF8Q6Nutx0WnJrQe5O+kOtBlLfRNUws98Y58Lblp+NJG5T4Q==",
+ "version": "4.0.1",
+ "resolved": "https://registry.npmjs.org/pbf/-/pbf-4.0.1.tgz",
+ "integrity": "sha512-SuLdBvS42z33m8ejRbInMapQe8n0D3vN/Xd5fmWM3tufNgRQFBpaW2YVJxQZV4iPNqb0vEFvssMEo5w9c6BTIA==",
"license": "BSD-3-Clause",
"dependencies": {
- "ieee754": "^1.1.12",
"resolve-protobuf-schema": "^2.1.0"
},
"bin": {
@@ -11534,17 +11451,6 @@
"url": "https://opencollective.com/unified"
}
},
- "node_modules/vt-pbf": {
- "version": "3.1.3",
- "resolved": "https://registry.npmjs.org/vt-pbf/-/vt-pbf-3.1.3.tgz",
- "integrity": "sha512-2LzDFzt0mZKZ9IpVF2r69G9bXaP2Q2sArJCmcCgvfTdCCZzSyz4aCLoQyUilu37Ll56tCblIZrXFIjNUpGIlmA==",
- "license": "MIT",
- "dependencies": {
- "@mapbox/point-geometry": "0.1.0",
- "@mapbox/vector-tile": "^1.3.1",
- "pbf": "^3.2.1"
- }
- },
"node_modules/web-streams-polyfill": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz",
diff --git a/package.json b/package.json
index 03b7c93..cf5c1d7 100644
--- a/package.json
+++ b/package.json
@@ -18,7 +18,7 @@
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"lucide-react": "^0.562.0",
- "maplibre-gl": "^4.7.1",
+ "maplibre-gl": "^5.15.0",
"next": "16.1.1",
"next-themes": "^0.4.6",
"react": "19.2.3",
diff --git a/src/app/docs/_components/examples/standalone-popup-example.tsx b/src/app/docs/_components/examples/standalone-popup-example.tsx
index 974c842..b00d886 100644
--- a/src/app/docs/_components/examples/standalone-popup-example.tsx
+++ b/src/app/docs/_components/examples/standalone-popup-example.tsx
@@ -10,30 +10,31 @@ export function StandalonePopupExample() {
return (
<div className="h-[400px] w-full relative">
<Map center={[-74.006, 40.7128]} zoom={13}>
- <MapPopup
- longitude={-74.006}
- latitude={40.7128}
- open={showPopup}
- onClose={() => setShowPopup(false)}
- closeButton
- focusAfterOpen={false}
- closeOnClick={false}
- >
- <div className="space-y-2">
- <h3 className="font-semibold text-foreground">New York City</h3>
- <p className="text-sm text-muted-foreground">
- The city that never sleeps. Population: 8.3 million
- </p>
- <Button
- size="sm"
- variant="outline"
- className="w-full"
- onClick={() => setShowPopup(false)}
- >
- Close
- </Button>
- </div>
- </MapPopup>
+ {showPopup && (
+ <MapPopup
+ longitude={-74.006}
+ latitude={40.7128}
+ onClose={() => setShowPopup(false)}
+ closeButton
+ focusAfterOpen={false}
+ closeOnClick={false}
+ >
+ <div className="space-y-2">
+ <h3 className="font-semibold text-foreground">New York City</h3>
+ <p className="text-sm text-muted-foreground">
+ The city that never sleeps. Population: 8.3 million
+ </p>
+ <Button
+ size="sm"
+ variant="outline"
+ className="w-full"
+ onClick={() => setShowPopup(false)}
+ >
+ Close
+ </Button>
+ </div>
+ </MapPopup>
+ )}
</Map>
{!showPopup && (
diff --git a/src/app/docs/api-reference/page.tsx b/src/app/docs/api-reference/page.tsx
index 6c8c600..1133a2f 100644
--- a/src/app/docs/api-reference/page.tsx
+++ b/src/app/docs/api-reference/page.tsx
@@ -406,12 +406,6 @@ export default function ApiReferencePage() {
type: "number",
description: "Latitude coordinate for popup position.",
},
- {
- name: "open",
- type: "boolean",
- default: "true",
- description: "Controls popup visibility.",
- },
{
name: "onClose",
type: "() => void",
@@ -430,7 +424,7 @@ export default function ApiReferencePage() {
{
name: "closeButton",
type: "boolean",
- default: "true",
+ default: "false",
description: "Show a close button in the popup.",
},
]}
diff --git a/src/components/theme-toggle.tsx b/src/components/theme-toggle.tsx
index 800d03c..fdd669c 100644
--- a/src/components/theme-toggle.tsx
+++ b/src/components/theme-toggle.tsx
@@ -36,7 +36,7 @@ export function ThemeToggle() {
onClick={() => setTheme(resolvedTheme === "dark" ? "light" : "dark")}
variant="ghost"
aria-label="Toggle theme"
- size="icon"
+ size="icon-sm"
>
<ThemeIcon className="size-4" />
</Button>
diff --git a/src/registry/map.tsx b/src/registry/map.tsx
index 165dcf5..a9f77f9 100644
--- a/src/registry/map.tsx
+++ b/src/registry/map.tsx
@@ -62,6 +62,7 @@ const DefaultLoader = () => (
function Map({ children, styles, ...props }: MapProps) {
const containerRef = useRef<HTMLDivElement>(null);
const mapRef = useRef<MapLibreGL.Map | null>(null);
+ const [isMounted, setIsMounted] = useState(false);
const [isLoaded, setIsLoaded] = useState(false);
const [isStyleLoaded, setIsStyleLoaded] = useState(false);
const { resolvedTheme } = useTheme();
@@ -75,7 +76,11 @@ function Map({ children, styles, ...props }: MapProps) {
);
useEffect(() => {
- if (!containerRef.current) return;
+ setIsMounted(true);
+ }, []);
+
+ useEffect(() => {
+ if (!isMounted || !containerRef.current) return;
const mapStyle =
resolvedTheme === "dark" ? mapStyles.dark : mapStyles.light;
@@ -100,7 +105,7 @@ function Map({ children, styles, ...props }: MapProps) {
mapInstance.remove();
mapRef.current = null;
};
- }, []);
+ }, [isMounted]);
useEffect(() => {
if (mapRef.current) {
@@ -112,15 +117,19 @@ function Map({ children, styles, ...props }: MapProps) {
}
}, [resolvedTheme]);
- const isLoading = !isLoaded || !isStyleLoaded;
+ const isLoading = !isMounted || !isLoaded || !isStyleLoaded;
return (
<MapContext.Provider
- value={{ map: mapRef.current, isLoaded: isLoaded && isStyleLoaded }}
+ value={{
+ map: mapRef.current,
+ isLoaded: isMounted && isLoaded && isStyleLoaded,
+ }}
>
<div ref={containerRef} className="relative w-full h-full">
{isLoading && <DefaultLoader />}
- {children}
+ {/* guard against hydration error */}
+ {isMounted && children}
</div>
</MapContext.Provider>
);
@@ -651,7 +660,6 @@ function CompassButton({ onClick }: { onClick?: () => void }) {
type MapPopupProps = {
longitude: number;
latitude: number;
- open?: boolean;
onClose?: () => void;
children: ReactNode;
className?: string;
@@ -661,23 +669,19 @@ type MapPopupProps = {
function MapPopup({
longitude,
latitude,
- open = true,
onClose,
children,
className,
- closeButton = true,
+ closeButton = false,
...popupOptions
}: MapPopupProps) {
- const { map, isLoaded } = useMap();
- const containerRef = useRef<HTMLDivElement | null>(null);
+ const { map } = useMap();
const popupRef = useRef<MapLibreGL.Popup | null>(null);
- const [mounted, setMounted] = useState(false);
- useEffect(() => {
- if (!isLoaded || !map) return;
+ const container = useMemo(() => document.createElement("div"), []);
- const container = document.createElement("div");
- containerRef.current = container;
+ useEffect(() => {
+ if (!map) return;
const popup = new MapLibreGL.Popup({
offset: 12,
@@ -686,30 +690,23 @@ function MapPopup({
})
.setMaxWidth("none")
.setDOMContent(container)
- .setLngLat([longitude, latitude]);
+ .setLngLat([longitude, latitude])
+ .addTo(map);
- popup.on("close", () => onClose?.());
+ const onCloseProp = () => onClose?.();
+
+ popup.on("close", onCloseProp);
popupRef.current = popup;
- setMounted(true);
return () => {
- popup.remove();
+ popup.off("close", onCloseProp);
+ if (popup.isOpen()) {
+ popup.remove();
+ }
popupRef.current = null;
- containerRef.current = null;
- setMounted(false);
};
- }, [isLoaded, map]);
-
- useEffect(() => {
- if (!popupRef.current || !map) return;
-
- if (open) {
- popupRef.current.addTo(map);
- } else {
- popupRef.current.remove();
- }
- }, [open, map, mounted]);
+ }, [map]);
useEffect(() => {
popupRef.current?.setLngLat([longitude, latitude]);
@@ -720,8 +717,6 @@ function MapPopup({
onClose?.();
};
- if (!mounted || !containerRef.current) return null;
-
return createPortal(
<div
className={cn(
@@ -742,7 +737,7 @@ function MapPopup({
)}
{children}
</div>,
- containerRef.current
+ container
);
}