diff options
Diffstat (limited to 'examples/framework-react/src/components/Counter.tsx')
-rw-r--r-- | examples/framework-react/src/components/Counter.tsx | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/examples/framework-react/src/components/Counter.tsx b/examples/framework-react/src/components/Counter.tsx new file mode 100644 index 000000000..cc416d3f1 --- /dev/null +++ b/examples/framework-react/src/components/Counter.tsx @@ -0,0 +1,25 @@ +import { useState } from 'react'; +import './Counter.css'; + +export default function Counter({ + children, + count: initialCount, +}: { + children: JSX.Element; + count: number; +}) { + const [count, setCount] = useState(initialCount); + 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="counter-message">{children}</div> + </> + ); +} |