Created
April 9, 2017 23:35
-
-
Save jongacnik/65af8617e5dc269ee740bbc7eb9948ea to your computer and use it in GitHub Desktop.
preact + hyperx
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
var { h, Component } = preact; | |
var hx = hyperx( (tag, props, kids) => h(tag, props, ...kids) ); | |
var App = () => hx` | |
<div id="app"> | |
${h(Demo)} | |
</div> | |
`; | |
class Demo extends Component { | |
constructor(props, context) { | |
super(props, context); | |
this.state = { n: 0 }; | |
this.handleClick = () => { | |
this.setState({ n: this.state.n + 1 }) | |
}; | |
} | |
render(props, state) { | |
return hx` | |
<div> | |
<h1>clicked ${state.n} times</h1> | |
<button onClick=${this.handleClick}>click me!</button> | |
</div> | |
`; | |
} | |
} | |
preact.render(h(App), document.body); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment