Skip to main content

detach

Removes a handler or interceptor that was registered with api.on or api.intercept using a tag. Call this to clean up event subscriptions when they're no longer needed.

Usage

detach(tag: number | string | symbol): void;
ParameterTypeDescription
tagnumber | string | symbolThe tag assigned when registering the handler via the config parameter of on or intercept

Example

Register a handler with a tag, then remove it later:

import { Kanban } from "@svar-ui/react-kanban";

function App() {
const api = useRef(null);

function attach(a) {
api.current = a;
api.current.on("update-card", (ev) => {
console.log("card updated", ev.id);
}, { tag: "logger" });
}

function cleanup() {
api.current.detach("logger");
}

return (
<>
<Kanban cards={cards} columns={columns} init={attach} />
<button onClick={cleanup}>Remove logger</button>
</>
);
}
  • on - register a handler with a tag for later detaching
  • intercept - register an interceptor with a tag