Created
September 20, 2022 14:04
-
-
Save x4d3/12a5ea791dfcf4f9dcdf41538f41ff70 to your computer and use it in GitHub Desktop.
This file contains 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"> | |
<title>htm Demo</title> | |
<link rel="stylesheet" href="https://cdn.simplecss.org/simple.min.css"> | |
<script type="module"> | |
import {html, Component, render} from 'https://unpkg.com/htm/preact/standalone.module.js'; | |
class App extends Component { | |
addTodo() { | |
const {todos = []} = this.state; | |
this.setState({todos: todos.concat(`Item ${todos.length}`)}); | |
} | |
render({page}, {todos = []}) { | |
return html` | |
<div class="app"> | |
<${Header} name="ToDo's (${page})"/> | |
<ul> | |
${todos.map(todo => html` | |
<li key=${todo}>${todo}</li> | |
`)} | |
</ul> | |
<button onClick=${() => this.addTodo()}>Add Todo</button> | |
<${Footer}>footer content here</ | |
/> | |
</div> | |
`; | |
} | |
} | |
const Header = ({name}) => html`<h1>${name} List</h1>` | |
const Footer = props => html` | |
<footer ...${props}/>` | |
render(html` | |
<${App} page="All"/>`, document.body); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment