Skip to content

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.

render: {
value() {
return {
text: String(this.state.count),
};
},
}

Render callbacks can return:

  • text
  • html
  • attributes
  • classes
  • style
  • dataset
  • events

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,
};
},
}

Set html when you want to update innerHTML.

render: {
output() {
return {
html: `<strong>${this.state.message}</strong>`,
};
},
}

Use attributes for standard and boolean attributes.

render: {
panel() {
return {
attributes: {
hidden: !this.state.open,
"aria-expanded": String(this.state.open),
},
};
},
}

Behavior summary:

  • string values set the attribute
  • true adds a boolean attribute
  • false removes a boolean attribute
  • null removes the attribute
  • undefined leaves it unchanged

Use classes for class toggling.

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",
},
};
},
}

Behavior summary:

  • string values set the style property
  • null removes the property
  • undefined leaves it unchanged

Use dataset for data-* updates.

render: {
item() {
return {
dataset: {
state: this.state.active ? "active" : "idle",
},
};
},
}

Behavior summary:

  • string values set the dataset property
  • null removes the dataset property
  • undefined leaves it unchanged

Use events to attach event handlers.

render: {
button() {
return {
events: {
click: () => this.methods.increment(),
},
};
},
}

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,
},
};
},
}

This is especially useful for:

  • tabs
  • menus
  • repeated buttons
  • repeated panels
  • filtered or selected lists

Render callbacks should describe DOM output, not general side effects.

That usually means:

  • render for visual and attribute updates
  • watch for internal side effects
  • lifecycle hooks for setup and cleanup