Skip to main content

detach

Removes a handler or interceptor that was registered through on or intercept. Used for cleanup, typically on component teardown.

Usage

detach(tag: number | string | symbol): void;
ArgumentTypeDescription
tagnumber | string | symbolTag returned (or supplied) when the handler was registered.

Example

import { useState, useEffect } from "react";
import { Calendar } from "@wx/react-calendar";
import type { CalendarInstanceApi } from "@wx/react-calendar";

const [api, setApi] = useState<CalendarInstanceApi>();
const tag = Symbol("delete-guard");

function init(a: CalendarInstanceApi) {
setApi(a);
a.intercept(
"delete-event",
p => confirm(`Delete event ${p.id}?`),
{ tag }
);
}

useEffect(() => () => api?.detach(tag), [api]);

<Calendar events={events} init={init} />
  • on — register a handler under a tag.
  • intercept — register an interceptor under a tag.
  • init — capture the api so you can call detach later.