no-use-effect
Skill9 starsChanged 4 months agoMITView on GitHub
Prevent unnecessary React `useEffect` usage by steering code toward derived state, event handlers, memoization, `key`-based resets, `useSyncExternalStore`, and framework or query-library data APIs. Use when writing or reviewing React/Next.js components, refactoring effect-heavy code, or when a change introduces `useEffect`, `useLayoutEffect`, or dependency-array churn. Triggers on: "avoid useEffect", "remove useEffect", "you might not need an effect", "effect dependencies", "derived state", "React side effects".
6 other projects use a version of this.
Adopted by
Most recently taken up by
- darknightdesigner/skillstheir own version, first seen Oct 2, 2026
- umangjaipuria/claude-skillstheir own version, first seen Sep 29, 2026
- lankyjo/lankyjo-core-skillstheir own version, first seen Jul 2, 2026
- langgenius/mosoo-skillstheir own version, first seen Jun 4, 2026
- GalvinGao/skillstheir own version, first seen Mar 18, 2026
- gokulkrishh/skillstheir own version, first seen Mar 8, 2026
Other versions6 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 6
- gokulkrishh/skills★ 3same name
- darknightdesigner/skills★ 2same name
- langgenius/mosoo-skills★ 2same name
- GalvinGao/skills★ 1same name
- umangjaipuria/claude-skills★ 1same name
- lankyjo/lankyjo-core-skills★ 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 repository25 other files it gives its agents.
- adversarial-reviewSkill
- agent-first-repoSkill
- agents-mdSkill
- architecture-mdSkill
- behavioral-testingSkill
- cleanup-swiftSkill
- cleanup-webSkill
- clear-communicationSkill
- code-commentsSkill
- design-patterns-gofSkill
- design-systemSkill
- distill-to-skillSkill
- git-safe-pr-workflowSkill
- git-worktreeSkill
- karpathy-guidelinesSkill
- lean-ts-patternsSkill
- macos-swift-desktopSkill
- modern-cssSkill
- parse-dont-validateSkill
- pr-review-triageSkill
- simplifySkill
- technical-writingSkill
- typescript-refactoringSkill
- typescriptSkill
- update-readmeSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
28 rules. 0 are common, 17 are distinctive, and 11 are very specific to this project.
0
Common
Most of the 6 edited versions we read keep these.
17
Distinctive
This author's own choices. Worth a look.
11
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 15
Treat raw useEffect as a last resort, not a default tool.
- Distinctive: line 25
Before adding an Effect, answer this question:
- Distinctive: line 30
If you cannot name the external system, do not write the Effect.
- Distinctive: line 49
Do not mirror props or state into more state.
- Distinctive: line 62
Use this for filtered lists, labels, counts, booleans, selected objects, and other values that can be computed from current inputs.
- Very specific: line 67
If the calculation is slow, cache it with useMemo.
- Distinctive: line 78
If the code runs because the user clicked, submitted, selected, dragged, or typed, keep it in the corresponding handler.
- Distinctive: line 95
Never build "set flag -> Effect notices flag -> Effect does the real work" flows unless the flag is synchronizing with a real external …
- Very specific: line 100
If a component should become a brand-new instance when some identity changes, give it a different key.
- Distinctive: line 127
Use this when the identity really changed: user, document, chat room, wizard step, or form instance.
- Distinctive: line 133
If an Effect exists only to notify a parent after local state changed, the data model is usually wrong.
- Very specific: line 156
Use useSyncExternalStore when the source of truth lives outside React and changes over time.
- Distinctive: line 202
Prefer this over hand-rolled subscription Effects in components.
- Very specific: line 206
if subscribe changes identity every render, React will resubscribe every render
- Very specific: line 207
if you support SSR, getServerSnapshot must match between server render and hydration
- Distinctive: line 209
Do not use this for:
- Distinctive: line 218
Avoid raw fetch-in-Effect code in app components when a framework loader or query library is available.
- Distinctive: line 227
If you must fetch in an Effect, handle cleanup so stale responses are ignored.
- Distinctive: line 257
keep the Effect tiny and specific
- Distinctive: line 260
prefer a custom hook over open-coded Effect logic in many components
- Very specific: line 261
consider useLayoutEffect only for pre-paint measurement or visual correctness
- Very specific: line 285
If your team bans raw useEffect, put these escape hatches behind approved hooks instead of sprinkling Effects through feature code.
- Distinctive: line 290
Treat these as red flags during authoring or review:
- Distinctive: line 301
Before accepting a new Effect, verify all of these:
- Very specific: line 315
Do not introduce useEffect for derived state, events, or resets.
- Very specific: line 316
Prefer render-time derivation, event handlers, key, useMemo, and useSyncExternalStore.
- Distinctive: line 318
If an Effect is still necessary, hide it behind a narrowly named custom hook or document the external system and cleanup explicitly in …
- Very specific: line 320
Never silence react-hooks/exhaustive-deps to "make it work".
“Common” is measured: kept by at least 6 in 10 of the 6 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 useEffect
Treat raw useEffect as a last resort, not a default tool. Most component logic belongs in
render, event handlers, framework data APIs, or narrower React primitives.
This skill is based primarily on the React docs (You Might Not Need an Effect,
Synchronizing with Effects, Removing Effect Dependencies), with supporting guidance from
Dan Abramov, Kent C. Dodds, TkDodo, and team practices that ban or heavily restrict raw
useEffect.
Core Rule
Before adding an Effect, answer this question:
"What external system am I synchronizing with, and why can't this be done during render, in an event handler, or with a more specific primitive?"
If you cannot name the external system, do not write the Effect.
External systems include:
- browser APIs and DOM subscriptions
- timers, sockets, observers, media APIs
- third-party widgets and imperative libraries
- network synchronization that truly happens because the component is visible
Not external systems:
- derived values from props or state
- event-driven actions like submit, save, buy, delete, notify
- resetting local state because props changed
- chaining state updates to trigger more state updates
- passing data upward just because a child rendered
Replacement Patterns
1. Derive during render
Do not mirror props or state into more state.
// Bad
const [fullName, setFullName] = useState("");
useEffect(() => {
setFullName(`${firstName} ${lastName}`);
}, [firstName, lastName]);
// Good
const fullName = `${firstName} ${lastName}`;Use this for filtered lists, labels, counts, booleans, selected objects, and other values that can be computed from current inputs.
2. Memoize expensive pure work
If the calculation is slow, cache it with useMemo. Do not use an Effect that immediately
calls setState with a computed value.
const visibleTodos = useMemo(() => getVisibleTodos(todos, filter), [todos, filter]);First ask whether the work is actually expensive. If not, calculate it directly during render.
3. Put user actions in event handlers
If the code runs because the user clicked, submitted, selected, dragged, or typed, keep it in the corresponding handler.
// Bad
useEffect(() => {
if (shouldSubmit) {
void saveForm(form);
}
}, [shouldSubmit, form]);
// Good
async function handleSubmit() {
await saveForm(form);
}Never build "set flag -> Effect notices flag -> Effect does the real work" flows unless the flag is synchronizing with a real external system.
4. Reset identity with key when you want a fresh instance
If a component should become a brand-new instance when some identity changes, give it a
different key. React will unmount the old subtree and mount a new one, which resets all local
state below that point without an Effect.
// Bad
function Profile({ userId }: { userId: string }) {
const [comment, setComment] = useState("");
useEffect(() => {
setComment("");
}, [userId]);
return <input value={comment} onChange={(e) => setComment(e.target.value)} />;
}
// Good
function ProfilePage({ userId }: { userId: string }) {
return <Profile key={userId} userId={userId} />;
}
function Profile({ userId }: { userId: string }) {
const [comment, setComment] = useState("");
return <input value={comment} onChange={(e) => setComment(e.target.value)} />;
}Use this when the identity really changed: user, document, chat room, wizard step, or form instance. Do not use it when you only want to tweak one field, because remounting resets the entire subtree.
5. Lift state or control the component
If an Effect exists only to notify a parent after local state changed, the data model is usually wrong. Prefer lifting state up or updating both sides in the same event.
// Bad
function Toggle({ onChange }: { onChange: (next: boolean) => void }) {
const [isOn, setIsOn] = useState(false);
useEffect(() => {
onChange(isOn);
}, [isOn, onChange]);
return <button onClick={() => setIsOn(!isOn)}>{isOn ? "On" : "Off"}</button>;
}
// Good
function Toggle({ isOn, onChange }: { isOn: boolean; onChange: (next: boolean) => void }) {
return <button onClick={() => onChange(!isOn)}>{isOn ? "On" : "Off"}</button>;
}6. Use useSyncExternalStore for external subscriptions
Use useSyncExternalStore when the source of truth lives outside React and changes over time.
This is React's built-in primitive for subscribing to external stores.
Good fits:
- browser APIs with a current value plus subscription events
- third-party or app-level stores outside React state
- reusable hooks like
useOnlineStatus()oruseMediaQuery()
The shape is:
const value = useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);Where:
subscribetells React how to listen for changes and return cleanupgetSnapshotreads the current value from the external storegetServerSnapshotprovides the initial server and hydration value when SSR is involved
// Bad
function useOnlineStatus() {
const [isOnline, setIsOnline] = useState(true);
useEffect(() => {
function updateStatus() {
setIsOnline(navigator.onLine);
}
updateStatus();
window.addEventListener("online", updateStatus);
window.addEventListener("offline", updateStatus);
return () => {
window.removeEventListener("online", updateStatus);
window.removeEventListener("offline", updateStatus);
};
}, []);
return isOnline;
}
// Good
const isOnline = useSyncExternalStore(subscribe, () => navigator.onLine, () => true);Prefer this over hand-rolled subscription Effects in components.
Important caveats from the React docs:
getSnapshotmust return a stable cached value unless the store actually changed- if
subscribechanges identity every render, React will resubscribe every render - if you support SSR,
getServerSnapshotmust match between server render and hydration
Do not use this for:
- normal component state that should live in
useState,useReducer, or context - derived values you can calculate during render
- user actions handled by event handlers
- one-time fetching
- general side effects that are not subscriptions
7. Fetch through the framework or a data library
Avoid raw fetch-in-Effect code in app components when a framework loader or query library is available.
Preferred order:
- framework data APIs (
Next.js,React Router, Remix, server components, route loaders) - data libraries (
TanStack Query,SWR) - a focused custom hook
- raw
useEffectonly if none of the above fit
If you must fetch in an Effect, handle cleanup so stale responses are ignored.
// Bad
useEffect(() => {
void fetchResults(query).then(setResults);
}, [query]);
// Good
useEffect(() => {
let ignore = false;
void fetchResults(query).then((next) => {
if (!ignore) {
setResults(next);
}
});
return () => {
ignore = true;
};
}, [query]);8. Encapsulate unavoidable imperative synchronization
Sometimes an Effect is correct: sockets, observers, widgets, media controls, focus management, layout measurement, or DOM APIs that must stay in sync with rendered output.
When that happens:
- keep the Effect tiny and specific
- name the external system in a comment or hook name
- include full cleanup
- prefer a custom hook over open-coded Effect logic in many components
- consider
useLayoutEffectonly for pre-paint measurement or visual correctness
// Bad
function ChatRoom({ roomId }: { roomId: string }) {
useEffect(() => {
const connection = createConnection(roomId);
connection.connect();
}, [roomId]);
}
// Good
function useChatConnection(roomId: string) {
useEffect(() => {
const connection = createConnection(roomId);
connection.connect();
return () => {
connection.disconnect();
};
}, [roomId]);
}If your team bans raw useEffect, put these escape hatches behind approved hooks instead of
sprinkling Effects through feature code.
Anti-Patterns
Treat these as red flags during authoring or review:
useEffect(() => setX(...), [...])for derived state- Effect only exists to call a function after a button click
- effect chains where one state update triggers another Effect and another render
- dependency arrays fought with
eslint-disable, refs-as-flags, or intentionally stale closures - object or function dependencies recreated every render without need
- child component fetching data and pushing it upward in an Effect
- mount-only initialization that should live in module scope, entrypoints, or framework boot code
Review Checklist
Before accepting a new Effect, verify all of these:
- The code synchronizes with a real external system
- Derived render data, memoization, events,
key, lifted state, anduseSyncExternalStorewere all considered first - The dependency list is honest and complete
- Setup and cleanup are symmetrical
- The Effect is idempotent under Strict Mode re-mounting
- Data fetching is not bypassing an existing framework or query abstraction
- The logic is small enough that a custom hook or helper name explains its purpose
Team Policy
For teams trying to ban or heavily restrict raw useEffect, use this policy:
- Do not introduce
useEffectfor derived state, events, or resets. - Prefer render-time derivation, event handlers,
key,useMemo, anduseSyncExternalStore. - Route data loading through the framework or an approved query library.
- If an Effect is still necessary, hide it behind a narrowly named custom hook or document the external system and cleanup explicitly in review.
- Never silence
react-hooks/exhaustive-depsto "make it work".
References
For source material and further reading, see references/sources.md.
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.

