Skip to content

Instantly share code, notes, and snippets.

@brandonros
Last active February 18, 2022 04:02
Show Gist options
  • Save brandonros/8850a4aad95f53c00375194d9cb35585 to your computer and use it in GitHub Desktop.
Save brandonros/8850a4aad95f53c00375194d9cb35585 to your computer and use it in GitHub Desktop.
Preact + htm template strings example (no JSX, no transpiling, unpkg imports)
<!doctype html>
<html>
<head>
</head>
<body>
<script type="module">
import * as Preact from 'https://unpkg.com/[email protected]/dist/preact.module.js'
import htm from 'https://unpkg.com/[email protected]/dist/htm.module.js'
const html = htm.bind(Preact.createElement)
class App extends Preact.Component {
constructor(props) {
super(props)
}
render() {
return html`
<div>Hello, world!</div>
`
}
}
window.addEventListener('load', () => {
Preact.render(html`<${App}/>`, document.body)
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment