react-component-guidelines

작성자: langfuse

React 컴포넌트 작성 지침입니다. 새로운 react 컴포넌트를 만들 때 사용하세요.

npx skills add https://github.com/langfuse/langfuse --skill react-component-guidelines

Components are useful because they act as an encapsulated unit and therefore promote composition. For this to work, a component needs to be isolatable and neither leak implementation details nor depend on its placement or usage context. The interface of a component is defined by its props, and therefore the props should be designed to be as explicit and unambiguous as possible.

Minimal Interface

  • No unused props
  • No default values unless they bring a MAJOR benefit for ergonomics, use your best judgement here.
  • Avoid optional props
  • No conflicting props (e.g. having both onClick & onSelect)

Composition

  • Avoid polymorphic components:
    • Presentation: A component should own one concrete presentation. When an action needs different presentations across contexts (e.g. sometimes a button, sometimes an icon), keep them separate rather than selecting between them with mode props or flags.
    • Behavior: A component should own one cohesive workflow. When a prop selects fundamentally different workflows, split them into separate behavior-owning components. For example, prefer dedicated create, update, and delete dialog controllers over one action component whose mode changes the entire interaction.
  • Extract only what is shared across call sites. Reuse a presentational component when the presentation is shared; when only state or behavior is shared, encapsulate it in a wrapper/render-prop component and let each call site provide its own presentation.

Explicit States

  • Always prefer Pick<> over Omit<> for prop types as this is more explicit.
  • When spreading props, you must exclude the props that are manually applied on an element in the type definition of the component via Pick<>
  • Use discriminated unions to communicate intent instead of relying on nullability / optionality
  • Use discriminated unions to make impossible states impossible to represent in the type system instead of relying on runtime checks (e.g. if there is a loading and data type in the prop, then it should not be possible to have a state where loading is true and data is not null)

Encapsulation

  • No className / style props unless the component itself is a headless component that does not contain any styling or layout logic itself.
  • Internals such as cva classes or helper functions should not be exported

Ownership

  • Margin should be applied by the parent component, not contained in a component. The child component should only define the inner spacing of itself and its contents.
  • It's bad practice to have a component that returns null or undefined. Most of the time this suggests that the condition that leads to this state should be handled by the parent component instead, often this can be done in a way close to the current component by using a hook or a HOC.

Deterministic Styling

  • Avoid conflicting style names in CSS definitions, even though they might be removed by tailwind-merge or the likes. Make the variants explicit instead by using cva, conditions or lookup tables.

langfuse의 다른 스킬

clickhouse-best-practices
langfuse
ClickHouse 스키마, 쿼리 또는 구성을 검토할 때 반드시 사용해야 합니다. 권장 사항을 제공하기 전에 반드시 확인해야 하는 28개의 규칙이 포함되어 있습니다. 항상 읽어보세요…
official
skill-creator
langfuse
효과적인 스킬을 만들기 위한 가이드입니다. 사용자가 Claude의 기능을 확장하는 새 스킬을 만들거나 기존 스킬을 업데이트하려 할 때 이 스킬을 사용해야 합니다.
official
vercel-react-best-practices
langfuse
Vercel Engineering의 React 및 Next.js 성능 최적화 가이드라인입니다. 이 스킬은 React/Next.js를 작성, 검토 또는 리팩토링할 때 사용해야 합니다…
official
add-model-price
langfuse
Use when editing worker/src/constants/default-model-prices.json, packages/shared/src/server/llm/types.ts, pricing tiers, tokenizer IDs, or matchPattern regexes…
official
analyze-cloud-costs
langfuse
Metabase cost marts를 사용하여 Langfuse Cloud 인프라 비용 구조를 분석합니다. 클라우드 지출, AWS 대 ClickHouse 비용 분할, 비용…에 대해 질문받을 때 사용합니다.
official
backend-dev-guidelines
langfuse
Build or review Langfuse backend code. Use for tRPC routers, public REST APIs, BullMQ processors, services, middleware, Prisma or ClickHouse access,…
official
clickhouse-best-practices
langfuse
ClickHouse 스키마, 쿼리 또는 구성을 검토할 때 반드시 사용해야 합니다. 권장사항을 제공하기 전에 확인해야 하는 28가지 규칙이 포함되어 있습니다. 항상 읽으세요…
official
code-review
langfuse
Review Langfuse code changes for correctness, regressions, and best practices.
official