0

I need the ability to perform file cleanup when a client-side web part is deleted from the page. How can I listen for the delete event?

4

You should override the Dispose() method on BaseClientSideWebPart. Make sure you call the base implementation as well.

protected dispose(): void
{
  // Do something interesting
  Log.warn("HelloWorld", "Cleaning up my stuff", this.context.serviceScope);

  // call the base class.
  super.dispose();
}

Note however, there there is a currently a bug where this code doesn't necessarily get called. That will be fixed.

  • Thanks, Pat. I'm still wrapping my head around Typescript so what you're saying makes sense in theory but could you provide sample code that demonstrates how to write this? – Jared Buttars Sep 23 '16 at 21:03
  • Thank you, I logged on here to report the bug you mentioned and found your code sample as well. Looking forward to the fix! – Jared Buttars Sep 29 '16 at 17:06
  • 1
    This now works using Drop 5 of SPFx. – Jared Buttars Oct 18 '16 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.