<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"));
});
Run Pen

External CSS

  1. https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css
  2. https://cdnjs.cloudflare.com/ajax/libs/daisyui/4.4.19/full.css

External JavaScript

This Pen doesn't use any external JavaScript resources.