revite/src/lib/PaintCounter.tsx

19 lines
582 B
TypeScript
Raw Normal View History

2021-06-19 07:34:53 -04:00
import { useState } from "preact/hooks";
const counts: { [key: string]: number } = {};
2021-06-19 15:24:11 -04:00
export default function PaintCounter({ small, always }: { small?: boolean, always?: boolean }) {
if (import.meta.env.PROD && !always) return null;
2021-06-19 10:29:04 -04:00
2021-06-19 07:34:53 -04:00
const [uniqueId] = useState('' + Math.random());
const count = counts[uniqueId] ?? 0;
counts[uniqueId] = count + 1;
return (
2021-06-19 13:46:05 -04:00
<div style={{ textAlign: 'center', fontSize: '0.8em' }}>
2021-06-19 10:29:04 -04:00
{ small ? <>P: { count + 1 }</> : <>
Painted {count + 1} time(s).
</> }
2021-06-19 13:46:05 -04:00
</div>
2021-06-19 07:34:53 -04:00
)
}