Token导航 LogoToken导航

Agent Skill · 前端设计

no-use-effect(没有使用效果)

no-use-effect 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

no-use-effect 是前端设计类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为操作浏览器;许可证信息还不明确,第三方扫描已通过,按安装量在前端设计类的 10,216 个 Skill 里排第 7,287。

总安装 392周安装 16GitHub Stars 公开资料未说明下载 127核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

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

请帮我安装这个 Agent Skill:no-use-effect(没有使用效果)
来源仓库:https://github.com/caidanw/skills
仓库路径:skills/no-use-effect
安装命令:
npx skills add https://github.com/caidanw/skills --skill no-use-effect
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

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

skills.shnpx skills
npx skills add https://github.com/caidanw/skills --skill no-use-effect

这个 Skill 是做什么的

前端设计类 Skill 关注页面结构、视觉规范和组件写法,输出通常是可运行的界面代码。

no-use-effect 主张最大限度避免 raw useEffect,将逻辑尽量置于 render 或事件处理器中。适用于 React 项目,减少副作用带来的依赖混乱与无限循环风险。提倡使用框架提供的数据流 API(如 SWR、React Query)替代手动同步。

使用前请团队统一 useEffect 使用边界,必要时引入 ESLint 插件辅助管控。遗留代码改造应逐步推进,优先处理高频变更组件以避免大规模重构。

来源仓库内路径:skills/no-use-effect

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/caidanw/skills --skill no-use-effect;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要操作浏览器,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

no-use-effect 怎么安装?

在终端执行 npx skills add https://github.com/caidanw/skills --skill no-use-effect。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

no-use-effect 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

no-use-effect 需要什么权限?

权限级别是操作浏览器。该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

no-use-effect 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

no-use-effect 用的人多吗?

公开数据是累计安装 392 次,近一周安装 16 次,下载 127 次。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

no-use-effect 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理前端设计类任务、又不想每次都手写提示词的人。

不太适合

  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

前端设计类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
frontend-design

前端设计 · Codex、Claude

8,823,360126,072只读MIT通过
vercel-composition-patterns

Vercel 组合模式 · Codex、Claude

3,858,81625,893需要联网MIT通过
vercel-react-native-skills

Vercel React native skills 前端 · Codex、Claude

2,468,66425,878只读MIT通过
adapt

adapt 搜索 · Codex、Claude

2,027,04023,125操作浏览器未明确通过
bolder

bolder 分析 · Codex、Claude

2,004,28823,130只读未明确通过
no-use-effect

没有使用效果 · 本页

392—操作浏览器未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

No useEffect

Treat raw useEffect as a last resort, not a default tool. Most component logic belongs in render, event handlers, framework data APIs, or narrower React primitives.

This skill is based primarily on the React docs (You Might Not Need an Effect, Synchronizing with Effects, Removing Effect Dependencies), with supporting guidance from Dan Abramov, Kent C. Dodds, TkDodo, and team practices that ban or heavily restrict raw useEffect.

Core Rule

Before adding an Effect, answer this question:

"What external system am I synchronizing with, and why can't this be done during render, in an event handler, or with a more specific primitive?"

If you cannot name the external system, do not write the Effect.

External systems include:

  • browser APIs and DOM subscriptions
  • timers, sockets, observers, media APIs
  • third-party widgets and imperative libraries
  • network synchronization that truly happens because the component is visible

Not external systems:

  • derived values from props or state
  • event-driven actions like submit, save, buy, delete, notify
  • resetting local state because props changed
  • chaining state updates to trigger more state updates
  • passing data upward just because a child rendered

Replacement Patterns

1. Derive during render

Do not mirror props or state into more state.

// Bad
const [fullName, setFullName] = useState("");
useEffect(() => {
  setFullName(`${firstName} ${lastName}`);
}, [firstName, lastName]);

// Good
const fullName = `${firstName} ${lastName}`;

Use this for filtered lists, labels, counts, booleans, selected objects, and other values that can be computed from current inputs.

2. Memoize expensive pure work

If the calculation is slow, cache it with useMemo. Do not use an Effect that immediately calls setState with a computed value.

const visibleTodos = useMemo(() => getVisibleTodos(todos, filter), [todos, filter]);

First ask whether the work is actually expensive. If not, calculate it directly during render.

3. Put user actions in event handlers

If the code runs because the user clicked, submitted, selected, dragged, or typed, keep it in the corresponding handler.

// Bad
useEffect(() => {
  if (shouldSubmit) {
    void saveForm(form);
  }
}, [shouldSubmit, form]);

// Good
async function handleSubmit() {
  await saveForm(form);
}

Never build "set flag -> Effect notices flag -> Effect does the real work" flows unless the flag is synchronizing with a real external system.

4. Reset identity with key when you want a fresh instance

If a component should become a brand-new instance when some identity changes, give it a different key. React will unmount the old subtree and mount a new one, which resets all local state below that point without an Effect.

// Bad
function Profile({ userId }: { userId: string }) {
  const [comment, setComment] = useState("");

  useEffect(() => {
    setComment("");
  }, [userId]);

  return <input value={comment} onChange={(e) => setComment(e.target.value)} />;
}

// Good
function ProfilePage({ userId }: { userId: string }) {
  return <Profile key={userId} userId={userId} />;
}

function Profile({ userId }: { userId: string }) {
  const [comment, setComment] = useState("");
  return <input value={comment} onChange={(e) => setComment(e.target.value)} />;
}

Use this when the identity really changed: user, document, chat room, wizard step, or form instance. Do not use it when you only want to tweak one field, because remounting resets the entire subtree.

5. Lift state or control the component

If an Effect exists only to notify a parent after local state changed, the data model is usually wrong. Prefer lifting state up or updating both sides in the same event.

