UNPKG

react-naver-maps

Version:

React Navermaps API integration for modern development.

1 lines 1.39 kB
{"version":3,"sources":["../src/overlay.tsx"],"sourcesContent":["import { useEffect } from 'react';\nimport type { ReactNode } from 'react';\n\nimport { EventTargetContext } from './contexts/event-target';\nimport { useMap } from './contexts/naver-map';\n\ntype MapElementType = {\n setMap(map: naver.maps.Map | null): void;\n getMap(): naver.maps.Map | null;\n};\n\nexport type Props = {\n element: MapElementType;\n children?: ReactNode;\n autoMount?: boolean;\n};\n\nexport function Overlay(props: Props) {\n const { element, children, autoMount = true } = props;\n const nmap = useMap();\n\n useEffect(() => {\n if (!autoMount) {\n return;\n }\n\n if (element.getMap() === nmap) {\n return;\n }\n\n element.setMap(nmap ? nmap : null);\n return () => {\n element.setMap(null);\n };\n }, [nmap]);\n\n return (\n <EventTargetContext.Provider value={element}>\n {children}\n </EventTargetContext.Provider>\n );\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,iBAAiB;AAqCtB;AApBG,SAAS,QAAQ,OAAc;AACpC,QAAM,EAAE,SAAS,UAAU,YAAY,KAAK,IAAI;AAChD,QAAM,OAAO,OAAO;AAEpB,YAAU,MAAM;AACd,QAAI,CAAC,WAAW;AACd;AAAA,IACF;AAEA,QAAI,QAAQ,OAAO,MAAM,MAAM;AAC7B;AAAA,IACF;AAEA,YAAQ,OAAO,OAAO,OAAO,IAAI;AACjC,WAAO,MAAM;AACX,cAAQ,OAAO,IAAI;AAAA,IACrB;AAAA,EACF,GAAG,CAAC,IAAI,CAAC;AAET,SACE,oBAAC,mBAAmB,UAAnB;AAAA,IAA4B,OAAO;AAAA,IACjC;AAAA,GACH;AAEJ;","names":[]}