Agent Skills › simstudioai/sim › you-might-not-need-state

you-might-not-need-state

GitHub

分析并修复 React 中不必要的 useState、派生状态及服务端数据本地化等反模式,确保状态管理符合最佳实践。

.agents/skills/you-might-not-need-state/SKILL.md simstudioai/sim

触发场景

审查代码中的状态使用方式 检查是否误用 useState 存储派生或服务器数据

安装

npx skills add simstudioai/sim --skill you-might-not-need-state -g -y
更多选项

非标准路径

npx skills add https://github.com/simstudioai/sim/tree/main/.agents/skills/you-might-not-need-state -g -y

不安装直接使用

npx skills use simstudioai/sim@you-might-not-need-state

指定 Agent (Claude Code)

npx skills add simstudioai/sim --skill you-might-not-need-state -a claude-code -g -y

安装 repo 全部 skill

npx skills add simstudioai/sim --all -g -y

预览 repo 内 skill

npx skills add simstudioai/sim --list

SKILL.md

Frontmatter
{
    "name": "you-might-not-need-state",
    "description": "Analyze and fix unnecessary useState, derived state, and server-state-in-local-state anti-patterns",
    "argument-hint": "[scope] [fix=true|false]"
}

You Might Not Need State

Arguments:

  • scope: what to analyze (default: your current changes). Examples: "diff to staging", "PR #123", "src/components/", "whole codebase"
  • fix: whether to apply fixes (default: true). Set to false to only propose changes.

User arguments: $ARGUMENTS

Context

React Query owns server data, nuqs (URL) owns shareable view-state (tabs, filters, search, sort, pagination, selected id), Zustand owns global client state, and useState owns only ephemeral UI (open/closed, hover, local form input). Server data should never be copied into useState or Zustand — React Query is the single source of truth.

References

Read these before analyzing:

  1. https://react.dev/learn/choosing-the-state-structure — 5 principles for structuring state
  2. https://tkdodo.eu/blog/dont-over-use-state — never store derived/computed values in state
  3. https://tkdodo.eu/blog/putting-props-to-use-state — never mirror props into state via useEffect

Anti-patterns to detect

  1. Derived state stored in useState: If a value can be computed from props, other state, or query data, compute it inline during render instead of storing it in state.
  2. Server state copied into useState: Never useState + useEffect to sync React Query data into local state. Use query data directly. The only exception is forms where users edit server data.
  3. Props mirrored into state: Never useState(prop) + useEffect(() => setState(prop)). Use the prop directly, reset with a remount key, or — for seed-on-transition (e.g. a modal opening) — adjust during render with the useState prev-tracker in .claude/rules/sim-hooks.md "State shape" (mind its sentinel-on-mount and no-useRef rules).
  4. Chained useEffect state updates: Never chain Effects that set state to trigger other Effects. Calculate all derived values in the event handler or inline during render.
  5. Storing objects when an ID suffices: Store selectedId not a copy of the selected object. Derive the object: items.find(i => i.id === selectedId).
  6. State that duplicates Zustand or React Query: If the data already lives in a store or query cache, don't create a parallel useState.
  7. Shareable view-state in useState: hand off to /you-might-not-need-url-state.

Steps

  1. Read the references above to understand the guidelines
  2. Analyze the specified scope for the anti-patterns listed above
  3. If fix=true, apply the fixes. If fix=false, propose the fixes without applying.

版本历史

  • c6cef5f 当前 2026-10-20 02:39

    更新上下文描述,明确区分 React Query、nuqs、Zustand 与 useState 的职责边界。

  • 6dfb467 2026-09-23 06:37

    移除过时的反模式描述,修正关于 Provider 矩阵和仓库特定声明的准确性,减少提示词冗余。

  • ceda457 2026-08-20 15:30

同 Skill 集合

.agents/skills/add-block-preview/SKILL.md
.agents/skills/add-block/SKILL.md
.agents/skills/add-column-type/SKILL.md
.agents/skills/add-connector/SKILL.md
.agents/skills/add-enrichment/SKILL.md
.agents/skills/add-feature-flag/SKILL.md
.agents/skills/add-hosted-key/SKILL.md
.agents/skills/add-integration/SKILL.md
.agents/skills/add-managed-cli/SKILL.md
.agents/skills/add-model/SKILL.md
.agents/skills/add-permission-group-item/SKILL.md
.agents/skills/add-selector/SKILL.md
.agents/skills/add-settings-page/SKILL.md
.agents/skills/add-tools/SKILL.md
.agents/skills/add-trigger/SKILL.md
.agents/skills/babysit/SKILL.md
.agents/skills/cleanup/SKILL.md
.agents/skills/council/SKILL.md
.agents/skills/db-migrate/SKILL.md
.agents/skills/design-taste-frontend/SKILL.md
.agents/skills/emcn-design-review/SKILL.md
.agents/skills/emil-design-eng/SKILL.md
.agents/skills/make-interfaces-feel-better/SKILL.md
.agents/skills/memory-load-check/SKILL.md
.agents/skills/react-query-best-practices/SKILL.md
.agents/skills/ship/SKILL.md
.agents/skills/test-audit/SKILL.md
.agents/skills/tool-registry-boundary/SKILL.md
.agents/skills/v2-api-conventions/SKILL.md
.agents/skills/validate-connector/SKILL.md
.agents/skills/validate-integration/SKILL.md
.agents/skills/validate-model/SKILL.md
.agents/skills/validate-permission-group-item/SKILL.md
.agents/skills/validate-selector/SKILL.md
.agents/skills/validate-trigger/SKILL.md
.agents/skills/you-might-not-need-a-callback/SKILL.md
.agents/skills/you-might-not-need-a-comment/SKILL.md
.agents/skills/you-might-not-need-a-memo/SKILL.md
.agents/skills/you-might-not-need-an-effect/SKILL.md
.agents/skills/you-might-not-need-url-state/SKILL.md
.claude/skills/add-settings-page/SKILL.md
helm/sim/.claude/skills/sim-helm/SKILL.md
.agents/skills/migrate-application-operation/SKILL.md

元信息

文件数
0
版本
c6cef5f
Hash
c722918c
收录时间
2026-08-20 15:30

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.156.0. UTC+08:00, 2026-11-21 16:27
浙ICP备14020137号-1