شعار Refactor React Effects

Refactor React Effects

مؤسسةشائع
langfuse
refactor-react-effects

Refactor avoidable React useEffect usage in Langfuse frontend code. Use when adding, reviewing, or removing effects; initializing forms or local UI state from query data; synchronizing client and server state; moving mutations or async workflows out of components; cleaning every effect from a frontend submodule; or reviewing whether an effect has a valid external-system owner.

نظرة عامة

الناشرlangfuse
المستودعlangfuse
اسم المهارةrefactor-react-effects
النجوم
37.4K
التفريعات
4.2K
الملفات المرفقة
2
الروابط
  • تعليمات بصيغة Markdown

    ملف SKILL.md يُحمّله النموذج عند الحاجة، فلا يستهلك توكنات إلا عندما يَرِد طلب ذو صلة فعلًا.

  • تعمل مع أي نموذج لغوي كبير

    مهارات الذكاء الاصطناعي مكتوبة بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا تعمل مع GPT أو Claude أو Gemini أو Grok أو نموذج محلي.

  • الملفات المرفقة: 2

    نصوص برمجية وقوالب ومراجع يمكن للنموذج قراءتها أثناء عمله. الملفات للقراءة فقط ولا تُنفّذ أبدًا.

  • مفتوحة المصدر

    نشرها langfuse على GitHub. اطّلع على المصدر قبل تثبيتها.

التثبيت

ثبّت مهارة الذكاء الاصطناعي Refactor React Effects في TypingMind لاستخدامها مع أي نموذج لغوي كبير، أو أضفها إلى وكيل ذكاء اصطناعي آخر يقرأ SKILL.md.

1

التثبيت في TypingMind

يُثبّت TypingMind المهارة مباشرةً من مجلدها على GitHub — فيقرأ SKILL.md، ويجمع ملفات الموارد في حزمة، ويحفظ النتيجة محليًا.

  1. افتح التطبيق وانتقل إلى الإضافات → المهارات.
  2. اختر «تثبيت من GitHub».
  3. الصق رابط مجلد المهارة الموضّح أدناه وأكّد التثبيت.
    https://github.com/langfuse/langfuse/tree/main/.agents/skills/refactor-react-effects
  4. فعّل المهارة في كل محادثة تريد إتاحتها فيها.
الإضافات → المهارات → إضافة مهارة → من رابط GitHub، ثم الصق رابط المجلد واضغط على «متابعة».
2

التثبيت في وكيل ذكاء اصطناعي آخر

يمكن لأي وكيل ذكاء اصطناعي يقرأ تنسيق Agent Skills استخدام هذه المهارة — انسخ المجلد إلى مجلد المهارات الخاص بذلك الوكيل.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/langfuse/langfuse.git /tmp/langfuse
mkdir -p .claude/skills
cp -r /tmp/langfuse/.agents/skills/refactor-react-effects .claude/skills/refactor-react-effects
أعد تشغيل Claude Code بعد النسخ ليتعرّف على المهارة الجديدة.

استخدمها في TypingMind

فعّل Refactor React Effects في أي محادثة على TypingMind وسيتولى النموذج الباقي. تتضمن مطالبة النظام اسمها ووصفها، وبمجرد ورود طلب ذي صلة، يُحمّل النموذج التعليمات الكاملة تلقائيًا — فلا تحتاج إلى استدعائها يدويًا، ولا تستهلك أي توكنات حتى تُستخدم فعليًا.

يُحمّل النموذج Refactor React Effects تلقائيًا بمجرد ورود طلب ذي صلة بها.

تعمل مع أي نموذج ذكاء اصطناعي

مهارات الذكاء الاصطناعي هي تعليمات بصيغة Markdown وليست شيفرة خاصة بمزوّد معيّن، لذا لا ترتبط Refactor React Effects بالنموذج الذي كُتبت له. ثبّتها مرة واحدة في TypingMind واستخدمها مع GPT-5 أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو نموذج محلي تشغّله بنفسك — كل ذلك باستخدام مفاتيح API الخاصة بك.

  • تُحمَّل عند الحاجة فقط

    تتضمن مطالبة النظام الاسم والوصف فقط. وتُجلب التعليمات عند أول طلب ذي صلة، لذا لا تترتب أي تكلفة على المهارة غير المستخدمة.

  • بدّل النماذج أثناء المحادثة

    لأن المهارة تعليمات وليست شيفرة، فإن تغيير النموذج لا يعطّلها — فالنموذج التالي يقرأ ملف SKILL.md نفسه.

تعليمات المهارة

هذا هو محتوى SKILL.md الذي يُحمّله النموذج. اقرأه قبل التثبيت — فالمهارة عبارة عن تعليمات سيتبعها نموذجك.

