no-use-effect
Skill1 starsChanged 3 days agoMITView on GitHub
ALWAYS ACTIVE in React and React Native repos. Enforces a strict no-direct-useEffect rule. Never write useEffect directly — use derived state, event handlers, useMemo, useSyncExternalStore, data-fetching libraries, key-based resets, or useMountEffect instead. Triggers on all React component code: writing new components, editing existing ones, reviewing code, fixing bugs, or refactoring. Also triggers when user mentions useEffect, side effects, data fetching, state sync, or component lifecycle. Does not apply to non-React code, and a repo's own AGENTS.md rule wins over this default.
14 other projects use a version of this, 8 of them edited.
Adopted by
Most recently taken up by
- caidanw/skillstheir own version, first seen Nov 8, 2026
- elbionredenica/consumer-app-startertheir own version, first seen Nov 8, 2026
- humanlayer/humanlayeredited, first seen Oct 25, 2026
- umangjaipuria/claude-skillsedited, first seen Oct 23, 2026
- jtljrdn/no-use-effectedited, first seen Oct 20, 2026
- mattiacerutti/supernovaedited, first seen Oct 8, 2026
Used with
Projects with it also use improve-codebase-architecture.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
GoogleSkillimprove-codebase-architecture
Scan a codebase for deepening opportunities, present them as a visual HTML report, then grill through whichever one you pick.
Also in 3 projects that use this
Other versions14 projects use a version of this.
Word for word · 0
None found.
Edited · 8
- humanlayer/humanlayer★ 13k16% same
- trycompai/crm★ 12k16% same
- mattiacerutti/supernova★ 19416% same
- darknightdesigner/skills★ 416% same
- GalvinGao/skills★ 116% same
- umangjaipuria/claude-skills★ 116% same
- jtljrdn/no-use-effect★ 016% same
- lankyjo/lankyjo-core-skills★ 016% same
Wrote their own version · 6
- fastrepl/hyprnote★ 9.9ksame name
- fastrepl/anarlog★ 9.8ksame name
- caidanw/skills★ 11same name
- langgenius/mosoo-skills★ 2same name
- CodingCossack/no-use-effect-skill★ 1same name
- elbionredenica/consumer-app-starter★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository22 other files it gives its agents.
- analyze-logsSkill
- architectSkill
- build-audit-logsSkill
- cloudflareSkill
- code-reviewSkill
- design-engineeringSkill
- diagnosing-bugsSkill
- full-sendSkill
- full-stopSkill
- ghSkill
- grillingSkill
- impeccableSkill
- improve-animationsSkill
- interrogateSkill
- prSkill
- retroSkill
- t3-toolsSkill
- triageSkill
- unslopSkill
- vitestSkill
- wait-whatSkill
- writing-for-agentsSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
13 rules. 0 are common, 7 are distinctive, and 6 are very specific to this project.
0
Common
Most of the 14 edited versions we read keep these.
7
Distinctive
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 8
Never call useEffect directly.
- Distinctive: line 25
If you can calculate it from existing state/props, compute it inline.
- Distinctive: line 80
If a user action triggers it, do the work in the handler.
- Distinctive: line 106
Only for true mount-time external system setup: DOM integration, third-party widgets, browser API subscriptions.
- Distinctive: line 128
If you need "start fresh when ID changes," use React's remount semantics.
- Very specific: line 148
If you need a useRef to stop an effect from double-firing, looping, or accessing stale state, the effect itself is the problem.
- Very specific: line 194
Do not use an effect to call onChange — update both in the event handler, or lift state up:
- Very specific: line 209
When an effect needs to read the latest value of a prop/state without re-running when it changes, use useEffectEvent instead of a ref …
- Very specific: line 255
Use useSyncExternalStore instead of manual subscription effects:
- Distinctive: line 267
Run once at module level, not in an effect:
- Distinctive: line 278
Never chain effects that trigger each other.
- Distinctive: line 300
Before writing any effect, answer these questions:
- Very specific: line 311
If none of the above apply and you still think you need useEffect, see references/patterns.md for detailed examples.
“Common” is measured: kept by at least 6 in 10 of the 14 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
No Direct useEffect
Never call useEffect directly. For the rare case of syncing with an external system on mount, use useMountEffect().
This rule is the default in React and React Native code. A repo's own AGENTS.md rule wins when it says otherwise, and it never applies to non-React code.
export function useMountEffect(effect: () => void | (() => void)) {
/* eslint-disable react-hooks/exhaustive-deps, no-restricted-syntax */
useEffect(effect, []);
}The only place useEffect may appear directly is inside reusable custom hooks (like useMountEffect itself, or a useData hook when no fetching library is available). Components must never import or call useEffect.
The 6 Rules
Rule 1: Derive state, do not sync it
If you can calculate it from existing state/props, compute it inline.
// BAD: two render cycles
const [filteredProducts, setFilteredProducts] = useState([]);
useEffect(() => {
setFilteredProducts(products.filter((p) => p.inStock));
}, [products]);
// GOOD: one render
const filteredProducts = products.filter((p) => p.inStock);For expensive calculations, use useMemo:
const visibleTodos = useMemo(
() => getFilteredTodos(todos, filter),
[todos, filter]
);Smell test: You're about to write useEffect(() => setX(f(y)), [y]) or state that only mirrors other state/props.
Rule 2: Use data-fetching libraries
Effect-based fetching creates race conditions and reinvents caching.
// BAD: race condition
useEffect(() => {
fetchProduct(productId).then(setProduct);
}, [productId]);
// GOOD: library handles cancellation/caching/staleness
const { data: product } = useQuery(
['product', productId],
() => fetchProduct(productId)
);In React 19+, use the use() hook with <Suspense> to unwrap promises without useEffect or useState:
// GOOD: use() + Suspense (React 19+)
function UserProfile({ userPromise }: { userPromise: Promise<User> }) {
const user = use(userPromise);
return <h1>{user.name}</h1>;
}Smell test: Your effect does fetch() then setState(), or you're reimplementing caching/retries/cancellation.
Rule 3: Event handlers, not effects
If a user action triggers it, do the work in the handler. Procedural logic (validate → transform → submit) belongs in handlers. Reconstructing procedural flow through ref+effect chains is a sign the logic was event-driven from the start.
// BAD: flag-relay through effect
const [liked, setLiked] = useState(false);
useEffect(() => {
if (liked) { postLike(); setLiked(false); }
}, [liked]);
// GOOD: direct
<button onClick={() => postLike()}>Like</button>For shared logic between handlers, extract a function — not an effect:
function buyProduct() {
addToCart(product);
showNotification(`Added ${product.name}`);
}Smell test: State used as a flag so an effect can do the real action, or "set flag -> effect runs -> reset flag" mechanics.
Rule 4: useMountEffect for one-time external sync
Only for true mount-time external system setup: DOM integration, third-party widgets, browser API subscriptions.
// BAD: guard inside effect
useEffect(() => {
if (!isLoading) playVideo();
}, [isLoading]);
// GOOD: conditional mounting
function VideoPlayerWrapper({ isLoading }) {
if (isLoading) return <LoadingScreen />;
return <VideoPlayer />;
}
function VideoPlayer() {
useMountEffect(() => playVideo());
}Smell test: Behavior is naturally "setup on mount, cleanup on unmount" with an external system.
Rule 5: Reset with key, not dependency choreography
If you need "start fresh when ID changes," use React's remount semantics.
// BAD: effect resets on ID change
useEffect(() => { loadVideo(videoId); }, [videoId]);
// GOOD: key forces clean remount
<VideoPlayer key={videoId} videoId={videoId} />
function VideoPlayer({ videoId }) {
useMountEffect(() => { loadVideo(videoId); });
}This also applies to resetting form state, clearing selections, etc. Use key on the component instead of an effect that sets state to initial values.
Smell test: Effect's only job is to reset local state when an ID/prop changes.
Rule 6: Never patch a broken effect with a ref
If you need a useRef to stop an effect from double-firing, looping, or accessing stale state, the effect itself is the problem. Eliminate the root effect — don't bandage it with a ref.
// BAD: ref guard hides the real problem
const hasRun = useRef(false);
useEffect(() => {
if (hasRun.current) return;
hasRun.current = true;
showWelcomeToast(userId);
}, [userId]);
// GOOD: useMountEffect for true one-time setup
useMountEffect(() => {
showWelcomeToast(userId);
});// BAD: ref to capture latest callback, dodging the dependency array
const onMessageRef = useRef(onMessage);
onMessageRef.current = onMessage;
useEffect(() => {
const conn = createConnection(roomId);
conn.on('message', (msg) => onMessageRef.current(msg));
return () => conn.disconnect();
}, [roomId]);
// GOOD: useEffectEvent (experimental) captures latest values automatically
const onMsg = useEffectEvent((msg) => {
onMessage(msg);
});
useEffect(() => {
const conn = createConnection(roomId);
conn.on('message', onMsg);
return () => conn.disconnect();
}, [roomId]);The React docs explicitly warn: "The right question isn't 'how to run an Effect once', but 'how to fix my Effect so that it works after remounting'."
Smell test: You're adding hasRun.current, isMounted.current, or a ref whose sole purpose is controlling when/if an effect runs. Or you're storing a callback in a ref to avoid listing it as a dependency.
Additional Patterns
Notifying parents about state changes
Do not use an effect to call onChange — update both in the event handler, or lift state up:
// BAD
useEffect(() => { onChange(isOn); }, [isOn, onChange]);
// GOOD: update both during the event
function updateToggle(nextIsOn) {
setIsOn(nextIsOn);
onChange(nextIsOn);
}useEffectEvent for latest values (experimental)
When an effect needs to read the latest value of a prop/state without re-running when it changes, use useEffectEvent instead of a ref workaround:
// BAD: ref to read latest theme without adding it as dependency
const themeRef = useRef(theme);
themeRef.current = theme;
useEffect(() => {
logVisit(url, themeRef.current);
}, [url]);
// GOOD: useEffectEvent reads latest values automatically
const onVisit = useEffectEvent(() => {
logVisit(url, theme);
});
useEffect(() => {
onVisit();
}, [url]);Until useEffectEvent is stable, prefer moving logic to event handlers or useMountEffect. If neither fits, isolate the ref workaround in a custom hook — never in a component.
Callback refs for DOM side effects
For DOM measurement or setup, a callback ref is more reliable than useRef + useMountEffect — it fires exactly when the node attaches or detaches:
// BAD: ref.current may be null on first render
const ref = useRef(null);
useMountEffect(() => {
setHeight(ref.current.getBoundingClientRect().height);
});
return <div ref={ref}>Content</div>;
// GOOD: callback ref fires when node is attached
const measuredRef = useCallback((node: HTMLDivElement | null) => {
if (node !== null) {
setHeight(node.getBoundingClientRect().height);
}
}, []);
return <div ref={measuredRef}>Content</div>;In React 19+, callback refs support cleanup return values. For earlier versions, store cleanup logic in a ref inside a custom hook.
Subscribing to external stores
Use useSyncExternalStore instead of manual subscription effects:
const isOnline = useSyncExternalStore(
subscribe,
() => navigator.onLine,
() => true
);App initialization
Run once at module level, not in an effect:
if (typeof window !== 'undefined') {
checkAuthToken();
loadDataFromLocalStorage();
}Chains of computations
Never chain effects that trigger each other. Derive values inline and batch state updates in the event handler:
// BAD: 3 effects chaining state -> 3 extra renders
useEffect(() => { if (card?.gold) setGoldCardCount(c => c + 1); }, [card]);
useEffect(() => { if (goldCardCount > 3) { setRound(r => r + 1); setGoldCardCount(0); } }, [goldCardCount]);
useEffect(() => { if (round > 5) setIsGameOver(true); }, [round]);
// GOOD: derive + handle in event
const isGameOver = round > 5;
function handlePlaceCard(nextCard) {
setCard(nextCard);
if (nextCard.gold) {
if (goldCardCount < 3) setGoldCardCount(goldCardCount + 1);
else { setGoldCardCount(0); setRound(round + 1); }
}
}Decision Checklist
Before writing any effect, answer these questions:
- Can I compute it during render? -> Derive it inline or
useMemo - Is it triggered by a user action? -> Event handler
- Am I fetching data? -> Data-fetching library (React Query, SWR, etc.) or
use()+ Suspense in React 19+ - Am I subscribing to an external store? ->
useSyncExternalStore - Do I need to reset state when a prop changes? ->
keyprop - Is it true mount-time external system sync? ->
useMountEffect - Am I using refs to control when/if an effect runs? -> Remove the refs; move logic to an event handler, derive it, or use
useEffectEvent - Do I need a DOM side effect when a node mounts? -> Callback ref
If none of the above apply and you still think you need useEffect, see references/patterns.md for detailed examples.
Failure Modes
- useMountEffect failures are binary and loud: it ran once, or not at all
- Direct useEffect failures degrade gradually as flaky behavior, perf issues, or loops before a hard crash
Choose the bug that's easy to find.
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
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.

