Skip to content

Instantly share code, notes, and snippets.

@stuf
Last active March 9, 2017 09:42
Show Gist options
  • Save stuf/fca5d17608abb187a6505c10b0504ba1 to your computer and use it in GitHub Desktop.
Save stuf/fca5d17608abb187a6505c10b0504ba1 to your computer and use it in GitHub Desktop.
import React from 'karet';
import Kefir from 'kefir';
const tick = Kefir.interval(1000, 1);
const Timer = ({ start = 0 }) =>
<div>
Seconds: {tick.scan((total, i) => total + i, start)}
</div>;
<timer>
<p>Seconds Elapsed: { time }</p>
<script>
this.time = opts.start || 0
tick() {
this.update({ time: ++this.time })
}
var timer = setInterval(this.tick, 1000)
this.on('unmount', function() {
clearInterval(timer)
})
</script>
</timer>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment