docs/docs/en/runjs/context/off.md
Removes a listener registered with ctx.on(eventName, handler). Use with ctx.on and unsubscribe when appropriate to avoid leaks or duplicate triggers.
| Scenario | Description |
|---|---|
| React useEffect cleanup | Call in useEffect cleanup; remove on unmount |
| JSField / JSEditableField | Unsubscribe from js-field:value-change when doing two-way binding |
| resource | Unsubscribe from ctx.resource.on (refresh, saved, etc.) |
off(eventName: string, handler: (event?: any) => void): void;
React.useEffect(() => {
const handler = (ev) => setValue(ev?.detail ?? '');
ctx.on('js-field:value-change', handler);
return () => ctx.off('js-field:value-change', handler);
}, []);
const handler = () => { /* ... */ };
ctx.resource?.on('refresh', handler);
// Later
ctx.resource?.off('refresh', handler);
handler passed to ctx.off must be the same reference as in ctx.on, or it will not be removed.ctx.off before unmount or context destroy to avoid leaks.on/off