You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/reference/eslint-plugin-react-hooks/index.md
+25-25Lines changed: 25 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,36 +5,36 @@ version: rc
5
5
6
6
<Intro>
7
7
8
-
`eslint-plugin-react-hooks`provides ESLint rules to enforce the [Rules of React](/reference/rules).
8
+
`eslint-plugin-react-hooks`يوفّر قواعد ESLint لتطبيق [قواعد React](/reference/rules).
9
9
10
10
</Intro>
11
11
12
-
This plugin helps you catch violations of React's rules at build time, ensuring your components and hooks follow React's rules for correctness and performance. The lints cover both fundamental React patterns (exhaustive-deps and rules-of-hooks) and issues flagged by React Compiler. React Compiler diagnostics are automatically surfaced by this ESLint plugin, and can be used even if your app hasn't adopted the compiler yet.
12
+
تساعدك الإضافة على اكتشاف مخالفات قواعد React وقت البناء، لتلتزم المكوّنات والـ hooks بقواعد الصحة والأداء. تغطي التحذيرات أنماط React الأساسية (مثل exhaustive-deps وrules-of-hooks) ومسائل يبلّغ عنها React Compiler. تُعرَض تشخيصات المُصرّف تلقائياً عبر هذه الإضافة، ويمكن استخدامها حتى إن لم يكن المُصرّف مفعّلاً في تطبيقك بعد.
13
13
14
14
<Note>
15
-
When the compiler reports a diagnostic, it means that the compiler was able to statically detect a pattern that is not supported or breaks the Rules of React. When it detects this, it **automatically**skips over those components and hooks, while keeping the rest of your app compiled. This ensures optimal coverage of safe optimizations that won't break your app.
15
+
عندما يبلّغ المُصرّف عن تشخيص، يعني أنه استطاع اكتشاف نمط غير مدعوم أو يخالف قواعد React. عندها **يتخطّى**تلقائياً تلك المكوّنات والـ hooks مع الإبقاء على بقية التطبيق مُجمَّعاً، لأقصى تغطية آمنة من التحسينات دون كسر التطبيق.
16
16
17
-
What this means for linting, is that you don’t need to fix all violations immediately. Address them at your own pace to gradually increase the number of optimized components.
17
+
بالنسبة للـ lint، لا يلزمك إصلاح كل المخالفات فوراً. عالجها بوتيرتك لزيادة عدد المكوّنات المُحسَّنة تدريجياً.
18
18
</Note>
19
19
20
-
## Recommended Rules {/*recommended*/}
21
-
22
-
These rules are included in the `recommended`preset in`eslint-plugin-react-hooks`:
23
-
24
-
*[`exhaustive-deps`](/reference/eslint-plugin-react-hooks/lints/exhaustive-deps)- Validates that dependency arrays for React hooks contain all necessary dependencies
25
-
*[`rules-of-hooks`](/reference/eslint-plugin-react-hooks/lints/rules-of-hooks)- Validates that components and hooks follow the Rules of Hooks
26
-
*[`component-hook-factories`](/reference/eslint-plugin-react-hooks/lints/component-hook-factories)- Validates higher order functions defining nested components or hooks
27
-
*[`config`](/reference/eslint-plugin-react-hooks/lints/config)- Validates the compiler configuration options
28
-
*[`error-boundaries`](/reference/eslint-plugin-react-hooks/lints/error-boundaries)- Validates usage of Error Boundaries instead of try/catch for child errors
29
-
*[`gating`](/reference/eslint-plugin-react-hooks/lints/gating)- Validates configuration of gating mode
30
-
*[`globals`](/reference/eslint-plugin-react-hooks/lints/globals)- Validates against assignment/mutation of globals during render
31
-
*[`immutability`](/reference/eslint-plugin-react-hooks/lints/immutability)- Validates against mutating props, state, and other immutable values
32
-
*[`incompatible-library`](/reference/eslint-plugin-react-hooks/lints/incompatible-library)- Validates against usage of libraries which are incompatible with memoization
33
-
*[`preserve-manual-memoization`](/reference/eslint-plugin-react-hooks/lints/preserve-manual-memoization)- Validates that existing manual memoization is preserved by the compiler
34
-
*[`purity`](/reference/eslint-plugin-react-hooks/lints/purity)- Validates that components/hooks are pure by checking known-impure functions
35
-
*[`refs`](/reference/eslint-plugin-react-hooks/lints/refs)- Validates correct usage of refs, not reading/writing during render
36
-
*[`set-state-in-effect`](/reference/eslint-plugin-react-hooks/lints/set-state-in-effect)- Validates against calling setState synchronously in an effect
37
-
*[`set-state-in-render`](/reference/eslint-plugin-react-hooks/lints/set-state-in-render)- Validates against setting state during render
38
-
*[`static-components`](/reference/eslint-plugin-react-hooks/lints/static-components)- Validates that components are static, not recreated every render
39
-
*[`unsupported-syntax`](/reference/eslint-plugin-react-hooks/lints/unsupported-syntax)- Validates against syntax that React Compiler does not support
40
-
*[`use-memo`](/reference/eslint-plugin-react-hooks/lints/use-memo)- Validates usage of the `useMemo`hook without a return value
20
+
## القواعد الموصى بها {/*recommended*/}
21
+
22
+
هذه القواعد ضمن الإعداد `recommended`في`eslint-plugin-react-hooks`:
23
+
24
+
*[`exhaustive-deps`](/reference/eslint-plugin-react-hooks/lints/exhaustive-deps)— يتحقق أن مصفوفات تبعيات الـ hooks تتضمّن كل التبعيات اللازمة
25
+
*[`rules-of-hooks`](/reference/eslint-plugin-react-hooks/lints/rules-of-hooks)— يتحقق أن المكوّنات والـ hooks تتبع Rules of Hooks
26
+
*[`component-hook-factories`](/reference/eslint-plugin-react-hooks/lints/component-hook-factories)— دوال رتبة أعلى تُعرّف مكوّنات أو hooks متداخلة
27
+
*[`config`](/reference/eslint-plugin-react-hooks/lints/config)— صحة خيارات إعداد المُصرّف
28
+
*[`error-boundaries`](/reference/eslint-plugin-react-hooks/lints/error-boundaries)— استخدام Error Boundaries بدلاً من try/ccatch لأخطاء الأبناء
29
+
*[`gating`](/reference/eslint-plugin-react-hooks/lints/gating)— ضبط وضع gating
30
+
*[`globals`](/reference/eslint-plugin-react-hooks/lints/globals)— تجنّب إسناد/تعديل عامات أثناء التصيير
31
+
*[`immutability`](/reference/eslint-plugin-react-hooks/lints/immutability)— عدم تعديل props أو state أو قيم غير قابلة للتغيير
32
+
*[`incompatible-library`](/reference/eslint-plugin-react-hooks/lints/incompatible-library)— مكتبات غير متوافقة مع التذكّر
33
+
*[`preserve-manual-memoization`](/reference/eslint-plugin-react-hooks/lints/preserve-manual-memoization)— الإبقاء على التذكّر اليدوي عند المُصرّف
34
+
*[`purity`](/reference/eslint-plugin-react-hooks/lints/purity)— نقاء المكوّنات/الـ hooks عبر دوال معروفة بعدم النقاء
35
+
*[`refs`](/reference/eslint-plugin-react-hooks/lints/refs)— استخدام صحيح للـ refs دون قراءة/كتابة أثناء التصيير
36
+
*[`set-state-in-effect`](/reference/eslint-plugin-react-hooks/lints/set-state-in-effect)— عدم استدعاء setState متزامناً داخل effect
37
+
*[`set-state-in-render`](/reference/eslint-plugin-react-hooks/lints/set-state-in-render)— عدم ضبط الحالة أثناء التصيير
38
+
*[`static-components`](/reference/eslint-plugin-react-hooks/lints/static-components)— مكوّنات ثابتة لا تُعاد إنشاؤها كل تصيير
39
+
*[`unsupported-syntax`](/reference/eslint-plugin-react-hooks/lints/unsupported-syntax)— صياغة لا يدعمها React Compiler
40
+
*[`use-memo`](/reference/eslint-plugin-react-hooks/lints/use-memo)— استخدام `useMemo`دون قيمة مُرجَعة
Copy file name to clipboardExpand all lines: src/content/reference/eslint-plugin-react-hooks/lints/component-hook-factories.md
+18-18Lines changed: 18 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,27 +4,27 @@ title: component-hook-factories
4
4
5
5
<Intro>
6
6
7
-
Validates against higher order functions defining nested components or hooks. Components and hooks should be defined at the module level.
7
+
يتحقق من عدم استخدام دوال رتبة أعلى تعرّف مكوّنات أو hooks متداخلة. يجب تعريف المكوّنات والـ hooks على مستوى الوحدة.
8
8
9
9
</Intro>
10
10
11
-
## Rule Details {/*rule-details*/}
11
+
## تفاصيل القاعدة {/*rule-details*/}
12
12
13
-
Defining components or hooks inside other functions creates new instances on every call. React treats each as a completely different component, destroying and recreating the entire component tree, losing all state, and causing performance problems.
13
+
تعريف مكوّنات أو hooks داخل دوال أخرى ينشئ نسخاً جديدة كل استدعاء. يعامل React كل نسخة كمكوّن مختلف تماماً، فيدمّر ويعيد إنشاء شجرة المكوّن بالكامل، يفقد كل الحالة، ويسبب مشاكل أداء.
14
14
15
-
### Invalid {/*invalid*/}
15
+
### غير صالح {/*invalid*/}
16
16
17
-
Examples of incorrect code for this rule:
17
+
أمثلة لشيفرة غير صحيحة لهذه القاعدة:
18
18
19
19
```js {expectedErrors: {'react-compiler': [14]}}
20
-
// ❌ Factory function creating components
20
+
// ❌ دالة مصنع تُنشئ مكوّنات
21
21
functioncreateComponent(defaultValue) {
22
22
returnfunctionComponent() {
23
23
// ...
24
24
};
25
25
}
26
26
27
-
// ❌ Component defined inside component
27
+
// ❌ مكوّن معرّف داخل مكوّن
28
28
functionParent() {
29
29
functionChild() {
30
30
// ...
@@ -33,38 +33,38 @@ function Parent() {
33
33
return<Child />;
34
34
}
35
35
36
-
// ❌ Hook factory function
36
+
// ❌ دالة مصنع لـ hook
37
37
functioncreateCustomHook(endpoint) {
38
38
returnfunctionuseData() {
39
39
// ...
40
40
};
41
41
}
42
42
```
43
43
44
-
### Valid {/*valid*/}
44
+
### صالح {/*valid*/}
45
45
46
-
Examples of correct code for this rule:
46
+
أمثلة لشيفرة صحيحة لهذه القاعدة:
47
47
48
48
```js
49
-
// ✅ Component defined at module level
49
+
// ✅ مكوّن معرّف على مستوى الوحدة
50
50
functionComponent({ defaultValue }) {
51
51
// ...
52
52
}
53
53
54
-
// ✅ Custom hook at module level
54
+
// ✅ hook مخصّص على مستوى الوحدة
55
55
functionuseData(endpoint) {
56
56
// ...
57
57
}
58
58
```
59
59
60
-
## Troubleshooting {/*troubleshooting*/}
60
+
## استكشاف الأعطال {/*troubleshooting*/}
61
61
62
-
### I need dynamic component behavior {/*dynamic-behavior*/}
Copy file name to clipboardExpand all lines: src/content/reference/eslint-plugin-react-hooks/lints/config.md
+24-24Lines changed: 24 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,44 +4,44 @@ title: config
4
4
5
5
<Intro>
6
6
7
-
Validates the compiler [configuration options](/reference/react-compiler/configuration).
7
+
يتحقق من [خيارات إعداد](/reference/react-compiler/configuration) المُصرّف.
8
8
9
9
</Intro>
10
10
11
-
## Rule Details {/*rule-details*/}
11
+
## تفاصيل القاعدة {/*rule-details*/}
12
12
13
-
React Compiler accepts various [configuration options](/reference/react-compiler/configuration) to control its behavior. This rule validates that your configuration uses correct option names and value types, preventing silent failures from typos or incorrect settings.
13
+
يقبل React Compiler عدة [خيارات إعداد](/reference/react-compiler/configuration)للتحكّم في سلوكه. تتحقق هذه القاعدة من أن إعدادك يستخدم أسماء خيارات صحيحة وأنواع قيم صحيحة، لتجنّب فشل صامت بسبب أخطاء مطبعية أو إعدادات خاطئة.
14
14
15
-
### Invalid {/*invalid*/}
15
+
### غير صالح {/*invalid*/}
16
16
17
-
Examples of incorrect code for this rule:
17
+
أمثلة لشيفرة غير صحيحة لهذه القاعدة:
18
18
19
19
```js
20
-
// ❌ Unknown option name
20
+
// ❌ اسم خيار غير معروف
21
21
module.exports= {
22
22
plugins: [
23
23
['babel-plugin-react-compiler', {
24
-
compileMode:'all'//Typo: should be compilationMode
24
+
compileMode:'all'//خطأ مطبعي: يجب أن يكون compilationMode
25
25
}]
26
26
]
27
27
};
28
28
29
-
// ❌ Invalid option value
29
+
// ❌ قيمة خيار غير صالحة
30
30
module.exports= {
31
31
plugins: [
32
32
['babel-plugin-react-compiler', {
33
-
compilationMode:'everything'//Invalid: use 'all' or 'infer'
33
+
compilationMode:'everything'//غير صالح: استخدم 'all' أو 'infer'
34
34
}]
35
35
]
36
36
};
37
37
```
38
38
39
-
### Valid {/*valid*/}
39
+
### صالح {/*valid*/}
40
40
41
-
Examples of correct code for this rule:
41
+
أمثلة لشيفرة صحيحة لهذه القاعدة:
42
42
43
43
```js
44
-
// ✅ Valid compiler configuration
44
+
// ✅ إعداد مُصرّف صالح
45
45
module.exports= {
46
46
plugins: [
47
47
['babel-plugin-react-compiler', {
@@ -52,38 +52,38 @@ module.exports = {
52
52
};
53
53
```
54
54
55
-
## Troubleshooting {/*troubleshooting*/}
55
+
## استكشاف الأعطال {/*troubleshooting*/}
56
56
57
-
### Configuration not working as expected {/*config-not-working*/}
57
+
### الإعداد لا يعمل كما تتوقع {/*config-not-working*/}
58
58
59
-
Your compiler configuration might have typos or incorrect values:
59
+
قد يحتوي إعداد المُصرّف على أخطاء مطبعية أو قيم خاطئة:
60
60
61
61
```js
62
-
// ❌ Wrong: Common configuration mistakes
62
+
// ❌ خطأ: أخطاء إعداد شائعة
63
63
module.exports= {
64
64
plugins: [
65
65
['babel-plugin-react-compiler', {
66
-
//Typo in option name
66
+
//خطأ مطبعي في اسم الخيار
67
67
compilationMod:'all',
68
-
//Wrong value type
68
+
//نوع قيمة خاطئ
69
69
panicThreshold:true,
70
-
//Unknown option
70
+
//خيار غير معروف
71
71
optimizationLevel:'max'
72
72
}]
73
73
]
74
74
};
75
75
```
76
76
77
-
Check the [configuration documentation](/reference/react-compiler/configuration)for valid options:
Copy file name to clipboardExpand all lines: src/content/reference/eslint-plugin-react-hooks/lints/error-boundaries.md
+18-18Lines changed: 18 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,35 +4,35 @@ title: error-boundaries
4
4
5
5
<Intro>
6
6
7
-
Validates usage of Error Boundaries instead of try/catch for errors in child components.
7
+
يتحقق من استخدام Error Boundaries بدلاً من try/catch لأخطاء المكوّنات الفرعية.
8
8
9
9
</Intro>
10
10
11
-
## Rule Details {/*rule-details*/}
11
+
## تفاصيل القاعدة {/*rule-details*/}
12
12
13
-
Try/catch blocks can't catch errors that happen during React's rendering process. Errors thrown in rendering methods or hooks bubble up through the component tree. Only[Error Boundaries](/reference/react/Component#catching-rendering-errors-with-an-error-boundary)can catch these errors.
13
+
لا تستطيع كتل try/catch التقاط أخطاء تحدث أثناء عملية التصيير في React. الأخطاء المرمية في دوال التصيير أو الـ hooks تنتقل عبر شجرة المكوّنات. فقط[Error Boundaries](/reference/react/Component#catching-rendering-errors-with-an-error-boundary)يمكنها التقاط هذه الأخطاء.
14
14
15
-
### Invalid {/*invalid*/}
15
+
### غير صالح {/*invalid*/}
16
16
17
-
Examples of incorrect code for this rule:
17
+
أمثلة لشيفرة غير صحيحة لهذه القاعدة:
18
18
19
19
```js {expectedErrors: {'react-compiler': [4]}}
20
-
// ❌ Try/catch won't catch render errors
20
+
// ❌ try/catch لن يلتقط أخطاء التصيير
21
21
functionParent() {
22
22
try {
23
-
return<ChildComponent />; //If this throws, catch won't help
23
+
return<ChildComponent />; //إذا رُمي خطأ هنا، catch لن يفيد
24
24
} catch (error) {
25
25
return<div>Error occurred</div>;
26
26
}
27
27
}
28
28
```
29
29
30
-
### Valid {/*valid*/}
30
+
### صالح {/*valid*/}
31
31
32
-
Examples of correct code for this rule:
32
+
أمثلة لشيفرة صحيحة لهذه القاعدة:
33
33
34
34
```js
35
-
// ✅ Using error boundary
35
+
// ✅ استخدام Error Boundary
36
36
functionParent() {
37
37
return (
38
38
<ErrorBoundary>
@@ -42,24 +42,24 @@ function Parent() {
42
42
}
43
43
```
44
44
45
-
## Troubleshooting {/*troubleshooting*/}
45
+
## استكشاف الأعطال {/*troubleshooting*/}
46
46
47
-
### Why is the linter telling me not to wrap `use`in`try`/`catch`? {/*why-is-the-linter-telling-me-not-to-wrap-use-in-trycatch*/}
47
+
### لماذا يطلب مني الـ linter عدم لفّ `use`داخل`try`/`catch`؟ {/*why-is-the-linter-telling-me-not-to-wrap-use-in-trycatch*/}
48
48
49
-
The `use`hook doesn't throw errors in the traditional sense, it suspends component execution. When `use`encounters a pending promise, it suspends the component and lets React show a fallback. Only Suspense and Error Boundaries can handle these cases. The linter warns against `try`/`catch`around`use`to prevent confusion as the `catch`block would never run.
49
+
لا يرمي الـ hook `use`أخطاء بالمعنى التقليدي؛ بل يعلّق تنفيذ المكوّن. عندما يصادف `use`وعداً معلّقاً، يعلّق المكوّن ويترك لـ React عرض حالة بديلة. فقط Suspense وError Boundaries يمكنها التعامل مع هذه الحالات. يحذّر الـ linter من `try`/`catch`حول`use`لتجنّب الالتباس لأن كتلة `catch`لن تعمل أبداً.
50
50
51
51
```js {expectedErrors: {'react-compiler': [5]}}
52
-
// ❌ Try/catch around `use` hook
52
+
// ❌ try/catch حول hook `use`
53
53
functionComponent({promise}) {
54
54
try {
55
-
constdata=use(promise); //Won't catch - `use` suspends, not throws
55
+
constdata=use(promise); //لن يلتقط — `use` يعلّق لا يرمي
56
56
return<div>{data}</div>;
57
57
} catch (error) {
58
-
return<div>Failed to load</div>; //Unreachable
58
+
return<div>Failed to load</div>; //لا يُنفَّذ
59
59
}
60
60
}
61
61
62
-
// ✅ Error boundary catches `use` errors
62
+
// ✅ Error boundary تلتقط أخطاء `use`
63
63
functionApp() {
64
64
return (
65
65
<ErrorBoundary fallback={<div>Failed to load</div>}>
0 commit comments