Skip to content

Instantly share code, notes, and snippets.

@benjaminoakes
Created April 23, 2021 03:16
Show Gist options
  • Save benjaminoakes/3acdc70bca8c1b3b0881e2e581257b0f to your computer and use it in GitHub Desktop.
Save benjaminoakes/3acdc70bca8c1b3b0881e2e581257b0f to your computer and use it in GitHub Desktop.
Preact and HTM example
import { html, Component, render } from 'https://unpkg.com/htm/preact/standalone.module.js';
class Clock extends Component {
constructor() {
super()
this.tick()
}
componentDidMount() {
this.timer = setInterval(() => this.tick(), 1000)
}
tick() {
this.setState({ time: new Date() })
}
componentWillUnmount() {
clearInterval(this.timer)
}
render() {
let iso8601 = this.state.time.toISOString()
return html`<span>${iso8601}</span>`
}
}
render(html`<${Clock} />`, document.body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment