Files
sweet/www/islands/Counter.tsx
T
Luca Casonato a6852fa58f feat: more advanced prop serializer for islands (#1224)
This commit adds support for an advanced (de)serializer that is used
for page state (island props and plugin state). This new serializer
supports maintaining references (thus supporting circular objects,
and multi-referenced objects).

This is a pre-requisite for allowing to pass signals, JSX, Uint8Arrays,
Date, and many other "advanced" values.
2023-05-31 10:12:07 +02:00

32 lines
889 B
TypeScript

import { useSignal } from "@preact/signals";
import { IS_BROWSER } from "$fresh/runtime.ts";
import { RoundedButton } from "../components/Button.tsx";
import { IconMinus, IconPlus } from "../components/Icons.tsx";
interface CounterProps {
start: number;
}
export default function Counter(props: CounterProps) {
const count = useSignal(props.start);
return (
<div class="bg-gray-100 p-4 border border-gray-200 flex items-center justify-around">
<RoundedButton
title="Subtract 1"
onClick={() => count.value -= 1}
disabled={!IS_BROWSER || count.value <= 0}
>
<IconMinus />
</RoundedButton>
<div class="text-3xl tabular-nums">{count}</div>
<RoundedButton
title="Add 1"
onClick={() => count.value += 1}
disabled={!IS_BROWSER}
>
<IconPlus />
</RoundedButton>
</div>
);
}