web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : RoVFH/KXL8s2dCKGjHwdnZ
Power Apps - Power Apps Pro Dev & ISV
Answered

destroy function on tab change

Like (0) ShareShare
ReportReport
Posted on 22 Feb 2022 16:04:48 by 87

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;
};

 

 

  • Kristoffer88 Profile Picture
    87 on 25 Feb 2022 at 23:17:58
    Re: destroy function on tab change

    Thanks! Just what i was looking for.

  • Verified answer
    skoofy5 Profile Picture
    480 on 25 Feb 2022 at 04:57:29
    Re: destroy function on tab change

    I've checked if my PCF is on an active tab by checking my container width. I've set 'trackContainerResize' to true in the index and then looked for an allocated width of greater than 0. If it's 0 then your PCF is not on an active tab.

     

     

    context.mode.trackContainerResize(true);
    context.mode.allocatedWidth > 0

     

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410 Super User 2025 Season 2

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 2

Loading complete