Newer
Older
hello-programmer-world / src / components / Counter.jsx
@houston[bot] houston[bot] on 15 Dec 435 bytes Initial commit from Astro
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 class="counter">
				<button onClick={subtract}>-</button>
				<pre>{count}</pre>
				<button onClick={add}>+</button>
			</div>
			<div class="counter-message">{children}</div>
		</>
	);
}