Render Options
render is how Ornata turns component state back into DOM output inside the component’s HTML contract.
Each render callback returns a RenderOptions object for one resolved element or one item in a resolved element list.
Basic shape
Section titled “Basic shape”render: { value() { return { text: String(this.state.count), }; },}render: { value() { return { text: String(this.state.count), }; },}Available render outputs
Section titled “Available render outputs”Render callbacks can return:
texthtmlattributesclassesstyledatasetevents
These options can be combined in a single render result.
Set text when you want to update textContent.
render: { label() { return { text: this.state.label, }; },}render: { label() { return { text: this.state.label, }; },}Set html when you want to update innerHTML.
render: { output() { return { html: `<strong>${this.state.message}</strong>`, }; },}render: { output() { return { html: `<strong>${this.state.message}</strong>`, }; },}attributes
Section titled “attributes”Use attributes for standard and boolean attributes.
render: { panel() { return { attributes: { hidden: !this.state.open, "aria-expanded": String(this.state.open), }, }; },}render: { panel() { return { attributes: { hidden: !this.state.open, "aria-expanded": String(this.state.open), }, }; },}Behavior summary:
- string values set the attribute
trueadds a boolean attributefalseremoves a boolean attributenullremoves the attributeundefinedleaves it unchanged
classes
Section titled “classes”Use classes for class toggling.
render: { item() { return { classes: { "is-active": this.state.active, }, }; },}render: { item() { return { classes: { "is-active": this.state.active, }, }; },}Use style for inline style updates.
render: { panel() { return { style: { display: this.state.open ? "block" : "none", }, }; },}render: { panel() { return { style: { display: this.state.open ? "block" : "none", }, }; },}Behavior summary:
- string values set the style property
nullremoves the propertyundefinedleaves it unchanged
dataset
Section titled “dataset”Use dataset for data-* updates.
render: { item() { return { dataset: { state: this.state.active ? "active" : "idle", }, }; },}render: { item() { return { dataset: { state: this.state.active ? "active" : "idle", }, }; },}Behavior summary:
- string values set the dataset property
nullremoves the dataset propertyundefinedleaves it unchanged
events
Section titled “events”Use events to attach event handlers.
render: { button() { return { events: { click: () => this.methods.increment(), }, }; },}render: { button() { return { events: { click: () => this.methods.increment(), }, }; },}Rendering lists with index
Section titled “Rendering lists with index”When the rendered element is an array, Ornata passes index in the render context.
render: { items({ index }) { const currentIndex = index ?? 0;
return { classes: { "is-active": currentIndex === this.state.activeIndex, }, }; },}render: { items({ index }) { const currentIndex = index ?? 0;
return { classes: { "is-active": currentIndex === this.state.activeIndex, }, }; },}This is especially useful for:
- tabs
- menus
- repeated buttons
- repeated panels
- filtered or selected lists
A good mental model
Section titled “A good mental model”Render callbacks should describe DOM output, not general side effects.
That usually means:
renderfor visual and attribute updateswatchfor internal side effects- lifecycle hooks for setup and cleanup