summaryrefslogtreecommitdiff
path: root/examples/server-islands/src/components/CartCount.tsx
blob: 5c3d3e3928d3d81c57db73b4da9d94b6d74ed411 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { useEffect, useState } from 'react';
import { onNewCartItem } from '../cart';

export default function({ count: initialCount }) {
	const [count, setCount] = useState(initialCount);
	useEffect(() => {
		return onNewCartItem(() => setCount(count + 1));
	}, [count]);
	
	return (
		<div className="absolute -right-3 -top-1 w-5 h-5 rounded-full flex items-center justify-center bg-primary text-white text-xs">
{count}</div>
	);
}