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: content/docs/conditional-rendering.md
+29-29Lines changed: 29 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,18 @@
1
1
---
2
2
id: conditional-rendering
3
-
title: Conditional Rendering
3
+
title: التصيير الشرطي (Conditional Rendering)
4
4
permalink: docs/conditional-rendering.html
5
5
prev: handling-events.html
6
6
next: lists-and-keys.html
7
7
redirect_from:
8
8
- "tips/false-in-jsx.html"
9
9
---
10
10
11
-
In React, you can create distinct components that encapsulate behavior you need. Then, you can render only some of them, depending on the state of your application.
11
+
من خلال React، يمكنك أن تنشيء مكونات (Components) متميزة، والتي تغلف السلوك الذي تريده. ثم يمكنك ان تعرض فقط بعض هذه المكونات، بناءاً على الحالة (State) في التطبيق الخاص بك.
12
12
13
-
Conditional rendering in React works the same way conditions work in JavaScript. Use JavaScript operators like [`if`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else)or the [conditional operator](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Conditional_Operator)to create elements representing the current state, and let React update the UI to match them.
13
+
العرض الشرطي في React يعمل بنفس طريقة عمل العرض الشرطي في لغة JavaScript. قم يإستخدام المعاملات الخاصة بلغة JavaScript، مثل [`if`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else)أو [conditional operator](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Conditional_Operator)لإنشاء العناصر التي تمثل الحالة (State)، وسوف يقوم React بتحديث الواجهه الأماميه (UI) لمطابقتها.
14
14
15
-
Consider these two components:
15
+
أنظر إلى هذين المكوّنين:
16
16
17
17
```js
18
18
functionUserGreeting(props) {
@@ -24,7 +24,7 @@ function GuestGreeting(props) {
24
24
}
25
25
```
26
26
27
-
We'll create a `Greeting` component that displays either of these components depending on whether a user is logged in:
27
+
سوف ننشيء مكون (Component) لتحية المستخدم، والذي يعرض أحد هذين المكوّنين بناءاً على حالة تسجيل دخول المستخدم:
28
28
29
29
```javascript{3-7,11,12}
30
30
function Greeting(props) {
@@ -42,15 +42,15 @@ ReactDOM.render(
42
42
);
43
43
```
44
44
45
-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/ZpVxNq?editors=0011)
45
+
[**جرّب المثال على موقع CodePen**](https://codepen.io/gaearon/pen/ZpVxNq?editors=0011)
46
46
47
-
This example renders a different greeting depending on the value of `isLoggedIn` prop.
47
+
هذا المثال يعرض تحيه مختلفه بناءاً على قيمة الخاصيّه `isLoggedIn`.
48
48
49
-
### Element Variables {#element-variables}
49
+
### متغيرات العناصر (Element Variables) {#element-variables}
50
50
51
-
You can use variables to store elements. This can help you conditionally render a part of the component while the rest of the output doesn't change.
51
+
يمكنك استخدام المتغيرات لحفظ العناصر. هذا يجعلك قادراً على عمل تصيير شرطي لجزء من المكوّنً، بينما باقي المخرجات لا تتغير.
52
52
53
-
Consider these two new components representing Logout and Login buttons:
53
+
أنظر إلى هذين المكوّنين الجديدين، والذين يمثلان أزرار لتسجيل الدخول والخروج للمستخدم:
54
54
55
55
```js
56
56
functionLoginButton(props) {
@@ -70,9 +70,9 @@ function LogoutButton(props) {
70
70
}
71
71
```
72
72
73
-
In the example below, we will create a [stateful component](/docs/state-and-lifecycle.html#adding-local-state-to-a-class)called`LoginControl`.
73
+
في المثال التالي، سوف نقوم بإنشاء [مكوّن صنف stateful component](/docs/state-and-lifecycle.html#adding-local-state-to-a-class)يسمى`LoginControl`.
74
74
75
-
It will render either`<LoginButton />`or`<LogoutButton />` depending on its current state. It will also render a `<Greeting />` from the previous example:
75
+
سوف يقوم بتصيير إما`<LoginButton />`أو`<LogoutButton />`، بناءاً على حالة المكوّن. سوف يقوم أيضاً بتصيير مكوّن تحية المستخدم، والذي رأيناه في المثال السابق:
76
76
77
77
```javascript{20-25,29,30}
78
78
class LoginControl extends React.Component {
@@ -116,13 +116,13 @@ ReactDOM.render(
116
116
);
117
117
```
118
118
119
-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/QKzAgB?editors=0010)
119
+
[**جرّب المثال على موقع CodePen**](https://codepen.io/gaearon/pen/QKzAgB?editors=0010)
120
120
121
-
While declaring a variable and using an `if` statement is a fine way to conditionally render a component, sometimes you might want to use a shorter syntax. There are a few ways to inline conditions in JSX, explained below.
121
+
بينما يعتبر استخدام المتغيرات والتعبير الشرطي if هي طريقه سليمه لعمل التصيير الشرطي للمكوّن، إلا أنّك في بعض الأحيان قد ترغب في استخدام صياغه أقصر. هناك بعض الطرق تمكنك من استخدام التعبير الشرطي المباشر في JSX، شرح هذه الطرق بالأسفل.
122
122
123
-
### Inline If with Logical && Operator {#inline-if-with-logical--operator}
123
+
### التعبير الشرطي المباشر بإستخدام معامل && المنطقي {#inline-if-with-logical--operator}
124
124
125
-
You may [embed any expressions in JSX](/docs/introducing-jsx.html#embedding-expressions-in-jsx)by wrapping them in curly braces. This includes the JavaScript logical `&&`operator. It can be handy for conditionally including an element:
125
+
يمكنك [تضمين أيّ تعبيرات في JSX](/docs/introducing-jsx.html#embedding-expressions-in-jsx)من خلال تغليفهم داخل القوسان المعقوصان `{}`. يتضمن هذا معامل `&&`المنطقي في JavaScript. قد يصبح هذا سهل الاستخدام لتضمين عنصر بشكل شرطي:
126
126
127
127
```js{6-10}
128
128
function Mailbox(props) {
@@ -146,17 +146,17 @@ ReactDOM.render(
146
146
);
147
147
```
148
148
149
-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/ozJddz?editors=0010)
149
+
[**جرّب المثال على موقع CodePen**](https://codepen.io/gaearon/pen/ozJddz?editors=0010)
150
150
151
-
It works because in JavaScript, `true && expression`always evaluates to`expression`, and `false && expression`always evaluates to`false`.
151
+
هذا المثال يعمل بنجاح لأنه في JavaScript، التعبير `true && expression`دائماً يعطي الناتج`expression`، و التعبير `false && expression`دائماً يعطي الناتج`false`.
152
152
153
-
Therefore, if the condition is `true`, the element right after`&&`will appear in the output. If it is`false`, React will ignore and skip it.
153
+
ولذلك، إذا كان الشرط يعطي الناتج `true`، فإن العنصر المحدد بعد`&&`سوف يظهر في المخرجات. وإذا كان الناتج`false`، فإن React سوف تهمل العنصر وتتخطّاه.
154
154
155
-
### Inline If-Else with Conditional Operator {#inline-if-else-with-conditional-operator}
155
+
### التعبير الشرطي المباشر (If-Else) بإستخدام المعامل الشرطي {#inline-if-else-with-conditional-operator}
156
156
157
-
Another method for conditionally rendering elements inline is to use the JavaScript conditional operator[`condition ? true : false`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Conditional_Operator).
157
+
طريقه أخرى للتصيير الشرطي المباشر في JSX بإستخدام المعامل الشرطي[`condition ? true : false`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Conditional_Operator).
158
158
159
-
In the example below, we use it to conditionally render a small block of text.
159
+
في المثال التالي، سوف نستخدم هذه الطريقه لتصيير نص قصير بشكل شرطي:
160
160
161
161
```javascript{5}
162
162
render() {
@@ -169,7 +169,7 @@ render() {
169
169
}
170
170
```
171
171
172
-
It can also be used for larger expressions although it is less obvious what's going on:
172
+
يمكن استخدام هذه الطريقه أيضاً في التعبيرات الأكبر، بالرغم من أن هذا يجعل الامر أقل وضوحاً لفهم ما يحدث:
173
173
174
174
```js{5,7,9}
175
175
render() {
@@ -186,13 +186,13 @@ render() {
186
186
}
187
187
```
188
188
189
-
Just like in JavaScript, it is up to you to choose an appropriate style based on what you and your team consider more readable. Also remember that whenever conditions become too complex, it might be a good time to [extract a component](/docs/components-and-props.html#extracting-components).
189
+
كما هو الحال في JavaScript، يمكنك اختيار النمط المناسب بناءاً على ما تعتبره أنت وفريقك أكثر سهوله في القراءه. تذكّر أيضاً أنّه عندما يصبح التعبير الشرطي اكثر تعقيداً، قد يكون هذا هو الوقت المناسب لـ [استخلاص مكوّن](/docs/components-and-props.html#extracting-components).
190
190
191
-
### Preventing Component from Rendering {#preventing-component-from-rendering}
191
+
### منع المكوّن (Component) من التصيير {#preventing-component-from-rendering}
192
192
193
-
In rare cases you might want a component to hide itself even though it was rendered by another component. To do this return `null`instead of its render output.
193
+
في بعض الحالات النادره، قد تفضّل أن تجعل المكوّن يخفي نفسه، بالرغم من أنّه تم تصييره من خلال مكوّن آخر. يمكنك فعل ذلك من خلال إعطاء الناتج `null`بدلاً من تصيير مخرجات المكوّن.
194
194
195
-
In the example below, the `<WarningBanner />`is rendered depending on the value of the prop called `warn`. If the value of the prop is `false`, then the component does not render:
195
+
في المثال التالي، المكوّن `<WarningBanner />`يتم تصييره بناءاً على قيمة الخاصيّه `warn`. إذا كانت قيمة الخاصيّه تساوي `false`، فإن المكوّن لن يتم تصييره:
196
196
197
197
```javascript{2-4,29}
198
198
function WarningBanner(props) {
@@ -238,6 +238,6 @@ ReactDOM.render(
238
238
);
239
239
```
240
240
241
-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/Xjoqwm?editors=0010)
241
+
[**جرّب المثال على موقع CodePen**](https://codepen.io/gaearon/pen/Xjoqwm?editors=0010)
242
242
243
-
Returning `null`from a component's `render`method does not affect the firing of the component's lifecycle methods. For instance`componentDidUpdate`will still be called.
243
+
إعطاء الناتج `null`في التابع `render`الخاص بالمكوّن لا يؤثر على حدوث التوابع الخاصه بدورة حياة المكوّن (Lifecycle Methods). فمثلاً التابع`componentDidUpdate`سوف يتم استدعاءه كالمعتاد.
0 commit comments