Skip to content

Commit efc65a4

Browse files
authored
Merge pull request #85 from maskeddeveloper/translation-faq-component-style
[Done] Translation of FAQ reference to faq-state.md
2 parents 52fddaf + ea63283 commit efc65a4

File tree

1 file changed

+47
-42
lines changed

1 file changed

+47
-42
lines changed

content/docs/faq-state.md

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,111 @@
11
---
22
id: faq-state
3-
title: Component State
3+
title: حالة المكونات
44
permalink: docs/faq-state.html
55
layout: docs
66
category: FAQ
77
---
8+
9+
### ماذا يفعل التابع `setState`؟ {#what-does-setstate-do}
810

9-
### What does `setState` do? {#what-does-setstate-do}
11+
يُجدوِل التابع `setState()`‎ تحديثًا لكائن حالة المكوّن `state`. عندما تتغير الحالة يستجب المكوّن بإعادة التصيير.
1012

11-
`setState()` schedules an update to a component's `state` object. When state changes, the component responds by re-rendering.
13+
### ما الفرق بين الحالة `state` والخاصيّات `props`؟ {#what-is-the-difference-between-state-and-props}
1214

13-
### What is the difference between `state` and `props`? {#what-is-the-difference-between-state-and-props}
15+
[`الخاصيّات props`](/docs/components-and-props.html) (اختصارًا للكلمة properties) و [`الحالة state`](/docs/state-and-lifecycle.html) كلاهما عبارة عن كائنات JavaScript مجرّدة. وفي حين أنّ كلاهما يحمل معلومات تؤثر في ناتج التصيير، فهما مختلفان بطريقة واحدة هامة، حيث تُمرَّر الخاصيّات إلى المكوّن (بشكل مماثل لمُعاملات الدالة) بينما تُدار الحالة `state` ضمن المكوّن (بشكل مشابه للمتغيرات المعرفة بداخل الدالة).
1416

15-
[`props`](/docs/components-and-props.html) (short for "properties") and [`state`](/docs/state-and-lifecycle.html) are both plain JavaScript objects. While both hold information that influences the output of render, they are different in one important way: `props` get passed *to* the component (similar to function parameters) whereas `state` is managed *within* the component (similar to variables declared within a function).
16-
17-
Here are some good resources for further reading on when to use `props` vs `state`:
17+
هنا تجد مصادر جيدة لقراءة المزيد حول استخدام الخاصيّات والحالة:
1818
* [Props vs State](https://github.com/uberVU/react-guide/blob/master/props-vs-state.md)
1919
* [ReactJS: Props vs. State](https://lucybain.com/blog/2016/react-state-vs-pros/)
2020

21-
### Why is `setState` giving me the wrong value? {#why-is-setstate-giving-me-the-wrong-value}
21+
### لماذا يُعطيني التابع `setState` القيمة الخاطئة؟ {#why-is-setstate-giving-me-the-wrong-value}
2222

23-
In React, both `this.props` and `this.state` represent the *rendered* values, i.e. what's currently on the screen.
23+
في React تُمثل `this.props` و `this.state` القيم المُصيَّرة، أي المعروضة على الشاشة حاليًّا.
2424

25-
Calls to `setState` are asynchronous - don't rely on `this.state` to reflect the new value immediately after calling `setState`. Pass an updater function instead of an object if you need to compute values based on the current state (see below for details).
25+
تكون استدعاءات التابع `setState` غير متزامنة، فلا تعتمد على `this.state` لتعكس القيمة الجديدة للحالة بشكل مباشر بعد استدعاء التابع setState. مرر دالة تحديث بدلًا من تمرير كائن إن احتجت لحساب القيم بناءً على الحالة الحاليّة (انظر في الأسفل للمزيد من التفاصيل).
2626

27-
Example of code that will *not* behave as expected:
27+
مثال عن شيفرة لن تعمل كما هو متوقع:
2828

2929
```jsx
3030
incrementCount() {
31-
// Note: this will *not* work as intended.
31+
// ملاحظة: لن يعمل هذا كما هو متوقع
3232
this.setState({count: this.state.count + 1});
3333
}
3434

3535
handleSomething() {
36-
// Let's say `this.state.count` starts at 0.
36+
// فلنقل أنّ this.state.count تبدأ بالقيمة 0
3737
this.incrementCount();
3838
this.incrementCount();
3939
this.incrementCount();
40-
// When React re-renders the component, `this.state.count` will be 1, but you expected 3.
40+
// عندما تعيد React تصيير المكون فستصبح قيمة this.state.count 1
41+
// ولكنك كنت تتوقعها أنها 3
4142

42-
// This is because `incrementCount()` function above reads from `this.state.count`,
43-
// but React doesn't update `this.state.count` until the component is re-rendered.
44-
// So `incrementCount()` ends up reading `this.state.count` as 0 every time, and sets it to 1.
43+
44+
// هذا لأنّ الدالة incrementCount()
45+
// تقرأ this.state.count
46+
// ولكن لا تحدث React قيمتها حتى إعادة تصيير المكون
47+
// لذا ستقرأ React قيمة هذه الدالة على أنها صفر في كل مرة وستعينها للقيمة واحد
4548

46-
// The fix is described below!
49+
// الحل موصوف لاحقًا
4750
}
4851
```
4952

50-
See below for how to fix this problem.
53+
انظر في الأسفل لمعرفة كيفية إصلاح هذه المشكلة.
54+
55+
56+
### كيف أحدث الحالة بقيم تعتمد على الحالة الحالية؟ {#how-do-i-update-state-with-values-that-depend-on-the-current-state}
5157

52-
### How do I update state with values that depend on the current state? {#how-do-i-update-state-with-values-that-depend-on-the-current-state}
58+
مرر دالة بدلًا من كائن إلى التابع `setState` لضمان استخدام الاستدعاء دائمًا لآخر إصدار من الحالة.
5359

54-
Pass a function instead of an object to `setState` to ensure the call always uses the most updated version of state (see below).
5560

56-
### What is the difference between passing an object or a function in `setState`? {#what-is-the-difference-between-passing-an-object-or-a-function-in-setstate}
61+
### ما الفرق بين تمرير كائن أو دالة إلى التابع `setState`؟ {#what-is-the-difference-between-passing-an-object-or-a-function-in-setstate}
5762

58-
Passing an update function allows you to access the current state value inside the updater. Since `setState` calls are batched, this lets you chain updates and ensure they build on top of each other instead of conflicting:
63+
يسمح لك تمرير دالة التحديث بالوصول إلى قيمة الحالة الحالية بداخل دالة التحديث. وبما أنّ استدعاءات التابع `setState` مجدولة سيسمح لك ذلك بسلسلة التحديثات وضمان أنّها تبني فوق بعضها بدلًا من التعارض فيما بينها:
5964

6065
```jsx
6166
incrementCount() {
6267
this.setState((state) => {
63-
// Important: read `state` instead of `this.state` when updating.
68+
// هام: اقرأ قيمة prevState بدلًا من this.state عند التحديث
6469
return {count: state.count + 1}
6570
});
6671
}
6772

6873
handleSomething() {
69-
// Let's say `this.state.count` starts at 0.
74+
// فلنفترض أنّ قيمة this.state.count تبدأ من الصفر
7075
this.incrementCount();
7176
this.incrementCount();
7277
this.incrementCount();
7378

74-
// If you read `this.state.count` now, it would still be 0.
75-
// But when React re-renders the component, it will be 3.
79+
// إن قرأت قيمة this.state.count الآن فستكون لا زالت صفر
80+
// ولكن عندما يعاد تصيير المكون فستصبح 3
7681
}
7782
```
7883

79-
[Learn more about setState](/docs/react-component.html#setstate)
84+
[تعلم المزيد حول setState.](/docs/react-component.html#setstate)
8085

81-
### When is `setState` asynchronous? {#when-is-setstate-asynchronous}
86+
### متى يكون التابع `setState` غير متزامن؟ {#when-is-setstate-asynchronous}
8287

83-
Currently, `setState` is asynchronous inside event handlers.
88+
حاليًّا التابع setState غير متزامن بداخل معالج الأحداث.
8489

85-
This ensures, for example, that if both `Parent` and `Child` call `setState` during a click event, `Child` isn't re-rendered twice. Instead, React "flushes" the state updates at the end of the browser event. This results in significant performance improvements in larger apps.
90+
إن كان المكوّن الأب `Parent` والمكوّن الابن `Child` يستدعيان التابع `setState` خلال حدث النقر يضمن لنا عدم التزامن ألّا يُعاد تصيير المكوّن الابن `Child` مرتين، وبدلًا من ذلك تمسح React تحديثات الحالة في نهاية أحداث المتصفّح. ينتج عن هذا تحسين هام في الأداء في التطبيقات الكبيرة.
8691

87-
This is an implementation detail so avoid relying on it directly. In the future versions, React will batch updates by default in more cases.
92+
لا يزال هذا تفصيلًا تنفيذيًّا لذا تجنّب الاعتماد عليه بشكل مباشر. في الإصدارات القادمة ستطبّق React التحديثات بشكل افتراضي في حالات أكثر.
8893

89-
### Why doesn't React update `this.state` synchronously? {#why-doesnt-react-update-thisstate-synchronously}
94+
### لماذا لا تُحدِّث React قيمة `this.state` بشكلٍ متزامن؟ {#why-doesnt-react-update-thisstate-synchronously}
9095

91-
As explained in the previous section, React intentionally "waits" until all components call `setState()` in their event handlers before starting to re-render. This boosts performance by avoiding unnecessary re-renders.
96+
كما تحدثنا في القسم السابق، تنتظر React عن قصد حتى تستدعي جميع المكوّنات التابع `setState()`‎ في مُعالِجات أحداثها قبل البدء بإعادة التصيير. يُسرِّع هذا الأداء عن طريق تجنّب إعادة التصيير غير الضروريّة.
9297

93-
However, you might still be wondering why React doesn't just update `this.state` immediately without re-rendering.
98+
على أيّة حال قد لا تزال تتساءل لماذا لا تُحدِّث React قيمة `this.state` بشكل مباشر وبدون إعادة التصيير.
9499

95-
There are two main reasons:
100+
هنالك سببان رئيسيّان:
96101

97-
* This would break the consistency between `props` and `state`, causing issues that are very hard to debug.
98-
* This would make some of the new features we're working on impossible to implement.
102+
* يخرق هذا التوافقيّة بين الخاصيّات `props` والحالة `state`، مسببًا مشاكل من الصعب تنقيحها.
103+
* سيجعل هذا من بعض الميّزات التي نعمل عليها مستحيلة التطبيق.
99104

100-
This [GitHub comment](https://github.com/facebook/react/issues/11527#issuecomment-360199710) dives deep into the specific examples.
105+
يشرح [ هذا التعليق في GitHub](https://github.com/facebook/react/issues/11527#issuecomment-360199710) بالتفصيل أمثلة عن هذا.
101106

102-
### Should I use a state management library like Redux or MobX? {#should-i-use-a-state-management-library-like-redux-or-mobx}
107+
### هل ينبغي أن أستخدم مكتبات إدارة الحالة مثل Redux أو MobX؟ {#should-i-use-a-state-management-library-like-redux-or-mobx}
103108

104-
[Maybe.](https://redux.js.org/faq/general#when-should-i-use-redux)
109+
[ربّما.](https://redux.js.org/faq/general#when-should-i-use-redux)
105110

106-
It's a good idea to get to know React first, before adding in additional libraries. You can build quite complex applications using only React.
111+
من الأفضل في البداية التعرّف على React أولًا قبل إضافة مكتبات أخرى. بإمكانك بناء تطبيقات معقدة وكبيرة باستخدام React فقط.

0 commit comments

Comments
 (0)