Skip to content

Conditional rendering #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
1f2dbb7
Update languages for Simplified Chinese completion (#1854)
tesseralis Mar 20, 2019
30a121c
Translate hello-world.md
sorousht Mar 21, 2019
6bd90d6
Merge branch 'master' of https://github.com/reactjs/reactjs.org into …
reactjs-translation-bot Mar 22, 2019
0c48554
Fix a spelling error
sorousht Mar 24, 2019
e744030
removed line as functions can have state now too (#1783)
saranshkataria Mar 25, 2019
ee4188b
remove ReactWeek from Conference list (#1864)
jcreighton Mar 25, 2019
448b7f1
Remove ReactNYC meetup from the list
gaearon Mar 26, 2019
a1a7ec3
Added RQ React meetup in Philadelphia (#1866)
pixelyunicorn Mar 26, 2019
6faeeb8
Adding immer in the list of immutable libraries (#1839)
pavanmehta91 Mar 26, 2019
2304fa1
📦 NEW: Add React.js Lahore Meetup Group (#1873)
Mar 26, 2019
5b0c1d4
Update content/docs/hello-world.md
sJJdGG Mar 27, 2019
c53fbb1
Update content/docs/hello-world.md
sJJdGG Mar 27, 2019
ab9e0e4
Update content/docs/hello-world.md
sJJdGG Mar 27, 2019
06f40f5
Update content/docs/hello-world.md
sJJdGG Mar 27, 2019
87ebd4b
Update content/docs/hello-world.md
sJJdGG Mar 27, 2019
496f2e4
Update content/docs/hello-world.md
sJJdGG Mar 27, 2019
3275589
Update content/docs/hello-world.md
sJJdGG Mar 27, 2019
96951e0
Update content/docs/hello-world.md
sJJdGG Mar 27, 2019
78d3ad0
Update content/docs/hello-world.md
sJJdGG Mar 27, 2019
d36d334
Update content/docs/hello-world.md
sJJdGG Mar 27, 2019
7df35ef
Update content/docs/hello-world.md
sJJdGG Mar 27, 2019
1ab34f6
Merge branch 'master' of https://github.com/reactjs/reactjs.org into …
reactjs-translation-bot Mar 27, 2019
9080ec3
Update TRANSLATION.md
mohsenkhanpour Mar 27, 2019
35c81c9
Merge pull request #42 from mohsenkhanpour/patch-1
sorousht Mar 27, 2019
4541a8f
Update languages.yml
tesseralis Mar 28, 2019
c6f99a6
Add kannada to languages
tesseralis Mar 28, 2019
2753191
Bump React versions
gaearon Mar 28, 2019
d0f2db9
removed sentence since functions can have state (#1878)
saranshkataria Mar 28, 2019
ef0d10d
merging all conflicts
reactjs-translation-bot Mar 29, 2019
982a2d2
Merge pull request #38 from sorousht/hello-world
sorousht Mar 29, 2019
f39fcc8
Remove a sentece which was originally removed
sorousht Mar 29, 2019
1099d24
Merge pull request #43 from reactjs/sync-d0f2db96
sorousht Mar 29, 2019
59c3c0a
Fix explanation of the `useState` example in 'Hooks API Reference' pa…
g12i Mar 29, 2019
b475d02
Merge pull request #44 from reactjs/fa
sJJdGG Mar 31, 2019
1a20fca
Merge branch 'master' of https://github.com/reactjs/reactjs.org into …
reactjs-translation-bot Apr 1, 2019
8de5aff
Update languages.yml to show italian finishing
tesseralis Apr 2, 2019
7daa6b3
Merge branch 'master' of https://github.com/reactjs/reactjs.org into …
reactjs-translation-bot Apr 3, 2019
c7dde3d
Add Chain React to conferences list (#1900)
bondparkerbond Apr 3, 2019
2a1b089
Fix 1640: Formatting for code blocks nested in blockquote (#1899)
camilogiraldo Apr 3, 2019
2fbc061
Merge branch 'master' of https://github.com/reactjs/reactjs.org into …
reactjs-translation-bot Apr 5, 2019
d2484f6
done with translation of conditional-rendering
blacksheepIV Apr 10, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion TRANSLATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@
<td>
داده
</td>
</tr>
<tr>
<td dir="ltr">
element
</td>
<td>
المنت
</td>
</tr>
<tr>
<td dir="ltr">
Expand Down Expand Up @@ -243,6 +251,11 @@
<td>
RFC
</td>
</tr>
<tr>
<td>
scope
</td>
</tr>
<tr>
<td>
Expand All @@ -268,4 +281,4 @@
</table>
<p dir="rtl">
اگر فکر می‌کنید چیزی فراموش شده‌است یا نیاز به تصحیح دارد، حتما نظر خود را با ما درمیان بگذارید.
</p>
</p>
7 changes: 4 additions & 3 deletions content/community/conferences.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ June 21, 2019 Chicago, Illinois USA

[Website](https://reactloop.com) - [Twitter](https://twitter.com/ReactLoop)

### React Week '19 {#RWNY19}
July 15-21, 2019. New York City, USA
### Chain React 2019
July 11-12, 2019. Portland, OR, USA.

[Website](https://reactweek.nyc) - [Twitter](https://twitter.com/ReactWeek)
[Website](https://infinite.red/ChainReactConf)

### React Rally 2019
August 22-23, 2019. Salt Lake City, USA.
Expand All @@ -64,6 +64,7 @@ August 22-23, 2019. Salt Lake City, USA.

### ComponentsConf 2019 {#componentsconf-2019}
September 6, 2019 in Melbourne, Australia

[Website](https://www.componentsconf.com.au/) - [Twitter](https://twitter.com/componentsconf)

### React Native EU 2019 {#react-native-eu-2019}
Expand Down
3 changes: 2 additions & 1 deletion content/community/meetups.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Do you have a local React.js meetup? Add it here! (Please keep the list alphabet

## Pakistan {#pakistan}
* [Karachi](https://www.facebook.com/groups/902678696597634/)
* [Lahore](https://www.facebook.com/groups/ReactjsLahore/)

## Peru {#peru}
* [Lima](https://www.meetup.com/ReactJS-Peru/)
Expand Down Expand Up @@ -130,8 +131,8 @@ Do you have a local React.js meetup? Add it here! (Please keep the list alphabet
* [New York, NY - ReactJS](https://www.meetup.com/NYC-Javascript-React-Group/)
* [New York, NY - React Ladies](https://www.meetup.com/React-Ladies/)
* [New York, NY - React Native](https://www.meetup.com/React-Native-NYC/)
* [New York, NY - ReactNYC](https://www.meetup.com/ReactNYC/)
* [Palo Alto, CA - React Native](https://www.meetup.com/React-Native-Silicon-Valley/)
* [Philadelphia, PA - ReactJS](https://www.meetup.com/RQ-React/)
* [Phoenix, AZ - ReactJS](https://www.meetup.com/ReactJS-Phoenix/)
* [Pittsburgh, PA - ReactJS/React Native](https://www.meetup.com/ReactPgh/)
* [Portland, OR - ReactJS](https://www.meetup.com/Portland-ReactJS/)
Expand Down
64 changes: 33 additions & 31 deletions content/docs/conditional-rendering.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
---
id: conditional-rendering
title: Conditional Rendering
title: رندر شرطی
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

رندر کردن شرطی

permalink: docs/conditional-rendering.html
prev: handling-events.html
next: lists-and-keys.html
redirect_from:
- "tips/false-in-jsx.html"
---

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.
در ری اکت، شما می‌توانید کامپوننت‌های مجزایی بسازید تا رفتار مورد نیاز شما را کپسوله سازی کنند. سپس می‌توانید بعضی از این کامپوننت‌ها را، بسته به state برنامه، رندر کنید .
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... می‌توانید فقط بعضی از این کامپوننت‌ها را، بسته به state برنامه، رندر کنید .


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.
رندر شرطی در ری اکت دقیقا مشابه «شرط‌ها» در جاوا‌اسکریپت کار میکند.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

رندرکردن شرطی در ری‌اکت همان‌طور کار می‌کند که شرط‌ها در جاوا‌اسکریپت کار می‌کنند. ...

از عملگر‌های جاوااسکریپت مثل کلمه کلیدی [`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 کنونی را نشان می‌دهند، استفاده کنید و بگذارید ری اکت UI را بروزرسانی کند تا با این شرط ها منطبق شود.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... از عملگرهای جاوااسکریپت مانند if یا عملگر شرطی (conditional operator) برای ساختن المنت‌هایی که نمایانگر state کنونی هستند، استفاده کند و بگذارید ری‌اکت UI را به‌روز رسانی کند تا با آن‌ها منطبق شود.


Consider these two components:
این دو کامپوننت را در نظر بگیرید:

```js
function UserGreeting(props) {
Expand All @@ -24,7 +25,7 @@ function GuestGreeting(props) {
}
```

We'll create a `Greeting` component that displays either of these components depending on whether a user is logged in:
در ادامه ما یک کامپوننت تحت عنوان `Greeting` می‌سازیم، که یکی از دو کامپوننت اشاره شده در بالا را بر حسب اینکه یک کاربر لاگین کرده یا خیر، نشان می‌دهد:
Copy link
Collaborator

@sorousht sorousht Apr 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

در ادامه ما یک کامپوننت Greeting می‌سازیم که یکی از این کامپوننت‌ها را بسته به اینکه کاربر وارد شده‌است نشان می‌هد:


```javascript{3-7,11,12}
function Greeting(props) {
Expand All @@ -36,21 +37,21 @@ function Greeting(props) {
}

ReactDOM.render(
// Try changing to isLoggedIn={true}:
//در خط زیر مقدار isLoggedIn را به true تغییر دهید‌‌(isLoggedIn={true}):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

تغییر isLoggedIn={true} را امتحان کنید

<Greeting isLoggedIn={false} />,
document.getElementById('root')
);
```

[**Try it on CodePen**](https://codepen.io/gaearon/pen/ZpVxNq?editors=0011)
[**کد بالا را در CodePen امتحان کنید**](https://codepen.io/gaearon/pen/ZpVxNq?editors=0011)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

روی CodePen امتحان کنید


This example renders a different greeting depending on the value of `isLoggedIn` prop.
در مثال بالا، هر بار یک پیام خوش آمد‌گویی متفاوت بر‌اساس مقدارprop ای که `isLoggedIn` نام دارد، رندر می‌شود.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

این مثال بر اساس مقدار prop isLoggedIn یک [پیام] خوش‌آمد گویی متفاوت را رندر می‌کند.


### Element Variables {#element-variables}
### متغیر‌های المان‌ها {#element-variables}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

متغییرهای المنت


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.
برای ذخیره سازی المان‌ها می‌توان از متغیرها کمک گرفت، استفاده از این روش باعث می‌شود تا بتوان بخشی از یک کامپوننت را به‌صورت شرطی، رندر کرده در حالیکه بقیه خروجی کامپوننت تغییری نمی‌کند.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

شما می‌توانید از متغییرها برای ذخیره کردن المنت‌ها استفاده کنید. این به شما کمک می‌کند که بتوان بخشی از یک کامپوننت را به‌صورت شرطی، رندر کرده در حالی‌که بقیه خروجی کامپوننت تغییری نمی‌کند.


Consider these two new components representing Logout and Login buttons:
این دو کامپوننت جدید رو در نظر بگیرید که به ترتیب نمایانگر دکمه ورود (Login) و خروج (Logout) هستند.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

این دو کامپوننت جدید رو در نظر بگیرید که به ترتیب نمایانگر دکمه‌های ورود (Login) و خروج (Logout) هستند.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.به نظرم در متن این آموزش چون هیچ جا لحن محاوره ای نیست بهتره به جای رو از را استفاده بشه.


```js
function LoginButton(props) {
Expand All @@ -70,9 +71,10 @@ function LogoutButton(props) {
}
```

In the example below, we will create a [stateful component](/docs/state-and-lifecycle.html#adding-local-state-to-a-class) called `LoginControl`.
در مثال زیر، یک [ کامپوننتstateful](/docs/state-and-lifecycle.html#adding-local-state-to-a-class)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

در مثال زیر، یک کامپوننت دارای state به نام LoginControl می‌سازیم.

به نام`LoginControl` می‌سازیم.

It will render either `<LoginButton />` or `<LogoutButton />` depending on its current state. It will also render a `<Greeting />` from the previous example:
این کامپوننت براساس state کنونی اش، یکی از کامپوننت‌های `<LoginButton />` یا`<LogoutButton />` را رندر می‌کند.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

این [کامپوننت] یکی از ... یا ... را براساس state کنونی رندر خواهد کرد. همچنین، یک ... را از مثال قبل رندر می‌کند:

در توضیح بالا که ... گذاشته‌ام به خاطر این هست که نمیدونم چطور در کامنت یک تگ باز و بسته بنویسم و به عنوان تکست نوشته بشه!


```javascript{20-25,29,30}
class LoginControl extends React.Component {
Expand Down Expand Up @@ -116,13 +118,13 @@ ReactDOM.render(
);
```

[**Try it on CodePen**](https://codepen.io/gaearon/pen/QKzAgB?editors=0010)
[**این کد را در CodePen امتحان کنید**](https://codepen.io/gaearon/pen/QKzAgB?editors=0010)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

روی ‌CodePen امتحان کنید


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.
در حالیکه روش تعریف یک متغیر و استفاده از عبارت شرطی `if`، یک روش خوب برای رندر شرطی است؛ گاهی ممکن است شما نیاز به یک syntax کوتاه‌تر داشته باشید. چندین روش برای شرط های خطی در JSX وجود دارد که در زیر توضیح داده شده است:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

در حالی‌که روش تعریف یک متغیر و استفاده از عبارت شرطی if، یک روش خوب برای رندرکردن شرطی است، ...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... گاهی ممکن است شما نیاز به بخواهید یک syntax کوتاه‌تر داشته باشید. ...


### Inline If with Logical && Operator {#inline-if-with-logical--operator}
### If خطی بااستفاده از اپراتور && منطقی {#inline-if-with-logical--operator}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if خطی با استفاده از عملگر منطقی &&


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:
شما می‌توانید هر عبارتی (شامل عملگر ‍‍‍‍`&&` منطقی در جاوااسکریپت)‌را در JSX با استفاده از یک جفت `{}`،‌استفاده کنید:‌ر.ک. [embed any expressions in JSX](/docs/introducing-jsx.html#embedding-expressions-in-jsx)؛ استفاده از این روش برای اضافه کردن یک المان به‌صورت شرطی، میتواند مفید باشد:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

شما می‌توانید هر expression را در JSX به صورت توکار با قراردادن در آکولاد بنویسید. این مورد شامل عملگر منطقی && هم می‌شود. کاربرد آن برای اضافه‌کردن شرطی یک المنت است:


```js{6-10}
function Mailbox(props) {
Expand All @@ -146,17 +148,16 @@ ReactDOM.render(
);
```

[**Try it on CodePen**](https://codepen.io/gaearon/pen/ozJddz?editors=0010)
[**این کد را در CodePen امتحان کنید**](https://codepen.io/gaearon/pen/ozJddz?editors=0010)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

روی CodePen استفاده کنید


It works because in JavaScript, `true && expression` always evaluates to `expression`, and `false && expression` always evaluates to `false`.
این روش جواب می‌دهد چرا که در جاوااسکریپت، حاصل `true && عبارت` همیشه برابر است با `عبارت` و همچنین حاصل `false && عبارت` ‍‍ همیشه برابر است با `false`. بنابراین اگر شرط برابر با `true` باشد، المانی که بلافاصله بعد از عملگر `&&` قرار گرفته است در خروجی نمایش داده خواهد شد و اگر حاصل شرط برابر با`false` باشد،‌ری‌اکت این عبارت را نادیده می‌گیرد.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

۱. در این پاراگراف نباید expression رو به "عبارت" ترجمه کنید. چون مثال‌هایی که نوشته شده کد یا شبه‌کد هستند و نباید ترجمه شوند.
۲. یک فاصله بعد از کاما در خط آخر باید اضافه شود.
۳. این بخش در متن اصلی در دو پاراگراف آمده است، اما در یک پاراگراف ترجمه شده‌است. باید قبل از "بنابراین ..." به یک خط جدید شروع شود.


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.
### If-Else خطی با عملگر شرطی {#inline-if-else-with-conditional-operator}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if-else خطی با عملگر شرطی

اینجا هم نیازی نیست که if-else رو مثل انگلیسی بزرگ بنویسیم


### Inline If-Else with Conditional Operator {#inline-if-else-with-conditional-operator}
روش دیگری که برای رندر شرطی المان‌ها به‌صورت خطی استفاده می‌شود،‌استفاده از عملگر شرطی جاوااسکریپت [`condition ? true : false`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Conditional_Operator)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

روش دیگری که برای رندر شرطی المان‌ها به‌صورت خطی استفاده می‌شود،‌ ...

است.

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

In the example below, we use it to conditionally render a small block of text.
در مثال زیر ما از این روش استفاده می‌کنیم تا متن کوتاهی را به‌صورت شرطی رندر کنیم.

```javascript{5}
render() {
Expand All @@ -169,7 +170,7 @@ render() {
}
```

It can also be used for larger expressions although it is less obvious what's going on:
از این روش همچنین می‌توان برای عبارات شرطی طولانی‌تر استفاده نمود، اگرچه که در اینصورت کمتر مشخص است که در کد نوشته شده چه اتفاقی افتاده است:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

از این روش همچنین می‌توان برای عبارات شرطی طولانی‌تر استفاده نمود، اگرچه که در اینصورت کمتر مشخص است که [در کد نوشته شده] چه اتفاقی افتاده است:

چون این عبارت در متن اصلی نیست و جهت فهم بهتر اضافه شده، حتما در کروشه قرار گیرد.


```js{5,7,9}
render() {
Expand All @@ -186,13 +187,14 @@ render() {
}
```

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).
درست مثل زبان جاوااسکریپت،انتخاب اینکه کدام روش مناسب است، به نظر شما و تیم شما بستگی دارد که کدام روش برای شما خوانا‌تر است.‌همچنین این نکته را در نظر داشته باشید که هرگاه شرط‌ها بیش از انداره پیچیده شدند،بهتر است که از روش [استخراج یک کامپوننت](/docs/components-and-props.html#extracting-components) استفاده کنید.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

۱. درست مثل زبان جاوااسکریپت، ...
۲. فاصله بعد از کاما
۳. فاصله بعد از نقطه
۴. ... بهتر است که یک کامپوننت استخراج کنید.


### جلوگیری از رندر شدن یک کامپوننت {#preventing-component-from-rendering}

### Preventing Component from Rendering {#preventing-component-from-rendering}
گاهی پیش می‌آید که بخواهید یک کامپوننت-حتی اگر توسط یک کامپوننت دیگر رندر شده باشد- خودش را مخفی کند. برای انجام این کار، عبارت `null` را به‌جای خروجی تابع رندر کامپوننت برگردانید.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

در موارد نادر، ممکن است شما گاهی پیش می‌آید که بخواهید یک کامپوننت - حتی اگر توسط یک کامپوننت دیگر رندر شده باشد - خودش را مخفی کند. برای انجام این کار، عبارت null را به‌جای خروجی تابع رندر کامپوننت برگردانید.


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.
در مثال زیر، کامپوننت `<WarningBanner />` بر‌اساس مقدار prop ای به‌نام `warn` رندر می‌شود. اگر مقدار این prop برابر با`false` باشد، در اینصورت این کامپوننت رندر نخواهد شد.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

در اینصورت این کامپوننت رندر نخواهد شد کرد.


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:

```javascript{2-4,29}
function WarningBanner(props) {
Expand Down Expand Up @@ -238,6 +240,6 @@ ReactDOM.render(
);
```

[**Try it on CodePen**](https://codepen.io/gaearon/pen/Xjoqwm?editors=0010)
[**این کد را در CodePen امتحان کنید**](https://codepen.io/gaearon/pen/Xjoqwm?editors=0010)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

روی CodePen امتحان کنید


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.
برگرداندن مقدار `null`از متد `render` یک کامپوننت، نحوه فراخوانی و اجرای متد‌های lifecycle کامپونتت را تحت تاثیر قرار نمی‌دهد.‌برای مثال متد `componentDidUpdate` همچنان فراخوانی خواهد شد.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

۱. برگرداندن مقدار nullاز متد render یک کامپوننت، نحوه فراخوانی و اجرای متد‌های lifecycle کامپونتت را تحت تاثیر قرار نمی‌دهد.‌
۲. فاصله بعد از نقطه در آخر جمله

Loading