मुख्य सामग्री पर जाएँ
Skillpedia
वेबसाइट और UI (frontend)9.7k · #12213

no-use-effect

यह क्या करती है

यह गाइड आपके एजेंट को एक आम React पैटर्न से दूर रखती है, जो अक्सर बग और अतिरिक्त रेंडर का कारण बनता है। यह उन डेवलपर्स के लिए है जो React कंपोनेंट और hooks लिखते या जाँचते हैं।

कब इस्तेमाल करें

  • ✓जब आपका एजेंट नए React कंपोनेंट या hooks बनाए।
  • ✓जब वह मौजूदा useEffect कॉल को दोबारा व्यवस्थित करे।
  • ✓जब कोई pull request useEffect जोड़े और आप उसकी समीक्षा चाहें।

Skill का लिंक

https://github.com/fastrepl/anarlog/blob/main/.agents/skills/no-use-effect/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/fastrepl/anarlog/blob/main/.agents/skills/no-use-effect/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“इस React कंपोनेंट की समीक्षा कीजिए और ऐसा कोई useEffect हटाइए जिसकी असल में ज़रूरत नहीं है।”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

स्किल पहले पूछती है कि हर effect क्यों मौजूद है, फिर उसे सबसे सरल फ़िट होने वाले पैटर्न से बदलती है। इनमें रेंडर के दौरान मान निकालना, डेटा लाने के लिए डेटा लाइब्रेरी, उपयोगकर्ता की कार्रवाइयाँ इवेंट हैंडलर में संभालना, और सच में एक बार होने वाले सेटअप के लिए एक सीमित hook शामिल हैं।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

No useEffect

Never call useEffect directly unless the work is a true mount-only sync with an external system and no simpler pattern fits. Prefer a render-time computation, a query or mutation hook, an event handler, or a remount boundary instead.

Workflow

  1. Classify why the effect exists.
  2. Replace it with the narrowest pattern below.
  3. Verify with the project's normal lint, typecheck, and tests.

Replacement Patterns

1. Derive state, do not sync it

Replace useEffect(() => setX(derive(y)), [y]) with inline computation or the project's existing memoization conventions.

const filteredProducts = products.filter((product) => product.inStock);

Smell test: state only mirrors props or other state.

2. Use query or mutation libraries for async work

Replace fetch-in-effect code with the app's data layer.

const productQuery = useQuery({
  queryKey: ["product", productId],
  queryFn: () => fetchProduct(productId),
});

Smell test: the effect fetches, awaits, retries, cancels, or writes async results into local state.

3. Use event handlers for user actions

Do the work where the action happens instead of setting a flag and reacting later.

const handleLike = () => {
  postLike();
};

Smell test: state exists only to trigger an effect, then gets reset.

4. Use useMountEffect for mount-only external sync

Use this only for work that is naturally "set up on mount, clean up on unmount": DOM integration, subscriptions, third-party widgets, and stable singleton bindings.

If the project already has a useMountEffect, use it. If not, add a small wrapper:

import { useEffect } from "react";

export function useMountEffect(effect: () => void | (() => void)) {
  useEffect(effect, []);
}

Prefer changing component structure so the component only mounts once preconditions are satisfied.

Smell test: the effect is a one-time setup or teardown for something outside React.

5. Use key to reset component state

If a component should behave like a fresh instance when an ID or entity changes, remount it from the parent.

return <VideoPlayer key={videoId} videoId={videoId} />;

Smell test: the effect exists only to reset local state when props change.

Review Standard

Treat new direct useEffect usage as a bug by default. Ask which of the five patterns applies. Accept direct useEffect only with explicit justification that the code is a mount-only external sync and that useMountEffect is the intended escape hatch.

Structure React Code This Way

Order component logic like this:

  1. Hooks that read external state or data.
  2. Local state.
  3. Derived values computed during render.
  4. Event handlers.
  5. Early returns.
  6. Render output.

Do not introduce mirrored state just to make an effect possible.

अक्सर पूछे जाने वाले सवाल

useEffect कब अनुमत है?

सिर्फ़ किसी बाहरी सिस्टम के साथ सच्चे सिंक के लिए, जो माउंट पर एक बार चले, और तभी जब कोई सरल पैटर्न फ़िट न हो।

क्या यह मेरे ऐप का व्यवहार बदलती है?

इसका लक्ष्य व्यवहार वही रखना है, और गाइड बाद में आपसे अपनी सामान्य lint, type और टेस्ट जाँच चलाने को कहती है।

व्युत्पन्न मान क्या है?

वह मान जो रेंडर के दौरान दूसरे मानों से निकाला जाता है, न कि किसी अलग state variable में कॉपी किया जाता है।

जानकारी

लेखक का मूल विवरण

Avoid direct React `useEffect` usage when writing or reviewing React components and hooks. Use this skill when creating new React code, refactoring existing `useEffect` calls, reviewing PRs that introduce `useEffect`, or when an agent reaches for `useEffect` as a default. Replace effects with derived state, query or mutation libraries, event handlers, `useMountEffect` for mount-only external sync, or `key`-based remounts.

repo: fastrepl/anarlog

लोकप्रियता

GitHub स्टार
9.7k
रैंकिंग में स्थान
#12213
लाइसेंस
MIT
अपडेट की गई
1/11/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

मिलती-जुलती skills