Skip to content

Instantly share code, notes, and snippets.

@sadhasivam
Created July 19, 2018 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sadhasivam/2a798a0495204acd85764d881a34a9a4 to your computer and use it in GitHub Desktop.
Save sadhasivam/2a798a0495204acd85764d881a34a9a4 to your computer and use it in GitHub Desktop.
npm_module_loading.js
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