Skip to content

Commit 4d14f8b

Browse files
authored
Merge pull request #22 from AdhamMoussa/conditional_rendering
Translating conditional-rendering.md
2 parents 6bf907d + 2101178 commit 4d14f8b

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

content/docs/conditional-rendering.md

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
---
22
id: conditional-rendering
3-
title: Conditional Rendering
3+
title: التصيير الشرطي (Conditional Rendering)
44
permalink: docs/conditional-rendering.html
55
prev: handling-events.html
66
next: lists-and-keys.html
77
redirect_from:
88
- "tips/false-in-jsx.html"
99
---
1010

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) في التطبيق الخاص بك.
1212

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) لمطابقتها.
1414

15-
Consider these two components:
15+
أنظر إلى هذين المكوّنين:
1616

1717
```js
1818
function UserGreeting(props) {
@@ -24,7 +24,7 @@ function GuestGreeting(props) {
2424
}
2525
```
2626

27-
We'll create a `Greeting` component that displays either of these components depending on whether a user is logged in:
27+
سوف ننشيء مكون (Component) لتحية المستخدم، والذي يعرض أحد هذين المكوّنين بناءاً على حالة تسجيل دخول المستخدم:
2828

2929
```javascript{3-7,11,12}
3030
function Greeting(props) {
@@ -42,15 +42,15 @@ ReactDOM.render(
4242
);
4343
```
4444

45-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/ZpVxNq?editors=0011)
45+
[**جرّب المثال على موقع CodePen**](https://codepen.io/gaearon/pen/ZpVxNq?editors=0011)
4646

47-
This example renders a different greeting depending on the value of `isLoggedIn` prop.
47+
هذا المثال يعرض تحيه مختلفه بناءاً على قيمة الخاصيّه `isLoggedIn`.
4848

49-
### Element Variables {#element-variables}
49+
### متغيرات العناصر (Element Variables) {#element-variables}
5050

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+
يمكنك استخدام المتغيرات لحفظ العناصر. هذا يجعلك قادراً على عمل تصيير شرطي لجزء من المكوّنً، بينما باقي المخرجات لا تتغير.
5252

53-
Consider these two new components representing Logout and Login buttons:
53+
أنظر إلى هذين المكوّنين الجديدين، والذين يمثلان أزرار لتسجيل الدخول والخروج للمستخدم:
5454

5555
```js
5656
function LoginButton(props) {
@@ -70,9 +70,9 @@ function LogoutButton(props) {
7070
}
7171
```
7272

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`.
7474

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 />`، بناءاً على حالة المكوّن. سوف يقوم أيضاً بتصيير مكوّن تحية المستخدم، والذي رأيناه في المثال السابق:
7676

7777
```javascript{20-25,29,30}
7878
class LoginControl extends React.Component {
@@ -116,13 +116,13 @@ ReactDOM.render(
116116
);
117117
```
118118

119-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/QKzAgB?editors=0010)
119+
[**جرّب المثال على موقع CodePen**](https://codepen.io/gaearon/pen/QKzAgB?editors=0010)
120120

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، شرح هذه الطرق بالأسفل.
122122

123-
### Inline If with Logical && Operator {#inline-if-with-logical--operator}
123+
### التعبير الشرطي المباشر بإستخدام معامل && المنطقي {#inline-if-with-logical--operator}
124124

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. قد يصبح هذا سهل الاستخدام لتضمين عنصر بشكل شرطي:
126126

127127
```js{6-10}
128128
function Mailbox(props) {
@@ -146,17 +146,17 @@ ReactDOM.render(
146146
);
147147
```
148148

149-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/ozJddz?editors=0010)
149+
[**جرّب المثال على موقع CodePen**](https://codepen.io/gaearon/pen/ozJddz?editors=0010)
150150

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`.
152152

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 سوف تهمل العنصر وتتخطّاه.
154154

155-
### Inline If-Else with Conditional Operator {#inline-if-else-with-conditional-operator}
155+
### التعبير الشرطي المباشر (If-Else) بإستخدام المعامل الشرطي {#inline-if-else-with-conditional-operator}
156156

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).
158158

159-
In the example below, we use it to conditionally render a small block of text.
159+
في المثال التالي، سوف نستخدم هذه الطريقه لتصيير نص قصير بشكل شرطي:
160160

161161
```javascript{5}
162162
render() {
@@ -169,7 +169,7 @@ render() {
169169
}
170170
```
171171

172-
It can also be used for larger expressions although it is less obvious what's going on:
172+
يمكن استخدام هذه الطريقه أيضاً في التعبيرات الأكبر، بالرغم من أن هذا يجعل الامر أقل وضوحاً لفهم ما يحدث:
173173

174174
```js{5,7,9}
175175
render() {
@@ -186,13 +186,13 @@ render() {
186186
}
187187
```
188188

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).
190190

191-
### Preventing Component from Rendering {#preventing-component-from-rendering}
191+
### منع المكوّن (Component) من التصيير {#preventing-component-from-rendering}
192192

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` بدلاً من تصيير مخرجات المكوّن.
194194

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`، فإن المكوّن لن يتم تصييره:
196196

197197
```javascript{2-4,29}
198198
function WarningBanner(props) {
@@ -238,6 +238,6 @@ ReactDOM.render(
238238
);
239239
```
240240

241-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/Xjoqwm?editors=0010)
241+
[**جرّب المثال على موقع CodePen**](https://codepen.io/gaearon/pen/Xjoqwm?editors=0010)
242242

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

Comments
 (0)