diff options
Diffstat (limited to 'examples/framework-preact/src/components/Counter.tsx')
-rw-r--r-- | examples/framework-preact/src/components/Counter.tsx | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/examples/framework-preact/src/components/Counter.tsx b/examples/framework-preact/src/components/Counter.tsx new file mode 100644 index 000000000..7c520b167 --- /dev/null +++ b/examples/framework-preact/src/components/Counter.tsx @@ -0,0 +1,19 @@ +import { h, Fragment } from 'preact'; +import { useState } from 'preact/hooks'; + +export default function Counter({ 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> + </> + ); +} |