Tutorial: Building a Reactive Hello World
In this 3-minute walkthrough, you will build a self-contained <hello-world> custom element that accepts an initial attribute, binds an input field, and updates the DOM without a bundler.
Complete Single-File Example
<!DOCTYPE html>
<html lang="en">
<body>
<template id="hello-world">
<p>Hello, <strong>{{ target }}</strong>!</p>
<input name="target" value="{{ target }}" placeholder="Enter a name" />
</template>
<hello-world target="Synergy"></hello-world>
<script type="module">
import { define } from 'https://unpkg.com/[email protected]/dist/synergy.mjs'
define('hello-world', (props) => ({
target: props.target || 'World'
}))
</script>
</body>
</html>
How It Works
Notice that typing into the <input name="target"> automatically updates this.target, which immediately updates the <strong> text node in place. No virtual tree diffing or manual setState() boilerplate is required.
Read more in Why SynergyJS Skips the Virtual DOM.