summaryrefslogtreecommitdiff
path: root/examples/framework-multiple/src/components/PreactCounter.tsx
blob: 9c9bf73a1c5924851c8d89067f77867b28202950 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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>
    </>
  );
}