Refactor React Effects

Do not add useEffect by default. Use it only to synchronize a component with a concrete system outside React. If there is no external system, remove the effect.

Before adding or retaining an effect, answer all of these questions:

  1. Which external system is being synchronized?
  2. What starts or updates the synchronization?
  3. What cleanup, if any, prevents leaks or duplicate subscriptions?
  4. Why can an event handler, query API, render derivation, conditional mount, or existing integration hook not own the behavior?

If the first question has no concrete answer, do not use an effect.

Required Context

Decision Rules

Apply these rules in order:

  1. Derive during render. Compute values from current props, query data, and client state instead of storing a synchronized copy.
  2. Gate on required data. If a form or UI cannot initialize correctly without query data, let a parent own loading/error handling. Mount a child only after the data exists and pass guaranteed initial values to its lazy useState initializer.
  3. Make reset semantics explicit. Use a key to remount for a new entity only when discarding the old local draft is intended. Use an explicit user action for refresh/reset when drafts must not be overwritten silently.
  4. Run actions from events. Put submit, mutation, navigation, notification, and multi-step async workflows in event handlers, actions/*.ts, or store actions. Pass a React Query client, mutation callback, or vanilla Zustand store as a dependency; never call React hooks from those actions.
  5. Keep real integration effects. Subscriptions, observers, browser event listeners, timers, and imperative third-party APIs may need an effect. Make setup and cleanup symmetrical and keep the effect in a narrow integration hook or container. In a direct-effect-free module, use a pre-existing, centrally owned integration hook. Do not create a feature-local wrapper just to hide useEffect.

Presume that an effect which writes React or Zustand state from props or query data is removable. Do not evade the design problem by switching to useLayoutEffect, suppressing dependency lint, hiding the same synchronization in a custom hook, or adding an ESLint disable.

Fast Smell Test

Refactor when any of these shapes appear:

  • useEffect(() => setX(deriveFromY(y)), [y]);
  • fetch data, then mirror it with setState;
  • set a flag, let an effect perform the action, then clear the flag;
  • chain effects where one state write triggers the next effect;
  • reset local state because an ID or prop changed;
  • guard an integration inside an effect when the component could mount only after the precondition is true.

Workflow

1. Establish the Behavior Boundary

Identify the state owner, query owner, user events, external systems, and loading/error states. For a bug fix, add the failing test first and confirm it fails. For a behavior-preserving migration, reuse existing coverage where it protects the relevant behavior; add focused coverage only for a meaningful behavior risk such as draft preservation, entity changes, refetches, submits, or cleanup. Do not add tests that inspect source code or merely assert that a hook is absent. Use behavior tests and the effect inventory instead.

2. Inventory Every Effect

Search the full target module, including tests and stories:

bash
rg -n '\b(use(?:Layout)?Effect|React\.use(?:Layout)?Effect)\b' 'web/src/features/<feature>'

Classify every result as:

  • render derivation;
  • query-to-local-state initialization;
  • client/server state synchronization;
  • user-event or async workflow;
  • external-system integration;
  • test-only harness behavior.

Do not refactor from a raw count alone. Record what triggers each effect, what it writes or controls, and the replacement pattern.

3. Refactor One Semantic Seam at a Time

Prefer this order:

  1. replace redundant state with pure derivation;
  2. split data-owning parents from stateful children;
  3. move event-driven work to handlers or external actions;
  4. isolate unavoidable integrations in narrow hooks;
  5. remove dead state, guards, dependencies, and imports.

Keep user-visible behavior stable. Avoid bundling unrelated file moves, visual changes, and state architecture changes into the same slice.

4. Complete a Submodule Migration

Repeat the inventory after each slice. Before declaring a submodule clean:

  • account for every original effect;
  • confirm no effect merely moved behind a wrapper hook;
  • confirm refetches do not overwrite local edits;
  • confirm entity changes have deliberate preserve/reset semantics;
  • confirm complex actions are callable without rendering the feature;
  • document any real external integration effect that remains outside the refactoring target.

Do not add or modify effect-specific ESLint rules or pre-commit checks as part of this workflow. Treat enforcement policy as separate, explicitly requested work.

5. Verify

Run, at minimum:

  • focused client tests for the changed behavior;
  • ESLint on the migrated path, then pnpm --filter web run lint;
  • type checking when state or action interfaces changed;
  • a real-browser review for user-visible flows, using seeded data where applicable — yours where the outcome is uncertain, otherwise the developer's, per .agents/AGENTS.md;
  • the effect inventory again to prove the intended scope is clean.

Report the exact command summary lines and any retained effects with their external-system rationale.

Output Format

Return valid Markdown. For module audits, include a compact table with the effect location, classification, replacement, and status. Check headings, lists, links, tables, backticks, and code fences for valid Markdown syntax before returning the report.

الملفات المرفقة

يقرأ النموذج هذه الملفات عند الحاجة أثناء تحميل المهارة. وهي متاحة للقراءة ولا تُنفّذ أبدًا.

الأسئلة الشائعة

ماذا تفعل مهارة الذكاء الاصطناعي Refactor React Effects؟

Refactor avoidable React useEffect usage in Langfuse frontend code. Use when adding, reviewing, or removing effects; initializing forms or local UI state from query data; synchronizing client and server state; moving mutations or async workflows out of components; cleaning every effect from a frontend submodule; or reviewing whether an effect has a valid external-system owner.

لماذا تستخدم Refactor React Effects على TypingMind؟

لأنك تثبّتها مرة واحدة وتستخدمها مع أي نموذج. مهارة Refactor React Effects عبارة عن نص Markdown وليست شيفرة خاصة بمزود بعينه، لذا تعمل المهارة نفسها مع GPT-5 أو Claude أو Gemini أو Grok أو نموذج محلي، ويمكنك تبديل النموذج أثناء المحادثة دون تعطّل المهارة. يعمل TypingMind بمفاتيح API الخاصة بك، فتدفع للمزودين مباشرةً بدلًا من اشتراك لكل مقعد، وتبقى مهاراتك ومحادثاتك في مساحة التخزين الخاصة بك.

كيف أثبّت Refactor React Effects في TypingMind؟

افتح الإضافات → المهارات → التثبيت من GitHub في TypingMind والصق https://github.com/langfuse/langfuse/tree/main/.agents/skills/refactor-react-effects. يقرأ TypingMind ملف SKILL.md الخاص بها، ويجمع ملفاتها ويثبّتها كمهارة يمكنك تفعيلها لكل محادثة على حدة.

ما نماذج الذكاء الاصطناعي التي يمكنها استخدام Refactor React Effects؟

أي نموذج تربطه في TypingMind. مهارات الذكاء الاصطناعي عبارة عن تعليمات Markdown وليست شيفرة خاصة بمزود بعينه، لذا يمكن لكل من GPT وClaude وGemini وGrok والنماذج المحلية تحميل هذه المهارة عندما يتوافق الطلب معها.

كم نموذج ذكاء اصطناعي يمكنني استخدامه مع Refactor React Effects؟

أي عدد تريده. ما دام النموذج يدعم المهارات، يمكنك استخدام Refactor React Effects معه، سواء كان GPT أو Claude أو Gemini أو Grok أو DeepSeek أو Mistral أو Llama أو غيرها، وكل ذلك على TypingMind باستخدام مفاتيح API الخاصة بك.

هل مهارة الذكاء الاصطناعي Refactor React Effects مجانية؟

نشرها langfuse على GitHub. راجع المستودع للاطلاع على شروط الترخيص. لا تدفع إلا لمزود الذكاء الاصطناعي الخاص بك مقابل التوكنات التي تستخدمها.

ما هي مهارات الذكاء الاصطناعي؟

مهارة الذكاء الاصطناعي حزمة تعليمات قابلة لإعادة الاستخدام تعلّم نموذج الذكاء الاصطناعي كيفية تنفيذ مهمة محددة. وتتبع تنسيق Agent Skills المفتوح: ملف SKILL.md يتضمن اسمًا ووصفًا، إلى جانب أي نصوص برمجية أو قوالب أو ملفات مرجعية قد يحتاج إليها النموذج. لا يقرأ النموذج التعليمات إلا عندما يتوافق طلبك مع المهارة، لذا لا تترتب على المهارة المثبتة أي تكلفة حتى تُستخدم.

كيف تختلف مهارات الذكاء الاصطناعي عن الإضافات أو موصلات MCP؟

تمنح الإضافة أو موصل MCP النموذج أدوات جديدة يمكنه استدعاؤها، وهي شيفرة تُنفَّذ في مكان ما وتُرجع نتيجة. أما مهارة الذكاء الاصطناعي فتزوّد النموذج بالمعرفة ومنهجية العمل: كيفية التعامل مع مهمة، والخطوات التي ينبغي اتباعها، وما ينبغي أن تكون عليه المخرجات الجيدة. المهارات عبارة عن نصوص Markdown، لذا لا تحتاج إلى خادم أو مفتاح API أو بيئة تشغيل، وتعمل مع أي نموذج.

عرض الكل

أنشئ مساحة عملك للذكاء الاصطناعي الآن

اشترك في نشرتنا البريدية لتصلك أخبار الميزات الجديدة والهدايا القادمة 👇