<div id="app" class="flex flex-col items-center justify-center h-screen">
<div class="py-4">Counter: {{ count }}</div>
<button onclick="increment()" class="btn btn-primary">Increment</button>
</div>
import Cog from "https://esm.sh/@mzrk/cog";
// Get the variable factory method from the global Cog object
const { variable, render } = Cog;
// Initialize reactive variable 'count'
const counter = variable("count", 0);
// Make increment available in global scope for onclick handler
window.increment = () => {
// Get count value and update it using count setter
counter.set(counter.value + 1);
};
document.addEventListener("DOMContentLoaded", function () {
render(document.getElementById("app"));
});
This Pen doesn't use any external JavaScript resources.