Created
January 22, 2020 02:00
-
-
Save brandonpittman/6f9dbf1d4a0f64d70d0b5a9611c966da to your computer and use it in GitHub Desktop.
Preact standalone module test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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