Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Preact standalone module test
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<script type="module">
import {html, render, useState} from 'https://unpkg.com/htm/preact/standalone.module.js';
const Counter = () => {
const [count, setCount] = useState(0)
const increment = () => setCount(count + 1)
const decrement = () => {
if (count > 0) setCount((currentCount) => currentCount - 1)
}
return html`
<p>
Count: ${count}
</p>
<button onClick=${decrement}>-</button>
<button onClick=${increment}>+</button>
`
}
render(html`<${Counter}/>`, document.body)
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment