← Back to Skills Marketplace
liyown

Use Effect

by chenchuying · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ✓ Security Clean
171
Downloads
0
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install use-effect
Description
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...
README (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.

Usage Guidance
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.
Capability Analysis
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.
Capability Assessment
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.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install use-effect
  3. After installation, invoke the skill by name or use /use-effect
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.0
Initial release.
Metadata
Slug use-effect
Version 1.0.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 1
Frequently Asked Questions

What is 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... It is an AI Agent Skill for Claude Code / OpenClaw, with 171 downloads so far.

How do I install Use Effect?

Run "/install use-effect" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is Use Effect free?

Yes, Use Effect is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does Use Effect support?

Use Effect is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created Use Effect?

It is built and maintained by chenchuying (@liyown); the current version is v1.0.0.

💬 Comments