Use
The use
directive is Nørd most direct access to the DOM, and is useful to apply arbitrary behaviour to DOM elements without creating custom directive.
Type: use(handler: (element: Element) => void): Directive<Element>
INFO
use
is a pure Element
directive.
Using use
To use the use
directive, include in a template.
ts
import { createComponent, use } from '@grainular/nord';
// Use the `use` directive to log the element.
const component = createComponent((html) => {
return html`<div ${use((e) => console.log({ e }))}></div>`;
});
The directive will log the Node
to the console when the template is evaluated.
⚡️
Code insights: You can see the function signature & implementation here: use.ts