summaryrefslogtreecommitdiff
path: root/examples/framework-solid/src/components/Counter.tsx
blob: d6f9419994a28e5467df029e74d89181a777041a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { createSignal, type JSX } from 'solid-js';
import './Counter.css';

export default function Counter(props: { children?: JSX.Element }) {
	const [count, setCount] = createSignal(0);
	const add = () => setCount(count() + 1);
	const subtract = () => setCount(count() - 1);

	return (
		<>
			<div class="counter">
				<button onClick={subtract}>-</button>
				<pre>{count()}</pre>
				<button onClick={add}>+</button>
			</div>
			<div class="counter-message">{props.children}</div>
		</>
	);
}