← 返回 Skills 市场
liyown

Use Effect

作者 chenchuying · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ 安全检测通过
171
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install use-effect
功能描述
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...
使用说明 (SKILL.md)

Use Effect

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

  1. Locate every direct useEffect in the relevant scope and classify why it exists.
  2. 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
  3. Replace the effect with the narrowest alternative pattern.
  4. Preserve existing project conventions. If the codebase already has useMountEffect, use it instead of raw useEffect(..., []).
  5. 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 \x3CLoadingScreen />;
return \x3CVideoPlayer />;

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 \x3CVideoPlayer key={videoId} videoId={videoId} />;

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.

安全使用建议
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 review model-invoked actions in your agent settings before granting write access.
功能分析
Type: OpenClaw Skill Name: use-effect Version: 1.0.0 The skill bundle provides legitimate architectural guidance and refactoring patterns for React development, specifically aimed at reducing direct useEffect usage in favor of derived state, data-fetching abstractions, and event handlers. The instructions in SKILL.md and references/patterns.md are consistent with modern React best practices and contain no evidence of malicious intent, data exfiltration, or unauthorized execution.
能力评估
Purpose & Capability
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.
Instruction Scope
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.
Install Mechanism
Instruction-only skill with no install spec and no code files to execute. There is nothing downloaded or written by an installer step.
Credentials
The skill requests no environment variables, credentials, or config paths. No broad or unrelated secrets are requested.
Persistence & Privilege
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.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install use-effect
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /use-effect 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release.
元数据
Slug use-effect
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

Use Effect 是什么?

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... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 171 次。

如何安装 Use Effect?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install use-effect」即可一键安装,无需额外配置。

Use Effect 是免费的吗?

是的,Use Effect 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

Use Effect 支持哪些平台?

Use Effect 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Use Effect?

由 chenchuying(@liyown)开发并维护,当前版本 v1.0.0。

💬 留言讨论