From 34fb6ee40637c5497fa77c161187bccd990698a0 Mon Sep 17 00:00:00 2001 From: Sashank Aryal Date: Thu, 31 Oct 2024 16:25:55 +0545 Subject: [PATCH] release tooltip event listener adding func --- .../components/Modal/ModalSamplePlugin.tsx | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/app/packages/core/src/components/Modal/ModalSamplePlugin.tsx b/app/packages/core/src/components/Modal/ModalSamplePlugin.tsx index 249285433f..44e06ec6ea 100644 --- a/app/packages/core/src/components/Modal/ModalSamplePlugin.tsx +++ b/app/packages/core/src/components/Modal/ModalSamplePlugin.tsx @@ -1,6 +1,6 @@ import { ErrorBoundary } from "@fiftyone/components"; import * as fos from "@fiftyone/state"; -import React, { Suspense, useEffect } from "react"; +import React, { Suspense, useCallback, useEffect, useMemo } from "react"; import { useRecoilCallback, useRecoilValue, useSetRecoilState } from "recoil"; import styled from "styled-components"; import Group from "./Group"; @@ -48,18 +48,30 @@ export const ModalSample = React.memo(() => { const { activeLookerRef, onLookerSetSubscribers } = useModalContext(); - useEffect(() => { - onLookerSetSubscribers.current.push((looker) => { + const addTooltipEventListener = useMemo(() => { + return (looker: fos.Lookers) => { looker.addEventListener("tooltip", tooltipEventHandler); - }); + }; + }, []); + + useEffect(() => { + onLookerSetSubscribers.current.push(addTooltipEventListener); return () => { activeLookerRef?.current?.removeEventListener( "tooltip", tooltipEventHandler ); + onLookerSetSubscribers.current = onLookerSetSubscribers.current.filter( + (fn) => fn !== addTooltipEventListener + ); }; - }, [activeLookerRef, onLookerSetSubscribers, tooltipEventHandler]); + }, [ + activeLookerRef, + addTooltipEventListener, + onLookerSetSubscribers, + tooltipEventHandler, + ]); useEffect(() => { // reset tooltip state when modal is closed