---
page_source: https://docs.juspay.io/clicktopay/docs/how-to-integrate/managing-component-lifecycle
page_title: Managing Component Lifecycle
---


# **Managing Component Lifecycle in ClickToPayWidget** 




### **What is** cleanupMountedApp function?



The cleanupMountedApp function is a crucial utility for managing component lifecycle and preventing memory leaks in the ClickToPayWidget implementation.


#### javascript Code Snippet:

```javascript
const cleanupComponent = (elem: HTMLElement) => {
// Framework-specific cleanup logic
// Example: React.unmountComponentAtNode(elem)
// Example: Vue app.unmount()
// Example: Angular - destroy component
}
```



#### **Purpose** 



* Ensures proper cleanup of mounted components
* Prevents memory leaks during re-renders
* Manages component lifecycle across render function calls