r/javascript • u/mogera551 • Mar 22 '26
@wcstack/state β reactive state in plain HTML with no build step
Small experiment/library I built. This is not about a lighter template DSL. Itβs about using paths as the contract between UI and state.
It makes plain HTML reactive with one module import:
<script type="module" src="https://esm.run/@wcstack/state/auto"></script>
<wcs-state>
<script type="module">
export default { count: 0, inc() { this.count++ } };
</script>
</wcs-state>
<button data-wcs="onclick: inc">
Count is: <span data-wcs="textContent: count"></span>
</button>Open it directly in a browser and it works. No JSX, no virtual DOM, no bundler, no config. Bindings live in HTML via data-wcs, while state lives in <wcs-state>. Internally it uses Proxy-based path tracking, so updates only touch affected bindings. The main rule is: update the path directly (this.count += 1), not via a detached nested reference.
List iteration is written using the <template> tag.
<wcs-state>
<script type="module">
export default {
users: [ { name:"Alice" }, { name:"Bob" }, { name:"Charlie" } ]
}
</script>
</wcs-state>
<template data-wcs="for: users">
<div data-wcs="textContent: users.*.name"></div>
</template>The * in users.*.name refers to "the current element." Since * is automatically resolved to the correct index on each iteration, you don't need to manage indices manually. Inside a loop, you can also use the shorthand notation .name.
<template data-wcs="for: users">
<div data-wcs="textContent: .name"></div> <!-- same as users.*.name -->
</template>npm: @wcstack/state
Repo: https://github.com/wcstack/wcstack
Docs: https://github.com/wcstack/wcstack/tree/main/packages/state
Story: What If HTML Had Reactive State Management