Wocart

@wocart/theme v4.1.0


@wocart/theme / lifecycle / bindEach

Function: bindEach()

bindEach<T>(selector, bind, options?): () => void

Runs bind once on every element selector matches: when the page is ready, after Astro's router swaps a page in, and after an editor's preview swaps a section in. A bind may return a teardown, run when its element leaves — before Astro swaps the page out, or when a later pass finds the element gone. Returns a function that stops it and runs every teardown.

TypeScriptCode
bindEach<HTMLFormElement>("[data-order-form]", (form) => { const onResize = () => layout(form); window.addEventListener("resize", onResize); return () => window.removeEventListener("resize", onResize); });

Type Parameters

T

T extends Element = HTMLElement

Parameters

selector

string

bind

(element) => Teardown

options?

LifecycleOptions

Returns

() => void