Skip to content

Instantly share code, notes, and snippets.

View knirb's full-sized avatar

Viktor Åsbrink knirb

  • Umain AB
  • Stockholm, Sweden
View GitHub Profile
@knirb
knirb / useTimer.ts
Created August 16, 2021 15:21
timer hook for react
import { useState, useRef } from "react";
interface Props {
length: number;
onComplete?: () => void;
}
const tick = 200;
const format = (date: number): string => {
const length = 10 * 1000 * 60;
const App: React.FC = () => {
const timer = useTimer({ length });
return (
<div className="App">
<h2>{timer.value}</h2>
<div>
<Button onClick={timer.start}>Start</Button>
<Button onClick={timer.stop}>Stop</Button>
<Button onClick={timer.skip}>Skip</Button>
@knirb
knirb / timer.js
Created August 16, 2021 15:10
excerpt from timer app
<div className="App">
<header className="App-header">
<h2>Timers completed: {completed}</h2>
<h2>{timer.value}</h2>
<div>
<Button onClick={timer.start}>Start</Button>
<Button onClick={timer.stop}>Stop</Button>
</div>
<div>
<Button onClick={timer.skip}>Skip</Button>