ctx.off()
Removes event listeners registered via ctx.on(eventName, handler). It is often used in conjunction with ctx.on to unsubscribe at the appropriate time, preventing memory leaks or duplicate triggers.
Use Cases
Type Definition
Examples
Paired usage in React useEffect
Unsubscribing from resource events
Notes
- Consistent handler reference: The
handlerpassed toctx.offmust be the same reference as the one used inctx.on; otherwise, it cannot be correctly removed. - Timely cleanup: Call
ctx.offbefore the component unmounts or the context is destroyed to avoid memory leaks.
Related Documents
- ctx.on - Subscribe to events
- ctx.resource - Resource instance and its
on/offmethods

