diff --git a/src/components/popup.js b/src/components/popup.js index b36366b8..18ac497a 100644 --- a/src/components/popup.js +++ b/src/components/popup.js @@ -18,7 +18,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. import * as React from 'react'; -import {useRef, useState, useEffect} from 'react'; +import {useRef, useState, useEffect, useCallback} from 'react'; import * as PropTypes from 'prop-types'; import useMapControl, {mapControlDefaultProps, mapControlPropTypes} from './use-map-control'; @@ -146,7 +146,8 @@ function onClick(evt, {props, context}) { */ function Popup(props) { const contentRef = useRef(null); - const {context, containerRef} = useMapControl({...props, onClick}); + const thisRef = useMapControl({...props, onClick}); + const {context, containerRef} = thisRef; const [, setLoaded] = useState(false); useEffect(() => { @@ -169,7 +170,9 @@ function Popup(props) { ); // If eventManager does not exist (using with static map), listen to React event - const onReactClick = context.eventManager ? null : onClick; + const onReactClick = useCallback(e => !context.eventManager && onClick(e, thisRef), [ + context.eventManager + ]); return (