Hello.
We have multiple of the same PCF app, on different tabs in the same model driven app form.
Is it possible to get a destroy function when the tab is changed?
Right now we are doing some unsupported calls into Xrm.Page.ui.tabs, to see if the component is on a active tab and then running the code we want to run, when the app is no longer in the current tab
https://www.codepile.net/pile/lBnP92e0
import {useState, useEffect} from "react";
export const useIsTabActive = (tab: any) => {
const [isActive, setIsActive] = useState<boolean>(true);
useEffect(() => {
tab.addTabStateChange(changeEventStatus);
}, []);
const changeEventStatus = (event: any) => {
const tabs: any[] = Object.values((window as any).Xrm.Page.ui.tabs._collection);
const tabIndex = tabs.findIndex(_ => _._controlName == event._eventSource._controlName);
const isAct = (window as any).Xrm.Page.ui.tabs.get(tabIndex).getDisplayState() == "expanded";
setIsActive(isAct);
}
return isActive;
};