render
Render a StacheElement
instance.
render(props)
Calling render
will initialize an element and render its view into its innerHTML
. Normally this is called by the connectedCallback, but can be called manually for testing:
import { StacheElement } from "can/everything";
class MyElement extends StacheElement {
static view = `
<p>{{this.age}}</p>
`;
static props = {
age: { type: Number, default: 30 }
};
}
customElements.define("my-el", MyElement);
const myEl = new MyElement()
.render({ age: 32 });
myEl.age; // -> 32
myEl.firstElementChild; // -> <p>32</p>
Parameters
- props
{Object}
:The initial property values.
Returns
{Element}
:
The element
instance.
Purpose
For testing purposes or integration with other libraries, render
can be called to render an element with its view.
The first time render
is called, it will:
- initialize the element with the property values passed to
render
. - render the stache view into the element.
Subsequent calls to render
will not have any effect.