2022-08-04 18:16:51 +00:00
|
|
|
/** @jsxImportSource preact */
|
|
|
|
|
2021-04-15 15:55:50 +00:00
|
|
|
import { useState } from 'preact/hooks';
|
|
|
|
|
2022-08-04 18:16:51 +00:00
|
|
|
/** A counter written with Preact */
|
2021-05-26 18:30:22 +00:00
|
|
|
export function PreactCounter({ children }) {
|
2021-05-03 18:26:10 +00:00
|
|
|
const [count, setCount] = useState(0);
|
|
|
|
const add = () => setCount((i) => i + 1);
|
|
|
|
const subtract = () => setCount((i) => i - 1);
|
2021-04-15 15:55:50 +00:00
|
|
|
|
2021-05-03 18:26:10 +00:00
|
|
|
return (
|
|
|
|
<>
|
2021-11-22 20:38:53 +00:00
|
|
|
<div class="counter">
|
2021-04-15 15:55:50 +00:00
|
|
|
<button onClick={subtract}>-</button>
|
|
|
|
<pre>{count}</pre>
|
|
|
|
<button onClick={add}>+</button>
|
2021-05-03 18:26:10 +00:00
|
|
|
</div>
|
2021-11-22 20:38:53 +00:00
|
|
|
<div class="counter-message">{children}</div>
|
2021-05-03 18:26:10 +00:00
|
|
|
</>
|
|
|
|
);
|
2021-04-15 15:55:50 +00:00
|
|
|
}
|