musikspider/islands/Counter.tsx

18 lines
492 B
TypeScript
Raw Normal View History

2023-04-12 07:34:23 +03:00
import { useState } from "preact/hooks";
import { Button } from "../components/Button.tsx";
interface CounterProps {
start: number;
}
export default function Counter(props: CounterProps) {
const [count, setCount] = useState(props.start);
return (
2023-04-12 09:47:57 +03:00
<div class="flex gap-2 w-full">
<p class="flex-grow-1 font-bold text-xl">{count}</p>
2023-04-12 07:34:23 +03:00
<Button onClick={() => setCount(count - 1)}>-1</Button>
<Button onClick={() => setCount(count + 1)}>+1</Button>
</div>
);
}