UNPKG

react-naver-maps

Version:

React Navermaps API integration for modern development.

52 lines (50 loc) 1.62 kB
import { loadScript } from "./chunk-F6WKUPXL.mjs"; // src/load-navermaps-script.tsx import { useEffect, useState } from "react"; import { jsx } from "react/jsx-runtime"; function loadNavermapsScript(options) { const url = makeUrl(options); const promise = loadScript(url).then(() => { const navermaps = window.naver.maps; if (navermaps.jsContentLoaded) { return navermaps; } return new Promise((resolve) => { navermaps.onJSContentLoaded = () => { resolve(navermaps); }; }); }); return promise; } function makeUrl(options) { const submodules = options.submodules; const clientIdQuery = "ncpKeyId" in options ? `ncpKeyId=${options.ncpKeyId}` : "ncpClientId" in options ? `ncpClientId=${options.ncpClientId}` : "govClientId" in options ? `govClientId=${options.govClientId}` : "finClientId" in options ? `finClientId=${options.finClientId}` : void 0; if (!clientIdQuery) { throw new Error("react-naver-maps: ncpKeyId, ncpClientId, govClientId or finClientId is required"); } let url = `https://oapi.map.naver.com/openapi/v3/maps.js?${clientIdQuery}`; if (submodules) { url += `&submodules=${submodules.join(",")}`; } return url; } function LoadNavermapsScript({ children: Children, ...options }) { const [navermaps, setNavermaps] = useState(); useEffect(() => { loadNavermapsScript(options).then((maps) => { setNavermaps(maps); }); }, []); return navermaps && Children ? /* @__PURE__ */ jsx(Children, {}) : null; } export { loadNavermapsScript, LoadNavermapsScript }; //# sourceMappingURL=chunk-RJK7NYEL.mjs.map