UNPKG

@uiw/react-baidu-map-copyright-control

Version:

Baidu Map copyright-control Components for React.

38 lines 855 B
import React from 'react'; import { useEffect, useState } from 'react'; import { usePrevious, usePortal } from '@uiw/react-baidu-map-utils'; import { jsx as _jsx } from "react/jsx-runtime"; var uid = 1; export function CopyrightControlItem(props) { if (props === void 0) { props = {}; } var { children, control, bounds } = props; var [id] = useState(uid++); var { container, Portal } = usePortal(); var prevId = usePrevious(id); useEffect(() => { if (control) { control.addCopyright({ id, bounds, content: container.innerHTML }); } return function () { if (prevId && control) { control.removeCopyright(prevId); } }; }, [bounds, children, container, control, id, prevId]); return /*#__PURE__*/_jsx(Portal, { children: children }); }