Token导航 LogoToken导航TokenDH.com
开发规范需要联网github未标认证来源可访问许可证需确认审计通过

typescript-and-react-guidelinesTypeScript AND React guidelines 开发

Agent Skill

用于辅助前端页面、组件、样式和交互逻辑的开发与维护。它适合让 Agent 生成或审查 React、Next.js、Vue、Tailwind、CSS 等相关代码,整理组件结构,或定位布局和性能问题。使用时需要结合项目现有设计系统、路由和构建方式,避免只生成孤立片段;涉及页面改动时,应配合本地预览和构建检查确认视觉效果。

总安装

238

周安装

10

GitHub Stars

公开资料未说明

下载量

83
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:typescript-and-react-guidelines(TypeScript AND React guidelines 开发)
来源仓库:https://github.com/lichens-innovation/skills
仓库路径:skills/typescript-and-react-guidelines
安装命令:
npx skills add https://github.com/lichens-innovation/skills --skill typescript-and-react-guidelines
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/lichens-innovation/skills --skill typescript-and-react-guidelines

简介

用于辅助前端页面、组件和样式开发,支持 React、Vue 等框架的代码生成与审查。

  • 适合在 Codex、Claude、Cursor、Gemini CLI 中整理组件结构或定位布局问题。
  • 通过 GitHub 安装,使用 npx skills add 命令从 lichens-innovation/skills 仓库添加技能。
  • 使用时需结合项目现有设计系统和构建方式,避免生成孤立代码片段。
  • typescript-and-react-guidelines 属于开发规范类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Coding Standards & Best Practices

Non-negotiable rules

Apply non-negotiable rules (19 rules, ordered by impact) before anything else.


Agent Instructions

After reading this skill:

  1. Apply ALL rules to every file you create or modify
  2. Run the Pre-output Validation checklist before returning any code
  3. If a rule conflicts with a user request, flag it explicitly and propose a compliant alternative
  4. Reference specific rule names when explaining choices (e.g., "Per the KISS principle, I simplified this by...")
  5. Load example files on demand — only read the relevant file for the task at hand

Code Quality Principles

PrincipleRule
Readability FirstCode is read more than written. Clear names > clever code.
KISSSimplest solution that works. Avoid over-engineering.
Avoid GodComponentSingle responsibility per component; extract utilities, hooks, sub-components.
DRYExtract common logic. Create reusable components.
YAGNIDon't build features before they're needed.
ImmutabilityNever mutate — always return new values.

Avoiding GodComponent (decomposition strategy)

Apply the following order to keep components focused and testable:

  1. Extract pure TypeScript utilities first

- Move logic that has no React dependency into pure functions. - If a utility takes more than one argument, use object destructuring in the signature so argument names are explicit at the call site. Extract the parameter type (e.g. interface FormatRangeArgs {start: number; end: number} then const formatRange = ({start, end}: FormatRangeArgs) =>...). - Reusable across features → put in src/utils/xyz.utils.ts. - Feature-specific → keep next to the component as component-name.utils.ts (same kebab-case base name as the component file, e.g. market-list-item.utils.ts next to market-list-item.tsx).

  1. Extract logic into named hooks

- Move state, effects, and derived logic into hooks (e.g. use-xyz.ts). - Reusable across features → put in src/hooks/use-xyz.ts. - Feature-specific → keep in the feature’s hooks/ subdirectory (e.g. features/market-list/hooks/use-market-filters.ts).

  1. Split the visual layer into sub-components

- If the render/JSX exceeds roughly 40 lines, extract sub-components with clear props and a single responsibility. - Each sub-component should have its own props interface and live in its own file (or a dedicated subfolder) when it grows.


Sections & Example Files

TypeScript / JavaScript

TopicExample FileWhen to load
Variable & function naming (incl. boolean prefixes)examples/typescript/naming.tsWhen naming anything (arrow functions only; booleans: is/has/should/can/will)
Immutability patternsexamples/typescript/immutability.tsWhen working with state/objects/arrays
Error handlingexamples/typescript/error-handling.tsWhen writing async code
Async / Promise patternsexamples/typescript/async-patterns.tsWhen using await/Promise
Type safetyexamples/typescript/type-safety.tsWhen defining interfaces/types (no inline types; no nested types; extract named types)
Control flow & readabilityexamples/typescript/control-flow.tsEarly returns, const vs let, Array.includes/some, nullish coalescing, destructuring

React

TopicExample FileWhen to load
Component structureexamples/react/component-structure.tsxWhen creating a component

Testing

TopicExample FileWhen to load
Unit test patternsexamples/testing/unit-testing-patterns.tsxWhen writing Jest/RTL tests (AAA, screen, spyOn, it.each, getByRole, mock factory)

Anti-patterns (read during code review)

TopicFile
All BAD patterns groupedanti-patterns/what-not-to-do.ts
Code smells detectionanti-patterns/code-smells.ts

File Organization Rules

  • 200–400 lines typical file length
  • 800 lines absolute maximum
  • One responsibility per file (high cohesion, low coupling)
  • File names: always kebab-case (lowercase with hyphens). No PascalCase or camelCase in file or folder names.
components/button.tsx           # kebab-case (not Button.tsx)
hooks/use-auth.ts               # kebab-case (not useAuth.ts)
lib/format-date.ts              # kebab-case (not formatDate.ts)
types/market.types.ts           # kebab-case + optional .types / .utils / .store suffix
features/market-list/market-list-item.tsx
settings-screen.tsx              # e.g. settings-screen.tsx, use-device-discovery.ts

