Skip to content

Define custom element

In LynJS, custom elements are defined by extending LynElement.

Once defined, the class is registered with the browser’s Custom Elements Registry and works as a standard Web Component.

This approach keeps components standard-compliant and makes them easily reusable across different projects.

import { LynElement } from '@lynjs/core';
export class MyElement extends LynElement {
render() {
const el = document.createElement('p');
el.innerText = 'Hello from MyElement!';
return el;
}
}
customElements.define('my-element', MyElement);
  • LynElement is the base class that provides lifecycle, rendering, and fine-grained reactivity features.
  • customElements.define registers the class as a custom element in the browser.