revite/src/lib/PaintCounter.tsx

23 lines
567 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-07-05 06:23:23 -04:00
export default function PaintCounter({
2021-07-05 06:25:20 -04:00
small,
always,
2021-07-05 06:23:23 -04:00
}: {
2021-07-05 06:25:20 -04:00
small?: boolean;
always?: boolean;
2021-07-05 06:23:23 -04:00
}) {
2021-07-05 06:25:20 -04:00
if (import.meta.env.PROD && !always) return null;
2021-06-19 10:29:04 -04:00
const [uniqueId] = useState(`${Math.random()}`);
2021-07-05 06:25:20 -04:00
const count = counts[uniqueId] ?? 0;
counts[uniqueId] = count + 1;
return (
<div style={{ textAlign: "center", fontSize: "0.8em" }}>
{small ? <>P: {count + 1}</> : <>Painted {count + 1} time(s).</>}
</div>
);
2021-06-19 07:34:53 -04:00
}