Components and hooks are still exported with PascalCase (components) or camelCase with use prefix (hooks); only the file name is kebab-case.


Code Style / TypeScript

  • TypeScript strict mode — enable in tsconfig.json for maximum type safety.
  • Explicit function signatures — type function parameters and return types explicitly; avoid relying on inference for public APIs.
  • Type inference for locals — prefer inference for local variables when the type is obvious (e.g. const count = 0).

React Components

  • FunctionComponent — type React components with FunctionComponent<Props> (or FC<Props>); use typed props interfaces, not inline or any.
  • Early returns — use early returns in component bodies to keep the main render path flat and readable.
  • Fragment shorthand — use <>...</> instead of <Fragment> unless a key is required.
  • Exports — prefer named exports for components; default export only when required by the framework (e.g. Expo Router).

React Hooks

  • Functions vs hooks — prefer a plain function to a custom hook when you don't need React primitives (state, effects, context).
  • use prefix — use the use prefix only for real hooks; never for plain functions.
  • useMemo / useCallback — avoid for simple computations or callbacks; use when profiling shows a need or when passing callbacks to memoized children.
  • Handlers — use a single arrow function per handler (e.g. const handleClick = () => {...}); avoid function factories that return handlers.
  • Selected items — store selection by ID in state and derive the full item from the list (e.g. selectedItem = items.find(i => i.id === selectedId)); avoids stale references when the list updates.

Data fetching (async: loading, error, data)

  • Prefer TanStack Query — for any async call that involves isLoading, error handling, and result data, use useQuery (or useMutation for writes) instead of manual useState + useEffect. You get caching, deduplication, and consistent loading/error state for free.
  • Query key factory — define a single source of truth for cache keys (e.g. XxxQueryKey.all, XxxQueryKey.list(...), XxxQueryKey.detail(id)). See examples/react/query-keys-example.ts and assets/hook-tanstack-query-template.ts.

Error Handling

  • Context in messages — include a prefix in error and log messages (e.g. [ComponentName] failed to load).
  • Rethrow policy — rethrow only when adding context or transforming the error type; don't rethrow after logging unless the caller needs to handle the failure.

Architecture & Organisation

  • Feature structure — each feature should be self-contained: its own components, hooks/ subdirectory, *.utils.ts and *.types.ts files, and Controllers/Services for complex business logic (e.g. features/scene-3d/, scene-manager/controllers/).
  • Single responsibility — one clear responsibility per file; keep components small and focused. Apply the Avoiding GodComponent (decomposition strategy): utilities first, then hooks, then sub-components when the visual layer exceeds ~40 lines.
  • Composition over inheritance — prefer composing small components and utilities over class inheritance.
  • Group related code — keep related functionality together (e.g. by feature or domain).

Comments

  • Self-documenting first — prefer clear names and structure over comments; comment only when behavior is non-obvious.
  • Explain "why" not "what" — comments should explain rationale, side effects, or workarounds, not restate the code.
  • Keep comments up to date — remove or update comments when code changes.
  • TODO with ticket ID — use a traceable format for TODOs (e.g. // TODO: JIRA-1234 - description).

Logging

  • Logger with levels — use a logger (e.g. logger.info(), logger.error(), logger.warn(), logger.debug()) instead of console.* in client code.
  • Context prefix — include a context prefix in log messages (e.g. [useDeviceDiscovery] storing last known camera IP).
  • Server exceptionconsole.log is acceptable in server-side or API route code for debugging.

Function Parameters

  • Destructuring for multiple params — use object destructuring when a function has more than one parameter (e.g. const fn = ({a, b}: Args) =>...).
  • Extract parameter types — export parameter types as named types/interfaces instead of inline typing.
  • Optional parameters — use param?: Type rather than param: Type | undefined.
  • Defaults in destructuring — set default values in the destructuring when possible (e.g. {page = 1, size = 10}).

TypeScript Best Practices

  • ReactNode for children — use ReactNode for component children (not JSX.Element | null | undefined).
  • PropsWithChildren — use PropsWithChildren<Props> for components that accept children.
  • Record<K, V> — prefer the Record<K, V> utility type over custom index signatures.
  • Array.includes() — use for multiple value checks instead of repeated === comparisons.
  • Array.some() — use for existence checks instead of array.find(...)!== undefined.
  • Explicit enum values — use explicit numeric (or string) values for enums so they survive reordering and serialization.

React Native (when applicable)

When working in a React Native or Expo project:

  • Spacing — prefer gap, rowGap, and columnGap over margin/padding for spacing between elements.
  • Responsive layout — use useWindowDimensions instead of Dimensions.get for layout that reacts to size changes.
  • Static data outside components — move constants and pure functions that don't depend on props or state outside the component to avoid new references on every render.

Pre-output validation

Before returning any code, run the Pre-output Validation checklist.


Templates

Skeletons to copy and adapt (file names in kebab-case):

TypeFileUse when
Hookassets/hook-template.tsCreating a data-fetching or effect hook
Hook (TanStack Query)assets/hook-tanstack-query-template.tsCreating a hook with @tanstack/react-query (queryKey, queryFn, placeholderData)
Componentassets/component-template.tsxCreating a React component
Utilityassets/utils-template.tsCreating pure or side-effect helpers (*.utils.ts)

Validation

Validate this skill's frontmatter and structure with skills-ref:

skills-ref validate ./skills/typescript-and-react-guidelines

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

34.22%
按下载量换算28

Claude

32.24%
按下载量换算27

Cursor

18.25%
按下载量换算15

Gemini CLI

9.77%
按下载量换算8

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills