mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-07 09:25:27 +00:00
Port and re-write icon code.
This commit is contained in:
12
src/lib/PaintCounter.tsx
Normal file
12
src/lib/PaintCounter.tsx
Normal file
@@ -0,0 +1,12 @@
|
||||
import { useState } from "preact/hooks";
|
||||
|
||||
const counts: { [key: string]: number } = {};
|
||||
|
||||
export default function PaintCounter() {
|
||||
const [uniqueId] = useState('' + Math.random());
|
||||
const count = counts[uniqueId] ?? 0;
|
||||
counts[uniqueId] = count + 1;
|
||||
return (
|
||||
<span>Painted {count + 1} time(s).</span>
|
||||
)
|
||||
}
|
||||
24
src/lib/windowSize.ts
Normal file
24
src/lib/windowSize.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { useEffect, useState } from "preact/hooks";
|
||||
|
||||
export function useWindowSize() {
|
||||
const [windowSize, setWindowSize] = useState({
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
function handleResize() {
|
||||
setWindowSize({
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight
|
||||
});
|
||||
}
|
||||
|
||||
window.addEventListener("resize", handleResize);
|
||||
handleResize();
|
||||
|
||||
return () => window.removeEventListener("resize", handleResize);
|
||||
}, []);
|
||||
|
||||
return windowSize;
|
||||
}
|
||||
Reference in New Issue
Block a user