24 lines
482 B
TypeScript
24 lines
482 B
TypeScript
import { useState } from "preact/hooks";
|
|
import { IS_BROWSER } from "$fresh/runtime.ts";
|
|
|
|
interface CounterProps {
|
|
start: number;
|
|
id: string;
|
|
}
|
|
|
|
export default function Counter(props: CounterProps) {
|
|
const [count, setCount] = useState(props.start);
|
|
return (
|
|
<div id={props.id}>
|
|
<p>{count}</p>
|
|
<button
|
|
id={`b-${props.id}`}
|
|
onClick={() => setCount(count + 1)}
|
|
disabled={!IS_BROWSER}
|
|
>
|
|
+1
|
|
</button>
|
|
</div>
|
|
);
|
|
}
|