/** @jsxImportSource preact */ import { useStore } from "@nanostores/preact"; import type { ComponentChildren } from "preact"; import { useState } from "preact/hooks"; import AstroLogo from "../../images/astro.png?url"; import OutSystemsLogo from "../../images/outsystems.png?url"; import { Operation, setCounterCount } from "../../lib/setCounterCount"; import { setupStore } from "../../stores/demo"; interface DemoProps { children: ComponentChildren; header: ComponentChildren; initialCount: number; showMessage: string; } export default function Demo({ children, header, initialCount, showMessage, }: DemoProps) { const [count, setCount] = useState(initialCount); const add = () => setCount((i) => setCounterCount(i, Operation.Add)); const subtract = () => setCount((i) => setCounterCount(i, Operation.Subtract)); const showParentMessage = () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any (window as any)[showMessage](count); }; const store = setupStore("preactStore"); const nanoStoreValue = useStore(store); return ( <> {header}
Preact counter component
Internal counter controls. It keeps state within the component.
{count}
The button sends the current count value to a function in the parent component.
Nano Stores
Value:
{nanoStoreValue}
Slot content
{children}
OutSystems logo Astro logo
); }