Last active
March 26, 2018 04:30
-
-
Save zouhir/01dc0cd4102f6ae4ef86e2662fa830cd to your computer and use it in GitHub Desktop.
Preact meets CMS: Building Lightweight Portable Widget Components
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
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