Reactopia
BrowseDiscoverSVG toolsAIChangelogAboutContact
BrowseDiscoverSVG toolsAI
Created by

Yash Mahajan


Reactopia

Open React tooling: components, SVG animation, and a growing directory. Built by Yash Mahajan.

Product

  • Components
  • Discover
  • SVG tools
  • AI direction

Legal

  • Privacy Policy
  • Terms of Use
  • Cookie Policy
  • License
  • Credits
  • Contact

Project

  • About
  • Changelog
  • GitHub
  • X

© 2026 Reactopia. All rights reserved.

PrivacyTermsCookies

Getting Started

IntroductionContributing

Components

SeparatorUiButtonBadgeStackUiInputIn devUiSelectIn devUiTextareaIn dev

Hooks

useDebounceuseLocalStorageuseMediaQueryuseMounted

Utilities

cngroupBysleep
Components
groupBy

groupBy

Group an array by key or selector function.

LiveutilityReact, Web, React NativeUpdated 2026-10-07MIT LicenseSource on GitHubReport Issue
cnsleep

Introduction

Group an array of objects by a key or selector function. No dependencies.

Platform: TypeScript / JavaScript (any environment).

Utility

export function groupBy<T, K extends string | number | symbol>(
items: T[],
keyFn: (item: T) => K
): Record<K, T[]> {
return items.reduce(
(acc, item) => {
const key = keyFn(item);
(acc[key] ??= []).push(item);
return acc;
},
{} as Record<K, T[]>
);
}

Example

ts
const byStatus = groupBy(tasks, (t) => t.status);

Footer

For large lists, consider indexing once and reusing the map instead of regrouping on every render.