Skip to content

Using it from a framework

The output is a tag. There is no adapter package, no wrapper, and nothing to install on the other side.

define('user-card', {
props: { name: '', age: 0, tags: [] },
setup: ({ name, age, tags }, host) => html``,
});
<script type="module" src="https://unpkg.com/@alacris/core@0.11.3"></script>
<script type="module" src="./user-card.js"></script>
<user-card name="Ada" age="36"></user-card>

Frameworks disagree about how to pass data to an unknown tag. React 18 sets attributes; Vue, Angular, Svelte and Solid set properties. A component that only handles one of them works in half the ecosystem.

Every Alacris prop is both:

el.setAttribute('age', '36'); // attribute path — parsed to a number
el.age = 36; // property path — used as-is

The default’s type drives the coercion, so props: { age: 0 } turns "36" into 36, and props: { tags: [] } parses '["a"]' as JSON.

Alacris does not do server-side rendering — it renders in the browser when the element upgrades. In practice that means:

  • Server-rendered markup can include the tag and its attributes; the component reads them at upgrade.
  • Anything inside the tag is slotted content, so it is visible before the script loads and stays visible after.
  • Properties set by a framework before the definition arrives are replayed.

For content that must be visible before JavaScript runs, put it in a slot rather than rendering it inside the component.

If several component packages depend on Alacris, make sure they share one copy — two copies means two reactive graphs. With a bundler this is automatic. Without one, use an import map:

<script type="importmap">
{ "imports": { "@alacris/core": "https://unpkg.com/@alacris/core@0.11.3/dist/alacris.js" } }
</script>