@gluonjs/ssr / packages/ssr/src / renderElement
Function: renderElement()
renderElement<
Constructor>(constructor,options?):TemplateValue
Uses the same registered GluonElement class without running connection hooks.
Type Parameters
Constructor
Constructor extends GluonElementClass
Parameters
constructor
Constructor
options?
ServerElementOptions = {}
Returns
Example
Instantiate a registered Gluon Element for server rendering without running browser connection hooks, then serialize its shadow template:
import { GluonElement, defineElement, html } from '@gluonjs/core';
import { renderElement, renderToString, type ServerElementOptions } from '@gluonjs/ssr';
class ProductBadge extends GluonElement {
static override readonly properties = { name: String };
declare name: string;
protected render() { return html`<strong>${this.name}</strong>`; }
}
defineElement('product-badge', ProductBadge);
const options = { properties: { name: 'Orbit Lamp' } } satisfies ServerElementOptions;
const template = renderElement(ProductBadge, options);
console.log(await renderToString(template));