mirror of
https://github.com/withastro/astro.git
synced 2025-01-20 22:12:38 -05:00
21 lines
545 B
TypeScript
21 lines
545 B
TypeScript
|
import { h, Fragment } from 'preact';
|
||
|
import { useState } from 'preact/hooks';
|
||
|
|
||
|
/** a counter written in Preact */
|
||
|
export default function PreactCounter({ children }) {
|
||
|
const [count, setCount] = useState(0);
|
||
|
const add = () => setCount((i) => i + 1);
|
||
|
const subtract = () => setCount((i) => i - 1);
|
||
|
|
||
|
return (
|
||
|
<>
|
||
|
<div className="counter">
|
||
|
<button onClick={subtract}>-</button>
|
||
|
<pre>{count}</pre>
|
||
|
<button onClick={add}>+</button>
|
||
|
</div>
|
||
|
<div className="children">{children}</div>
|
||
|
</>
|
||
|
);
|
||
|
}
|