Thunderous
Building web components has never been easier.
Thunderous is a functional-style web component authoring library, supercharged with signals!
Thunderous is a functional-style web component authoring library, supercharged with signals!
import { customElement, html, css, createSignal } from 'thunderous';
const MyElement = customElement(({ adoptStyleSheet }) => {
const [count, setCount] = createSignal(0);
const increment = () => setCount(count() + 1);
adoptStyleSheet(myStyleSheet);
return html`
<button onclick="${increment}">Increment</button>
<output>${count}</output>
`;
});
const myStyleSheet = css`
:host {
display: block;
font-family: sans-serif;
}
`;
MyElement.define('my-element');
import { customElement, html, createSignal } from 'thunderous';
// Thunderous functional component:
const FnElement = customElement(() => {
const [count, setCount] = createSignal(0);
const increment = () => setCount(count() + 1);
return html`
<button onclick="${increment}">Increment</button>
<output>${count}</output>
`;
});
// Traditional class component with Thunderous helpers:
class ClssElement extends HTMLElement {
#shadowRoot = this.attachShadow({ mode: 'closed' });
#count = createSignal(0);
increment() {
const [count, setCount] = this.#count;
setCount(count() + 1);
}
constructor() {
super();
const [count] = this.#count;
this.#shadowRoot.append(html`
<button onclick="${this.increment}">Increment</button>
<output>${count}</output>
`);
}
}
onServerDefine() insertTemplates()