astro/examples/framework-multiple/src/components/PreactCounter.tsx
2021-12-22 16:11:05 -05:00

19 lines
468 B
TypeScript

import { useState } from 'preact/hooks';
/** a counter written in Preact */
export function PreactCounter({ children }) {
const [count, setCount] = useState(0);
const add = () => setCount((i) => i + 1);
const subtract = () => setCount((i) => i - 1);
return (
<>
<div class="counter">
<button onClick={subtract}>-</button>
<pre>{count}</pre>
<button onClick={add}>+</button>
</div>
<div class="counter-message">{children}</div>
</>
);
}