```tsx import { computed, UI, pattern } from 'commontools'; interface Item { title: string; category: string; } interface Input { items: Item[]; } export default pattern(({ items }) => { const groupedItems = computed(() => { const groups: Record = {}; for (const item of items) { const cat = item.category || "Uncategorized"; if (!groups[cat]) groups[cat] = []; groups[cat].push(item); } return groups; }); const categories = computed(() => Object.keys(groupedItems).sort()); return { [UI]: ( <> {categories.map(category => (

{category}

{(groupedItems[category] ?? []).map(item => (
{item.title}
))}
))} ), }; }); ```