Created
July 19, 2018 21:42
-
-
Save sadhasivam/2a798a0495204acd85764d881a34a9a4 to your computer and use it in GitHub Desktop.
npm_module_loading.js
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
const npm = p => import(`https://unpkg.com/${p}?module`); | |
(async () => { | |
const { h, Component, render } = await npm('preact'); | |
class Clock extends Component { | |
componentWillMount() { | |
const tick = () => this.setState({ time: new Date() }); | |
setInterval(tick, 1000); | |
tick(); | |
} | |
render({ }, { time }) { | |
return h('time', { title: time+'' }, time.toLocaleTimeString()); | |
} | |
} | |
render(h(Clock), document.body); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment