<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Preact Counter</title>
<script type="module">
import {
html,
render,
useState,
} from "https://esm.sh/htm@3.1.1/preact/standalone";
var root = document.getElementById("root");
render(html`<${Counter} />`, root);
function Counter({ start = 0 }) {
var [count, setCount] = useState(start);
function increment() {
setCount(count + 1);
}
return html`
<p>Count: ${count}</p>
<button type="button" onClick=${increment}>
Increment
</button>
`;
}
</script>
</head>
<body>
<div id="root"></div>
</body>
</html>JavaScript modules generally don’t work with the file://
protocol because of security features that web browsers implement. They prevent malicious scripts from accessing files on your computer that they shouldn’t.