Skip to content

Commit f8cd763

Browse files
authored
Merge pull request #30 from galtalmor/conditional-rendering-translate
Translate Conditional Rendering page
2 parents 1e771b1 + 3caf8b9 commit f8cd763

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

content/docs/conditional-rendering.md

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
---
22
id: conditional-rendering
3-
title: Conditional Rendering
3+
title: רינדור מותנה
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, אתם יכולים ליצור קומפוננטות יחודיות אשר מכמסות את ההתנהגות שאתם מחפשים. לאחר מכן, אתם יכולים לרנדר רק חלק מהן, על פי תלות ב-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) או [האופרטו המותנה](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Conditional_Operator) כדי ליצור אלמנטים המייצגים את ה-state הנוכחי, ותנו ל-React לעדכן את ממשק המשתמש כדי שיהיה תואם אליהם.
1414

15-
Consider these two components:
15+
הביטו בשתי הקומפוננטות האלו:
1616

1717
```js
1818
function UserGreeting(props) {
19-
return <h1>Welcome back!</h1>;
19+
return <h1>ברוך הבא!</h1>;
2020
}
2121

2222
function GuestGreeting(props) {
23-
return <h1>Please sign up.</h1>;
23+
return <h1>אנא הירשם.</h1>;
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+
ניצור קומפוננטת `Greeting` שמציגה אחת מהקומפוננטות האלו כתלות באם משתמש מחובר:
2828

2929
```javascript{3-7,11,12}
3030
function Greeting(props) {
@@ -42,37 +42,37 @@ 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+
דוגמא זו מרנדרת ברכה שונה כתלות בערך של ה-prop `isLoggedIn`.
4848

49-
### Element Variables {#element-variables}
49+
### משתני אלמנט {#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) {
5757
return (
5858
<button onClick={props.onClick}>
59-
Login
59+
התחבר
6060
</button>
6161
);
6262
}
6363

6464
function LogoutButton(props) {
6565
return (
6666
<button onClick={props.onClick}>
67-
Logout
67+
התנתק
6868
</button>
6969
);
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+
בדוגמה הבאה, ניצור [קומפוננטה התלויה ב-state](/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 />` כתלות ב-state הנוכחי שלה. בנוסף היא תרנדר `<Greeting />` מהדוגמה הקודמת:
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+
### הטמעת תנאי If עם אופרטור && לוגי {#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) {
@@ -132,7 +132,7 @@ function Mailbox(props) {
132132
<h1>Hello!</h1>
133133
{unreadMessages.length > 0 &&
134134
<h2>
135-
You have {unreadMessages.length} unread messages.
135+
יש לך {unreadMessages.length} הודעות שלא נקראו.
136136
</h2>
137137
}
138138
</div>
@@ -146,30 +146,30 @@ 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+
שיטה נוספת להטמעת רינדור אלמנטים מותנה היא להשתמש באופרטור ההתנייה של JavaScript [`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() {
163163
const isLoggedIn = this.state.isLoggedIn;
164164
return (
165165
<div>
166-
The user is <b>{isLoggedIn ? 'currently' : 'not'}</b> logged in.
166+
המשתמש <b>{isLoggedIn ? 'כרגע' : 'לא'}</b> מחובר.
167167
</div>
168168
);
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+
### מניעת רינדור של קומפוננטה {#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 />` מרונדר בהתאם לערך של ה-prop שנקרא `warn`. אם ערך ה-prop הוא `false`, אזי הרכיב אינו מתרנדר:
196196

197197
```javascript{2-4,29}
198198
function WarningBanner(props) {
@@ -202,7 +202,7 @@ function WarningBanner(props) {
202202
203203
return (
204204
<div className="warning">
205-
Warning!
205+
אזהרה!
206206
</div>
207207
);
208208
}
@@ -225,7 +225,7 @@ class Page extends React.Component {
225225
<div>
226226
<WarningBanner warn={this.state.showWarning} />
227227
<button onClick={this.handleToggleClick}>
228-
{this.state.showWarning ? 'Hide' : 'Show'}
228+
{this.state.showWarning ? 'הסתר' : 'הצג'}
229229
</button>
230230
</div>
231231
);
@@ -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` של קומפוננטה לא משפיעה על הרצת מתודות מחזור החיים של קומפוננטה. למשל `componentDidUpdate` עדיין יקרא.

0 commit comments

Comments
 (0)