Last active
November 28, 2020 00:10
-
-
Save fev4/e41f8fe61f0dc1833979efde22b9eb2a to your computer and use it in GitHub Desktop.
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
import { h, render } from 'https://unpkg.com/preact@latest?module'; | |
import { | |
useState, | |
useEffect, | |
} from 'https://unpkg.com/preact@latest/hooks/dist/hooks.module.js?module'; | |
import htm from 'https://unpkg.com/htm@latest/dist/htm.module.js?module'; | |
// Initialize htm with Preact | |
const html = htm.bind(h); | |
function Props() { | |
const [count, setCount] = useState(0); | |
// set counters | |
const increment = () => setCount(count + 1); | |
// You can also pass a callback to the setter | |
const decrement = () => setCount((currentCount) => currentCount - 1); | |
return html` | |
<div>Count: ${count}</div> | |
<p>New content!</p> | |
<button onClick="${increment}">Increment</button> | |
<button onClick="${decrement}">Decrement</button> | |
`; | |
} | |
render(html` <${Props} /> `, document.getElementById('preact-container')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment