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