Skip to content
Skills Library
Programming · Building & coding

split-components

/split-components

Keep component files small and split — one main component per file, extract heavy sub-components, pull out logic and types. Use whenever a .tsx file is swelling (several big components in one file, file over ~250 lines) or before creating a new one, to avoid ending up with monster 800+ line files.

Repository
rerun ↗
Licence
AGPL-3.0
Last repository change
13.11.2026

Assessment and security

90/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content25 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 13.11.2026, without references to retired models or APIs.

Licence

AGPL-3.0, copyleft: przeróbki udostępniane innym muszą mieć tę samą licencję.

What it does and when to use it

Keep component files small and split — one main component per file, extract heavy sub-components, pull out logic and types. Use whenever a .tsx file is swelling (several big components in one file, file over ~250 lines) or before creating a new one, to avoid ending up with monster 800+ line files.

Original author description

Keep component files small and split — one main component per file, extract heavy sub-components, pull out logic and types. Use whenever a .tsx file is swelling (several big components in one file, file over ~250 lines) or before creating a new one, to avoid ending up with monster 800+ line files.

How it works

  1. Rule
  2. What to extract (in priority order)
  3. What NOT to split (tolerances)
  4. Splitting an oversized file (procedure)
  5. Before creating a new component
Original SKILL.md headings · 40 lines, 464 words
SKILL.md preview
---
name: split-components
description: Keep component files small and split — one main component per file, extract heavy sub-components, pull out logic and types. Use whenever a .tsx file is swelling (several big components in one file, file over ~250 lines) or before creating a new one, to avoid ending up with monster 800+ line files.
---

# split-components — one component per file, short files

Companion to [sort-components]: `sort-components` places files **in the right feature folder** ; this skill keeps **each file short and focused**. The real problem: files that balloon (`CreateAgentDialog.tsx` = 813 lines, `AgentChat.tsx` = 645) because several big components + their logic + their types get piled into one place. It becomes unreadable, impossible to review in a diff, and painful to change.

## Rule

> **One file = one main exported component.** The file name = the component name (`AgentChat.tsx` exports `AgentChat`).

When a file grows, split it **before** it turns into a monster. Warning threshold: **~250 lines**, or **more than one "heavy" component** (state/effects/business logic) in the same file.

## What to extract (in priority order)

1. **A second heavy component** (its own state/effects/logic, or reused elsewhere) → its own file in the same feature folder, imported with the absolute alias `@/components/<folder>/<File>`.
2. **Non-visual logic** (fetch, transforms, complex handlers) → a `useXxx` hook in a neighboring file, or a `lib/` helper.
3. **Shared types/schemas** → a folder-level `types.ts`, or co-located at the top of the file of the component that owns them.
4. **Large constant arrays / config** (option lists, mappings) → a `*.constants.ts`.

## What NOT to split (tolerances)

- **Small, purely presentational local sub-components** used only by the file's main component (a `<Row>`, a private 15-line header): keep them in the file. Extracting them would create more noise than value.
- **Compound primitives in `ui/` and `ai-elements/`** (shadcn / Radix: `dropdown-menu.tsx`, `dialog.tsx`, `select.tsx`, `message.tsx`…). They deliberately export several sub-parts (`DialogTrigger`, `DialogContent`…): that's the expected compound-component pattern, **do not break them up**. The "components per file" count is misleading here.

In other words: the "one component per file" rule targets **feature** components (agent/, space/, chat/, dialogs/, layout/…), not compound primitives.

## Splitting an oversized file (procedure)

1. **List the components in the file**: `grep -nE "^(export )?(function|const) [A-Z]" <file>` → identify the main component vs the heavy sub-component candidates.
2. For each heavy candidate: create `@/components/<folder>/<SubComponentName>.tsx`, move the component + its imports there.
3. **Rewrite imports** with the absolute alias (`@/components/...`), never fragile `./Foo`.
4. Pull logic out into a hook / helper if the file is still heavy after extracting the components.
5. **Verify**: `cd apps/ui && npx tsc --noEmit` → exit 0 (all imports resolve).
6. Diff: moves should show up cleanly; don't reformat the whole file along the way (see [[prettier-not-uniform-apps-ui]] — fix indentation by hand, no global `prettier --write` that bloats the diff).

## Before creating a new component

Don't start from a file that will host 3 components "because it's convenient". Create the right file per component from the start, placed according to [sort-components]. Splitting after the fact is more expensive than placing it well up front.

[sort-components]: ../sort-components/SKILL.md

Versions

The database has no other skills named split-components.

Database snapshot: 13.11.2026 · package version c28a1b31f1ce (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100creating-components
    Use when creating new UI components in packages/ui. Covers component structure, tests, stories, and what to avoid.
  • 100frontend-component-patterns
    ACTIVATE when creating or refactoring React components, splitting large components, extracting hooks, or deciding Container vs Presentation. ACTIVATE for 'component split', 'Container/Presentation', 'extract hook', 'god component', 'prop drilling'. Covers: Container vs…
  • 100react
    React component development guide. Use when working with React components (.tsx files), creating UI, using @lobehub/ui components, implementing routing, or building frontend features. Triggers on React component creation, modification, layout implementation, or navigation tasks.
  • 100module-boundaries
    Decide which file owns a piece of logic in Motioneer, keep files small, and know which boundaries are load bearing. Use when adding a feature, when logic could plausibly live in two files, when a file grows past a few hundred lines, or when reviewing a change for architecture rather than for bugs.
  • 91components
    React component architecture for creating composable, accessible components with data attributes. Use when creating/updating composable components, not for higher-level feature/page components.
  • 100frontend-test
    Generate frontend component tests (React Testing Library, Vue Test Utils, snapshot) for existing components. Auto-invoke when user says "test this component", "write component test", or "add component test".

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.