Skip to content

Instantly share code, notes, and snippets.

@jongacnik
Created April 9, 2017 23:35
Show Gist options
  • Save jongacnik/65af8617e5dc269ee740bbc7eb9948ea to your computer and use it in GitHub Desktop.
Save jongacnik/65af8617e5dc269ee740bbc7eb9948ea to your computer and use it in GitHub Desktop.
preact + hyperx
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