// Bad
function Toggle({ onChange }: { onChange: (next: boolean) => void }) {
  const [isOn, setIsOn] = useState(false);

  useEffect(() => {
    onChange(isOn);
  }, [isOn, onChange]);

  return <button onClick={() => setIsOn(!isOn)}>{isOn ? "On" : "Off"}</button>;
}

// Good
function Toggle({ isOn, onChange }: { isOn: boolean; onChange: (next: boolean) => void }) {
  return <button onClick={() => onChange(!isOn)}>{isOn ? "On" : "Off"}</button>;
}

6. Use useSyncExternalStore for external subscriptions

Use useSyncExternalStore when the source of truth lives outside React and changes over time. This is React's built-in primitive for subscribing to external stores.

Good fits:

  • browser APIs with a current value plus subscription events
  • third-party or app-level stores outside React state
  • reusable hooks like useOnlineStatus() or useMediaQuery()

The shape is:

const value = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);

Where:

  • subscribe tells React how to listen for changes and return cleanup
  • getSnapshot reads the current value from the external store
  • getServerSnapshot provides the initial server and hydration value when SSR is involved
// Bad
function useOnlineStatus() {
  const [isOnline, setIsOnline] = useState(true);

  useEffect(() => {
    function updateStatus() {
      setIsOnline(navigator.onLine);
    }

    updateStatus();
    window.addEventListener("online", updateStatus);
    window.addEventListener("offline", updateStatus);

    return () => {
      window.removeEventListener("online", updateStatus);
      window.removeEventListener("offline", updateStatus);
    };
  }, []);

  return isOnline;
}

// Good
const isOnline = useSyncExternalStore(subscribe, () => navigator.onLine, () => true);

Prefer this over hand-rolled subscription Effects in components.

Important caveats from the React docs:

  • getSnapshot must return a stable cached value unless the store actually changed
  • if subscribe changes identity every render, React will resubscribe every render
  • if you support SSR, getServerSnapshot must match between server render and hydration

Do not use this for:

  • normal component state that should live in useState, useReducer, or context
  • derived values you can calculate during render
  • user actions handled by event handlers
  • one-time fetching
  • general side effects that are not subscriptions

7. Fetch through the framework or a data library

Avoid raw fetch-in-Effect code in app components when a framework loader or query library is available.

Preferred order:

  1. framework data APIs (Next.js, React Router, Remix, server components, route loaders)
  2. data libraries (TanStack Query, SWR)
  3. a focused custom hook
  4. raw useEffect only if none of the above fit

If you must fetch in an Effect, handle cleanup so stale responses are ignored.

// Bad
useEffect(() => {
  void fetchResults(query).then(setResults);
}, [query]);

// Good
useEffect(() => {
  let ignore = false;

  void fetchResults(query).then((next) => {
    if (!ignore) {
      setResults(next);
    }
  });

  return () => {
    ignore = true;
  };
}, [query]);

8. Encapsulate unavoidable imperative synchronization

Sometimes an Effect is correct: sockets, observers, widgets, media controls, focus management, layout measurement, or DOM APIs that must stay in sync with rendered output.

When that happens:

  • keep the Effect tiny and specific
  • name the external system in a comment or hook name
  • include full cleanup
  • prefer a custom hook over open-coded Effect logic in many components
  • consider useLayoutEffect only for pre-paint measurement or visual correctness
// Bad
function ChatRoom({ roomId }: { roomId: string }) {
  useEffect(() => {
    const connection = createConnection(roomId);
    connection.connect();
  }, [roomId]);
}

// Good
function useChatConnection(roomId: string) {
  useEffect(() => {
    const connection = createConnection(roomId);
    connection.connect();

    return () => {
      connection.disconnect();
    };
  }, [roomId]);
}

If your team bans raw useEffect, put these escape hatches behind approved hooks instead of sprinkling Effects through feature code.

Anti-Patterns

Treat these as red flags during authoring or review:

  • useEffect(() => setX(...), [...]) for derived state
  • Effect only exists to call a function after a button click
  • effect chains where one state update triggers another Effect and another render
  • dependency arrays fought with eslint-disable, refs-as-flags, or intentionally stale closures
  • object or function dependencies recreated every render without need
  • child component fetching data and pushing it upward in an Effect
  • mount-only initialization that should live in module scope, entrypoints, or framework boot code

Review Checklist

Before accepting a new Effect, verify all of these:

  • The code synchronizes with a real external system
  • Derived render data, memoization, events, key, lifted state, and useSyncExternalStore were all considered first
  • The dependency list is honest and complete
  • Setup and cleanup are symmetrical
  • The Effect is idempotent under Strict Mode re-mounting
  • Data fetching is not bypassing an existing framework or query abstraction
  • The logic is small enough that a custom hook or helper name explains its purpose

Team Policy

For teams trying to ban or heavily restrict raw useEffect, use this policy:

  1. Do not introduce useEffect for derived state, events, or resets.
  2. Prefer render-time derivation, event handlers, key, useMemo, and useSyncExternalStore.
  3. Route data loading through the framework or an approved query library.
  4. If an Effect is still necessary, hide it behind a narrowly named custom hook or document the external system and cleanup explicitly in review.
  5. Never silence react-hooks/exhaustive-deps to "make it work".

References

For source material and further reading, see references/sources.md.

平台分布

Codex

39.05%
按下载量换算50

Claude

29.55%
按下载量换算38

Cursor

19.86%
按下载量换算25

Gemini CLI

9.34%
按下载量换算12

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

操作浏览器

该 Skill 可能涉及浏览器控制能力,使用时可能读取或操作网页内容,需要在受控环境中确认权限边界。

安装前确认

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

继续浏览同类 Skills