Skip to content
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

Update conditional-rendering.md #36

Closed
wants to merge 17 commits into from
Closed
Changes from 9 commits
Commits
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
52 changes: 28 additions & 24 deletions content/docs/conditional-rendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ 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.
React में, आप अलग-अलग कॉम्पोनेन्ट बना सकते हैं जो आपके लिए आवश्यक व्यवहार को संक्षिप्त करते हैं। फिर, आप अपने आवेदन की स्टेट के आधार पर उनमें से कुछ को ही रिप्रेजेंट कर सकते हैं।.
kambleaa007 marked this conversation as resolved.
Show resolved Hide resolved
arshadkazmi42 marked this conversation as resolved.
Show resolved Hide resolved
arshadkazmi42 marked this conversation as resolved.
Show resolved Hide resolved
arshadkazmi42 marked this conversation as resolved.
Show resolved Hide resolved

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.
कंडीशनल रेंडरिंग React में वैसे ही काम करता हे जैसे कंडीशंस जावास्क्रिप्ट में करते हे । जावास्क्रिप्ट ऑपरेटर्स जैसे [`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) जो एलिमेंट्स बनके करंट स्टेट को रिप्रेजेंट करते हे । , फिर React UI को अपडेट करके मैच कर देगा ।
arshadkazmi42 marked this conversation as resolved.
Show resolved Hide resolved
arshadkazmi42 marked this conversation as resolved.
Show resolved Hide resolved

Consider these two components:
एक्साम्पल के तौर पे यह दो कॉम्पोनेन्ट देखो :
kambleaa007 marked this conversation as resolved.
Show resolved Hide resolved
arshadkazmi42 marked this conversation as resolved.
Show resolved Hide resolved

```js
function UserGreeting(props) {
Expand All @@ -24,7 +24,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` कॉम्पोनेन्ट बना रहे हे । अगर यूजर लॉगिन हे तभी देखेगा :
kambleaa007 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

बना रहे हे । अगर यूजर लॉगिन हे तभी देखेगा : => बना रहे है। अगर यूजर लॉगिन हे तभी देखेगा:

Copy link
Member

Choose a reason for hiding this comment

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

not fixed

Copy link
Member

Choose a reason for hiding this comment

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

कॉम्पोनेन्ट => कौम्पोनॅन्ट

Copy link
Member

Choose a reason for hiding this comment

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

देखेगा : => देखेगा:

Copy link
Member

Choose a reason for hiding this comment

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

देखेगा : => देखेगा:

this is missed

Copy link
Member

Choose a reason for hiding this comment

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

कॉम्पोनेन्ट => कौम्पोनॅन्ट

this is missed


```javascript{3-7,11,12}
function Greeting(props) {
Expand All @@ -44,13 +44,15 @@ ReactDOM.render(

[**Try it on CodePen**](https://codepen.io/gaearon/pen/ZpVxNq?editors=0011)

This example renders a different greeting depending on the value of `isLoggedIn` prop.

arshadkazmi42 marked this conversation as resolved.
Show resolved Hide resolved
### Element Variables {#element-variables}
यह एक्साम्पल `isLoggedIn` प्रोप के वैल्यू के अनुसार अलग अलग ग्रीटिंग्स रेंडर करता हे
arshadkazmi42 marked this conversation as resolved.
Show resolved Hide resolved

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.
### एलिमेंट वेरिएबल {#element-variables}

Consider these two new components representing Logout and Login buttons:
आप एलिमेंट्स को स्टोर करने के लिए वेरिएबल्स का उसे कर सकते हो .
arshadkazmi42 marked this conversation as resolved.
Show resolved Hide resolved
जिससे आपको कंडीशनल रेंडरिंग में मदत होगी और बाकि का आउटपुट चेंज नहीं होगा
Copy link
Member

Choose a reason for hiding this comment

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

remove line break, move this with the previous line

Copy link
Member

Choose a reason for hiding this comment

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

not fixed

Copy link
Member

Choose a reason for hiding this comment

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

remove line break, move this with the previous line

this is not fixed

Copy link
Member

Choose a reason for hiding this comment

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

मदत => मदद

Copy link
Member

Choose a reason for hiding this comment

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

not fixed

Copy link
Member

Choose a reason for hiding this comment

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

मदत => मदद

not fixed

kambleaa007 marked this conversation as resolved.
Show resolved Hide resolved

अब लॉगिन और लॉगआउट बटन्स नए कंपोनेंट्स को देखो :
arshadkazmi42 marked this conversation as resolved.
Show resolved Hide resolved
kambleaa007 marked this conversation as resolved.
Show resolved Hide resolved

```js
function LoginButton(props) {
Expand All @@ -70,9 +72,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`.

It will render either `<LoginButton />` or `<LogoutButton />` depending on its current state. It will also render a `<Greeting />` from the previous example:
इस एक्साम्पल में हम बना रहे हे [स्टैटिफुल कम्पोनेनेट ] (/docs/state-and-lifecycle.html#adding-local-state-to-a-class) जिसे बोलते हे `LoginControl`.
arshadkazmi42 marked this conversation as resolved.
Show resolved Hide resolved
kambleaa007 marked this conversation as resolved.
Show resolved Hide resolved

जो करंट स्टेट के हिसाब से `<LoginButton />` या `<LogoutButton />` को रेंडर करेगा वो `<Greeting />` को भी रेंडर करेगा जैसे पिछले एक्साम्पल में बताया था :
arshadkazmi42 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

एक्साम्पल => उदहारण

change this everywhere

Copy link
Member

Choose a reason for hiding this comment

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

not fixed

Copy link
Member

Choose a reason for hiding this comment

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

एक्साम्पल => उदहारण

change this everywhere

no fixed


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

[**Try it on CodePen**](https://codepen.io/gaearon/pen/QKzAgB?editors=0010)

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` स्टेटमेंट का यूज़ करना जिससे हम कॉम्पोनेन्ट को कंडशनल रेंडर कर सके यह अच्छी बात हे ,कभी आपको छोटा शार्ट सिंटेक्स उसे करना पड़ सकता हे .यहाँ नीचे, JSX में इन लाइन कंडीशंस के कुछ पर्याय दिए हे

### Inline If with Logical && Operator {#inline-if-with-logical--operator}
### लॉजिकल && ऑपरेटर के साथ इन लाइन `if` का इस्तेमाल {#inline-if-with-logical--operator}

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` में डाल सकते हे](/docs/introducing-jsx.html#embedding-expressions-in-jsx) उसको कर्ली ब्रेसेस के अंदर व्रैप करना पड़ेगा. इसमें जावास्क्रिप्ट का लॉजिकल `&&` ऑपरेटर भी शामिल हे. इसकी मदत से हम कोई एलिमेंट को कंडीशंस से इन्क्लूड कर सकते हे:

```js{6-10}
function Mailbox(props) {
Expand All @@ -148,15 +151,15 @@ ReactDOM.render(

[**Try it on CodePen**](https://codepen.io/gaearon/pen/ozJddz?editors=0010)

It works because in JavaScript, `true && expression` always evaluates to `expression`, and `false && expression` always evaluates to `false`.
जैवसक्रिप्ट मे यह काम करता हे, `true && expression` हमेशा `expression` होता हे , और `false && expression` हमेशा `false` होता हे.

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.
इसीलिए, अगर कोई कंडीशन `true` हे, तोह `&&` के आगे का एलिमेंट आउटपुट में आ जाता हे. अगर यह `false` हे, फिर रियेक्ट इसको इग्नोर कर स्किप करेगा.

### Inline If-Else with Conditional Operator {#inline-if-else-with-conditional-operator}
### कंडीशनल ऑपरेटर्स के साथ इन लाइन if-else {#inline-if-else-with-conditional-operator}

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).
जावास्क्रिप्ट की कंडीशनल ऑपरेटर्स का उसे करना [`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 +172,7 @@ render() {
}
```

It can also be used for larger expressions although it is less obvious what's going on:
इसे हम बड़े एक्सप्रेशन्स के साथ भी उसे कर सकते हे इससे कैसे काम हो रहा हे यह समझना आसान हो जाता हे :

```js{5,7,9}
render() {
Expand All @@ -186,13 +189,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).
,

### Preventing Component from Rendering {#preventing-component-from-rendering}
### कॉम्पोनेन्ट को रेंडर करने से बचाये {#preventing-component-from-rendering}

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.
कुछ केसेस में कंपोनेंट को छिपाना पड़ता हे जब की वह किसी दूसरे कॉम्पोनेन्ट में रेंडर हो रहे हो. तब हमको आउटपुट को रेंडर करने के अलावा `null` रीटर्न करना हे .

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:
जैसे नीचे के एक्साम्पल में, `<WarningBanner />` यह कॉम्पोनेन्ट `warn` प्रोप के वैल्यू के अनुसार रेंडर हुआ हे. अगर इसकी वैल्यू `false` रहती तोह कॉम्पोनेन्ट रेंडर नहीं होता :

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

[**Try it on CodePen**](https://codepen.io/gaearon/pen/Xjoqwm?editors=0010)

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` रीटर्न करने का और कॉम्पोनेन्ट के लाइफ साइकिल मेथड्स पर कोई असर नहीं पड़ता. जैसे की `componentDidUpdate` फिर भी कॉल होगा .