Something went wrong. Try again.
a tiny pet with a GPT-2 brain, living in your browser
Something went wrong. Try again.
773 B · 33 lines
TSX
at cloud-pet
12345678910111213141516171819202122232425262728293031323334import { useLayoutEffect, useState } from "preact/hooks";import { snapshot, subscribe } from "../app/store.ts";import { SPRITES, spriteURL } from "../sprites.ts";export function useApp() { const [revision, setRevision] = useState(snapshot); useLayoutEffect(() => { const update = () => setRevision(snapshot()); const unsubscribe = subscribe(update); update(); return unsubscribe; }, []); return revision;}export function Icon({ name, scale = 3, alt = "",}: { name: string; scale?: number; alt?: string;}) { const rows = SPRITES[name]; return rows ? ( <img class="px-icon" src={spriteURL(name, scale)} alt={alt} width={rows[0].length * scale} height={rows.length * scale} /> ) : null;}