no-use-effect
ما الذي تفعله
يبعد هذا الدليل وكيلك عن نمط شائع في React يسبب كثيرًا من الأخطاء وإعادة الرسم الزائدة. وهو مخصص للمطورين الذين يكتبون أو يراجعون مكونات React والخطافات.
متى تستخدمها
- ✓عندما ينشئ وكيلك مكونات React أو خطافات جديدة.
- ✓عندما يعيد هيكلة استدعاء useEffect موجود.
- ✓عندما تضيف طلب دمج يحتوي على useEffect جديد وتريد مراجعته.
رابط المهارة
https://github.com/fastrepl/anarlog/blob/main/.agents/skills/no-use-effect/SKILL.mdانسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.
طريقة الاستخدام
أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.
رسالة جاهزة للصق
لـ Claude Code أو Codex أو Cursor: شغّله داخل مجلد مشروعك وستُثبَّت المهارة.
نزّل ملف SKILL.md وضعه في مجلد مهارات وكيلك.
مثال على ما تطلبه من الذكاء الاصطناعي
“راجع مكون React هذا، واحذف أي useEffect ليس ضروريًا فعلًا.”
5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.
كيف تعمل
تسأل المهارة أولًا عن سبب وجود كل تأثير، ثم تستبدله بأبسط نمط مناسب. ومن هذه الأنماط حساب القيم أثناء العرض، واستخدام مكتبة بيانات للجلب، ومعالجة إجراءات المستخدم في معالجات الأحداث، وخطاف ضيق للإعداد الفعلي لمرة واحدة.
المحتوى التقني (ملف 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
- Classify why the effect exists.
- Replace it with the narrowest pattern below.
- 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:
- Hooks that read external state or data.
- Local state.
- Derived values computed during render.
- Event handlers.
- Early returns.
- Render output.
Do not introduce mirrored state just to make an effect possible.
الأسئلة الشائعة
متى يُسمح باستخدام useEffect؟
فقط للمزامنة الفعلية مع نظام خارجي تعمل مرة واحدة عند التركيب، وفقط عندما لا يناسب نمط أبسط.
هل يغيّر ذلك سلوك تطبيقي؟
يهدف إلى إبقاء السلوك كما هو، ويطلب الدليل تشغيل فحوص lint والنوع والاختبارات المعتادة بعد ذلك.
ما القيمة المشتقة؟
قيمة تُحسب من قيم أخرى أثناء العرض، بدل نسخها إلى متغير حالة منفصل.
التفاصيل
الوصف الأصلي من المؤلف
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
التعليقات
- …
المزيد من المهارات من هذا المستودع
sqlite-schema-design
9.7kيساعد وكيلك على تصميم جداول قواعد البيانات التي تتزامن بين الأجهزة باستخدام SQLite Sync، ويتبع قواعده للمفاتيح والقيم الافتراضية وتغييرات المخطط.
anarlog
9.7kيساعد وكيلك على البحث في ملاحظات اجتماعاتك في Anarlog وملخصاتها ونصوصها وحاضريها وبنود عملها، أو على استيراد تسجيل محلي.
مهارات مشابهة
angular-developer
280kيساعد وكيلك على كتابة شيفرة Angular وتقديم نصائح لبنية المشروع، ويفيد في بدء المشاريع الجديدة وإنشاء المكونات وتحسين الأداء وإمكانية الوصول.
frontend-a11y
280kيساعد وكيلك على جعل واجهات الويب متاحة للجميع، فيضمن أن المواقع والتطبيقات تعمل جيدًا مع قارئات الشاشة والتنقل بلوحة المفاتيح.
frontend-patterns
280kيطبّق وكيلك أنماط تطوير الواجهات الحديثة، فيحسّن الأداء ويدير الحالة ويتبع أفضل الممارسات في React وNext.js.