agentleFS
theoklitosBam7theoklitosBam7/skills/react-useeffect-guide/SKILL.md

react-useeffect-guide

Skill1 starsChanged 5 months agoMITView on GitHub

Effect discipline for React code. Use when writing, reviewing, or refactoring useEffect, cleanup functions, dependency arrays, useLayoutEffect, data fetching in Effects, or synchronization with external systems.

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 4 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    If there is no external system, replace the Effect with the React-native shape:

    line 27
  2. Distinctive:

    Complete when: every Effect has a named external system, or has been replaced with a non-Effect shape.

    line 38
  3. Distinctive:

    Complete when: every subscription, timer, listener, observer, connection, request guard, or widget setup has a matching teardown or …

    line 60
  4. Very specific:

    Do not suppress react-hooks/exhaustive-deps.

    line 71
  5. Distinctive:

    Prefer framework loading, route loaders, or cache libraries such as TanStack Query/SWR.

    line 81
  6. Very specific:

    Use useLayoutEffect only for visual DOM reads/writes where a paint before the Effect would cause visible flicker.

    line 106

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

React useEffect Guide

Golden rule

useEffect is for synchronizing a component with an external system. If no external system is involved, remove the Effect.

External systems include browser APIs, network connections, timers, third-party widgets, external stores, and raw data fetching when a framework or cache library is not available.

Workflow

1. Classify the Effect

For each Effect, name the external system it synchronizes with.

If there is no external system, replace the Effect with the React-native shape:

  • Derived value → calculate during render, or useMemo only when measurement shows the calculation is expensive.
  • User-triggered work → event handler.
  • Reset on identity change → split the component and pass key.
  • Parent/sibling synchronization → lift state or update both states in the same event.
  • External store subscription → useSyncExternalStore.
  • Repeated Effect pattern → custom hook.

Complete when: every Effect has a named external system, or has been replaced with a non-Effect shape.

2. Make setup and cleanup symmetrical

A valid Effect has one setup story and, when setup creates ongoing work, a cleanup that mirrors it:

useEffect(() => {
  const connection = createConnection(serverUrl, roomId);
  connection.connect();

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

Cleanup-only Effects are suspicious. In Strict Mode, setup → cleanup → setup runs once extra in development; the user should not be able to tell.

Complete when: every subscription, timer, listener, observer, connection, request guard, or widget setup has a matching teardown or cancellation guard.

3. Prove the dependencies

Dependencies are not chosen; they are determined by the reactive values read by the Effect: props, state, and variables/functions declared inside the component.

Rules:

  • List every reactive value used by the Effect.
  • Do not suppress react-hooks/exhaustive-deps; change the code instead.
  • To remove a dependency, remove the reactive read: move object/function creation inside the Effect, use a functional state updater, or separate non-reactive logic with the project-approved Effect Event pattern.

Complete when: the dependency array matches the Effect body and the hooks linter would not need suppression.

4. Handle data fetching deliberately

Prefer framework loading, route loaders, or cache libraries such as TanStack Query/SWR. Use raw Effect fetching only when those are not in scope.

Raw Effect fetching needs a stale-response guard:

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

  async function fetchData() {
    const result = await fetchBio(person);
    if (!ignore) setBio(result);
  }

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

Complete when: fetch responses cannot update state after being superseded, and any missing caching, SSR, deduplication, or waterfall concern has been called out.

5. Escalate only when needed

Use useLayoutEffect only for visual DOM reads/writes where a paint before the Effect would cause visible flicker. Otherwise use useEffect.

Extract a custom hook when the same synchronization pattern appears in more than one component, or when hiding imperative setup makes the component declarative.

Complete when: the hook choice is justified by observable behavior, not habit.

Reference pointer

For examples of anti-patterns, dependency repairs, cleanup pairs, custom hooks, and server-rendering caveats, read references/useeffect-patterns.md only when a case needs that detail.

Sources

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.