首页龙虾技能列表 › Use Effect — 技能工具

Use Effect — 技能工具

v1.0.0

Refactor React code away from direct useEffect usage. Use when Codex needs to review, rewrite, or prevent useEffect in React components, custom hooks, or fro...

0· 131·0 当前·0 累计
by @liyown (chenchuying)·MIT-0
下载技能包
License
MIT-0
最后更新
2026/3/18
安全扫描
VirusTotal
无害
查看报告
OpenClaw
安全
high confidence
The skill's instructions, scope, and resource requirements are consistent with its stated purpose of refactoring away from direct useEffect usage in React code; it requests no credentials or installs and only operates on project source, which is expected.
评估建议
This skill appears coherent and focused: it will inspect and suggest (or make) source-code changes related to useEffect patterns, and may recommend lint or documentation updates. Before installing, ensure you: (1) trust the agent to read your repository files, (2) review any code edits or pull requests the skill proposes, (3) run your tests/CI on changes, and (4) avoid giving it access to repositories containing secrets you don't want examined. If you want to prevent autonomous edits, disable or...
详细分析 ▾
用途与能力
Name and description match the instructions: the skill's only purpose is to find and replace or advise about useEffect patterns in React code. It does not declare unrelated binaries, env vars, or external services.
指令范围
SKILL.md tells the agent to locate and inspect useEffect occurrences, classify them, and replace them with narrower patterns; it also recommends running tests and updating lint/docs when rolling out changes. Reading and modifying project source is expected for this purpose — users should know the agent will examine repository files and may propose or apply code changes.
安装机制
Instruction-only skill with no install spec and no code files to execute. There is nothing downloaded or written by an installer step.
凭证需求
The skill requests no environment variables, credentials, or config paths. No broad or unrelated secrets are requested.
持久化与权限
always is false and the skill does not request persistent system-level privileges. It does suggest modifying project lint/docs, which is appropriate for its purpose; autonomous invocation is allowed by default but not excessive here.
安全有层次,运行前请审查代码。

License

MIT-0

可自由使用、修改和再分发,无需署名。

运行时依赖

无特殊依赖

版本

latestv1.0.02026/3/18

Initial release.

● 无害

安装命令 点击复制

官方npx clawhub@latest install use-effect
镜像加速npx clawhub@latest install use-effect --registry https://cn.clawhub-mirror.com

技能文档

Inspect the local React patterns before changing code. Prefer the project's existing data-fetching library, lifecycle wrapper, and lint setup over introducing new abstractions.

Treat direct useEffect as a code smell by default. Replace it with clearer control flow unless the code is genuinely synchronizing with an external system on mount or unmount.

Workflow

  • Locate every direct useEffect in the relevant scope and classify why it exists.
  • Decide whether the effect is:
- deriving state from props or state - fetching data - relaying an action that should happen in response to a user event - synchronizing with an external system on mount - resetting local state when an identity changes
  • Replace the effect with the narrowest alternative pattern.
  • Preserve existing project conventions. If the codebase already has useMountEffect, use it instead of raw useEffect(..., []).
  • Verify behavior by running the relevant tests or targeted checks. Pay special attention to loops, duplicate requests, stale state, and remount semantics.

Replacement Rules

Derive State, Do Not Sync It

If an effect sets state from other props or state, compute the value during render instead.

Common smell:

useEffect(() => {
  setFilteredProducts(products.filter((p) => p.inStock));
}, [products]);

Preferred direction:

const filteredProducts = products.filter((p) => p.inStock);

Also collapse multi-step derived values instead of chaining effects through intermediary state.

Use Data-Fetching Abstractions

If an effect fetches data and then writes it into local state, prefer the project's query or loader abstraction. Reuse the codebase's existing library when present.

Common smell:

useEffect(() => {
  fetchProduct(productId).then(setProduct);
}, [productId]);

Preferred direction:

const { data: product } = useQuery({
  queryKey: ["product", productId],
  queryFn: () => fetchProduct(productId),
});

If the project does not already use a client-side query library, check whether the fetch belongs in framework loaders, server components, or route-level data APIs before adding one.

Use Event Handlers, Not Effect Relays

If state is only used as a flag to make an effect do work later, move that work into the event handler that caused it.

Common smell:

useEffect(() => {
  if (liked) {
    postLike();
    setLiked(false);
  }
}, [liked]);

Preferred direction:

const handleLike = () => {
  postLike();
};

Use Mount-Only Effects Only for External Sync

For true setup and cleanup with external systems, use the project's mount-only wrapper if it exists. Keep this category narrow: DOM integration, subscriptions, widget lifecycle, imperative browser APIs.

If a precondition gates the mount-only effect, prefer conditional rendering so the component mounts only when ready.

if (isLoading) return ;
return ;

Then let VideoPlayer run mount-only setup once.

Reset with key, Not Dependency Choreography

If the goal is "treat this as a new instance when identity changes", remount with key instead of writing effect logic that tries to reset local state.

return ;

Use this when the desired behavior is a fresh lifecycle boundary.

Code Review Heuristics

Flag direct useEffect when you see:

  • setState driven by props or other state
  • fetch(...).then(setState) or async loading logic inside an effect
  • state used as an action flag
  • dependency arrays that are being "fixed" incrementally
  • effect chains where one effect updates state that triggers another effect
  • logic that really wants remount semantics

Do not remove mount-only effects that are genuinely integrating with external systems unless you replace them with an equivalent lifecycle boundary.

Adoption Guidance

When the user asks for a broader rollout:

  • Add or update lint rules that ban direct useEffect.
  • Add a local wrapper such as useMountEffect only if the codebase wants an explicit exception path.
  • Update agent guidance or contributor docs so future edits do not reintroduce direct effects.
  • Prefer incremental refactors around touched files unless the user asks for a full migration.

References

Read patterns.md when you need detailed smell tests, larger before/after examples, or help choosing between replacement patterns.

数据来源:ClawHub ↗ · 中文优化:龙虾技能库
OpenClaw 技能定制 / 插件定制 / 私有工作流定制

免费技能或插件可能存在安全风险,如需更匹配、更安全的方案,建议联系付费定制

了解定制服务