react-no-use-effect
Skill17 starsChanged 6 months agoApache-2.0View on GitHub
Enforce the no-useEffect rule when writing or reviewing React code. Activate when writing React components, refactoring existing useEffect calls, reviewing PRs that introduce useEffect, or when an agent adds useEffect "just in case." Provides five replacement patterns and the useMountEffect escape hatch.
1 other project uses a version of this, 1 of them edited.
Adopted by
Most recently taken up by
- felipegomss/agent-skillsedited, first seen Mar 26, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 1
- felipegomss/agent-skills★ 139% same
Wrote their own version · 0
None found.
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 repository19 other files it gives its agents.
- AGENTS.mdAGENTS.md
- agent-browserSkill
- agentic-legibilitySkill
- babysit-prSkill
- better-result-adoptSkill
- code-breaking-changesSkill
- code-review-change-sizeSkill
- code-reviewSkill
- code-review-testingSkill
- drizzle-migration-conflict-resolutionSkill
- gh-pr-writingSkill
- knip-deadcodeSkill
- onequery-blog-imagesSkill
- onequery-bugSkill
- onequery-pr-bodySkill
- protobufSkill
- tanstack-query-best-practicesSkill
- tanstack-router-best-practicesSkill
- xstateSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 2 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 12
Never call useEffect directly.
- Distinctive: line 46
Use the five rules below to pick the right replacement.
- Very specific: line 56
Use bunx turbo check --json when the change spans multiple packages or needs a whole-repo lint/format pass.
- Distinctive: line 125
If a user clicks a button, do the work in the handler.
- Very specific: line 173
Use useMountEffect for stable dependencies such as singletons, refs, or context values that do not change over the component lifetime:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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.
Files
No useEffect
Never call useEffect directly. Use derived state, event handlers, data-fetching libraries, or useMountEffect instead.
Quick Reference
- Repo linting:
bun lint --format json <package-path> - Escape hatch hook:
useMountEffectfrom@onequery/ui/hooks/use-mount-effect - React docs: You Might Not Need an Effect
- Origin: https://x.com/alvinsng/status/2033969062834045089
Comment: the repo currently has
useMountEffect, but it does not appear to have a global lint rule that already bansuseEffect. Treat this skill as the policy source unless that restriction is added later.
| Instead of useEffect for... | Use |
| Deriving state from other state/props | Inline computation (Rule 1) |
| Fetching data | useQuery / data-fetching library (Rule 2) |
| Responding to user actions | Event handlers (Rule 3) |
| One-time external sync on mount | useMountEffect (Rule 4) |
| Resetting state when a prop changes | key prop on parent (Rule 5) |
When to Use This Skill
- Writing new React components
- Refactoring existing
useEffectcalls - Reviewing PRs that introduce
useEffect - An agent adds
useEffect"just in case"
Workflow
1. Identify the useEffect
Determine what the effect is doing: deriving state, fetching data, responding to an event, syncing with an external system, or resetting state.
2. Apply the Correct Replacement Pattern
Use the five rules below to pick the right replacement.
3. Verify
bun lint --format json <package-path>
bunx turbo typecheck --filter=<package> --json
bunx turbo test --filter=<package> --jsonUse bunx turbo check --json when the change spans multiple packages or needs a whole-repo lint/format pass.
The Escape Hatch: useMountEffect
For the rare case where you need to sync with an external system on mount, use the shared wrapper from @onequery/ui/hooks/use-mount-effect.
The implementation keeps the intent explicit:
import { useEffect } from "react";
export function useMountEffect(effect: () => void | (() => void)) {
useEffect(effect, []);
}Replacement Patterns
Rule 1: Derive state, do not sync it
Most effects that set state from other state are unnecessary and add extra renders.
// BAD: Two render cycles - first stale, then filtered
function ProductList() {
const [products, setProducts] = useState([]);
const [filteredProducts, setFilteredProducts] = useState([]);
useEffect(() => {
setFilteredProducts(products.filter((p) => p.inStock));
}, [products]);
}
// GOOD: Compute inline in one render
function ProductList() {
const [products, setProducts] = useState([]);
const filteredProducts = products.filter((p) => p.inStock);
}Smell test: You are about to write useEffect(() => setX(deriveFromY(y)), [y]), or you have state that only mirrors other state or props.
Rule 2: Use data-fetching libraries
Effect-based fetching creates race conditions and duplicated caching logic.
// BAD: Race condition risk
function ProductPage({ productId }: { productId: string }) {
const [product, setProduct] = useState(null);
useEffect(() => {
fetchProduct(productId).then(setProduct);
}, [productId]);
}
// GOOD: Query library handles cancellation, caching, and staleness
function ProductPage({ productId }: { productId: string }) {
const { data: product } = useQuery({
queryKey: ["product", productId],
queryFn: () => fetchProduct(productId),
});
}Smell test: Your effect does fetch(...) and then setState(...), or you are re-implementing caching, retries, cancellation, or stale handling.
Rule 3: Event handlers, not effects
If a user clicks a button, do the work in the handler.
// BAD: Effect as an action relay
function LikeButton() {
const [liked, setLiked] = useState(false);
useEffect(() => {
if (liked) {
postLike();
setLiked(false);
}
}, [liked]);
return <button onClick={() => setLiked(true)}>Like</button>;
}
// GOOD: Direct event-driven action
function LikeButton() {
return <button onClick={() => postLike()}>Like</button>;
}Smell test: State is used as a flag so an effect can do the real action, or you are building "set flag -> effect runs -> reset flag" mechanics.
Rule 4: useMountEffect for one-time external sync
Good uses: DOM integration (focus, scroll), third-party widget lifecycles, browser API subscriptions.
// BAD: Guard inside effect
function VideoPlayer({ isLoading }: { isLoading: boolean }) {
useEffect(() => {
if (!isLoading) playVideo();
}, [isLoading]);
}
// GOOD: Mount only when preconditions are met
function VideoPlayerWrapper({ isLoading }: { isLoading: boolean }) {
if (isLoading) return <LoadingScreen />;
return <VideoPlayer />;
}
function VideoPlayer() {
useMountEffect(() => playVideo());
}Use useMountEffect for stable dependencies such as singletons, refs, or context values that do not change over the component lifetime:
// BAD: useEffect with dependency that never changes
useEffect(() => {
connectionManager.on("connected", handleConnect);
return () => connectionManager.off("connected", handleConnect);
}, [connectionManager]);
// GOOD: useMountEffect for stable dependencies
useMountEffect(() => {
connectionManager.on("connected", handleConnect);
return () => connectionManager.off("connected", handleConnect);
});Smell test: You are synchronizing with an external system, and the behavior is naturally "setup on mount, cleanup on unmount."
Rule 5: Reset with key, not dependency choreography
// BAD: Effect attempts to emulate remount behavior
function VideoPlayer({ videoId }: { videoId: string }) {
useEffect(() => {
loadVideo(videoId);
}, [videoId]);
}
// GOOD: key forces clean remount
function VideoPlayer({ videoId }: { videoId: string }) {
useMountEffect(() => {
loadVideo(videoId);
});
}
function VideoPlayerWrapper({ videoId }: { videoId: string }) {
return <VideoPlayer key={videoId} videoId={videoId} />;
}Smell test: You are writing an effect whose only job is to reset local state when an ID or prop changes, or you want the component to behave like a brand-new instance for each entity.
Component Structure Convention
Computed values come after hooks and local state, never via useEffect:
export function FeatureComponent({ featureId }: ComponentProps) {
// Hooks first
const { data, isLoading } = useQueryFeature(featureId);
// Local state
const [isOpen, setIsOpen] = useState(false);
// Computed values (NOT useEffect + setState)
const displayName = user?.name ?? "Unknown";
// Event handlers
const handleClick = () => {
setIsOpen(true);
};
// Early returns
if (isLoading) return <Loading />;
// Render
return <Flex direction="column" gap="lg">...</Flex>;
}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.

