import { action, component, defineApp, html, page, state } from 'redweb'; @component() export class CounterComponent { @state() count = 0; constructor(private readonly label: string) {} @action() increment() { this.count += 1; } render() { return html`

${this.label}

${this.count}
`; } } @page('/', { css: 'components.css' }) export class ComponentsPage { primary = new CounterComponent('Primary counter'); secondary = new CounterComponent('Independent counter'); render() { return html`

Reusable server components

${this.primary}${this.secondary}
`; } } if (require.main === module) void defineApp({ pages: [ComponentsPage], port: 8080 }).run() .catch(error => { console.error(error); process.exitCode = 1; });