no-use-effect
यह क्या करती है
यह AI एजेंट को React के useEffect हुक को छोड़कर सुरक्षित विकल्प अपनाना सिखाती है। यह उन React डेवलपर्स के लिए है जो साफ़ और आसानी से डीबग होने वाले कॉम्पोनेंट चाहते हैं।
कब इस्तेमाल करें
- ✓जब एजेंट एक नया React कॉम्पोनेंट लिखने वाला हो।
- ✓जब आप useEffect इस्तेमाल करने वाला कोड समीक्षा कर रहे हैं और उसे सरल बनाना चाहते हैं।
- ✓जब एजेंट यूँ ही useEffect जोड़ दे और आप उसे हटवाना चाहते हैं।
Skill का लिंक
https://github.com/humanlayer/humanlayer/blob/main/.claude/skills/no-use-effect/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“मेरे React कॉम्पोनेंट को रीफ़ैक्टर कीजिए ताकि उसमें useEffect न हो, और हर बदलाव की वजह समझाइए।”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
एजेंट पता लगाता है कि हर effect क्या करता है, फिर पाँच विकल्पों में से एक चुनता है, जैसे मान को सीधे इनलाइन गणना करना या इवेंट हैंडलर इस्तेमाल करना। दुर्लभ मामलों के लिए एक बार माउंट होने वाला विकल्प भी है।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
No useEffect
Never call useEffect directly. Use derived state, event handlers, data-fetching libraries, or useMountEffect instead.
Quick Reference
This skill is dervied from the React docs: You Might Not Need an Effect. IMPORTANT: when this skill is invoked you MUST read this post in entirety.
| 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 --bun run typecheck -- --filter=<package>
bun --bun run test -- --filter=<package>
The Escape Hatch: useMountEffect
For the rare case where you need to sync with an external system on mount:
The implementation wraps useEffect with an empty dependency array to make intent explicit:
export function useMountEffect(effect: () => void | (() => void)) {
/* eslint-disable no-restricted-syntax */
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 }) {
const [product, setProduct] = useState(null);
useEffect(() => {
fetchProduct(productId).then(setProduct);
}, [productId]);
}
// GOOD: Query library handles cancellation/caching/staleness
function ProductPage({ productId }) {
const { data: product } = useQuery(['product', productId], () =>
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 }) {
useEffect(() => {
if (!isLoading) playVideo();
}, [isLoading]);
}
// GOOD: Mount only when preconditions are met
function VideoPlayerWrapper({ isLoading }) {
if (isLoading) return <LoadingScreen />;
return <VideoPlayer />;
}
function VideoPlayer() {
useMountEffect(() => playVideo());
}
Use useMountEffect for stable dependencies (singletons, refs, context values that never c
अक्सर पूछे जाने वाले सवाल
useEffect की जगह क्या लेता है?
इनलाइन गणना, डेटा-फ़ेचिंग लाइब्रेरी, इवेंट हैंडलर, एक बार माउंट होने वाला हुक, और स्टेट रीसेट करने के लिए key prop।
क्या यह useEffect को पूरी तरह मना करती है?
यह कहती है कि useEffect को सीधे कभी न बुलाएँ और उसके बजाय सूचीबद्ध विकल्प इस्तेमाल करें।
यह सलाह कहाँ से आती है?
यह React दस्तावेज़ के उस मार्गदर्शन पर आधारित है कि effect कब ज़रूरी नहीं होता।
जानकारी
लेखक का मूल विवरण
Enforce the no-useEffect rule when writing or reviewing React code. ACTIVATE when writing React components, refactoring existing useEffect calls, reviewing PRs with useEffect, or when an agent adds useEffect "just in case." Provides the five replacement patterns and the useMountEffect escape hatch.
repo: humanlayer/humanlayer
लोकप्रियता
- GitHub स्टार
- 13k
- रैंकिंग में स्थान
- #11389
- लाइसेंस
- Apache-2.0
- अपडेट की गई
- 31/10/2026
कमेंट
- …
इस repository की और skills
asd-ste100
13kउलझे हुए अंग्रेज़ी टेक्स्ट को छोटे, एक-अर्थ वाले वाक्यों में बदलना सिखाती है, जो लोगों और दूसरे सॉफ़्टवेयर दोनों के लिए पढ़ने में आसान हों।
better-github-skill
13kतैयार GitHub स्क्रिप्ट से pull request की स्थिति जाँचने, उसकी समीक्षा टिप्पणियाँ पढ़ने, और CI बिल्ड क्यों विफल हुआ यह पता करने में आपके एजेंट की मदद करती है।
calldiff
13kकोड समीक्षा में बदलाव का असर देखने के लिए, दो git संस्करणों के बीच कोड में फ़ंक्शन कॉल की श्रृंखलाओं की तुलना करने में मदद करती है।
chrome-devtools-cli
13kआपके एजेंट को टर्मिनल से Chrome चलाने देती है, ताकि वह पेज खोल सके, क्लिक कर सके, फ़ॉर्म भर सके और ब्राउज़र ऑटोमेशन व टेस्टिंग के लिए पेज का स्नैपशॉट ले सके।
मिलती-जुलती skills
angular-developer
280kआपके एजेंट को Angular code बनाने और प्रोजेक्ट स्ट्रक्चर पर सलाह देने में मदद करता है। नए प्रोजेक्ट शुरू करने, code के हिस्से बनाने, या performance और accessibility सुधारने में उपयोगी है।
frontend-a11y
280kआपके एजेंट को web interfaces को सबके लिए accessible बनाने में मदद करता है। यह सुनिश्चित करता है कि websites और apps screen readers और keyboard navigation के साथ अच्छे से काम करें।
frontend-patterns
280kआपके एजेंट को React और Next.js में frontend development के modern patterns लागू करने में मदद करता है। यह performance optimize करता है, state manage करता है और best practices फॉलो करवाता है।