Skip to content

Instantly share code, notes, and snippets.

@zouhir
Last active March 26, 2018 04:30
Show Gist options
  • Save zouhir/01dc0cd4102f6ae4ef86e2662fa830cd to your computer and use it in GitHub Desktop.
Save zouhir/01dc0cd4102f6ae4ef86e2662fa830cd to your computer and use it in GitHub Desktop.
Preact meets CMS: Building Lightweight Portable Widget Components
import { h, Component } from "preact";
import habitat from "preact-habitat";
class HelloWidget extends Component {
render() {
let time = new Date().toLocaleTimeString();
let name = this.props.name || "nobody";
return <h1>{`Hello ${name}, time is: ${time}`}</h1>;
}
}
let helloWidgetHabitat = habitat(HelloWidget);
helloWidgetHabitat.render({
inline: true
});
// assuming your build tool exports a `hello-widget.js` static file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment