-
Notifications
You must be signed in to change notification settings - Fork 130
Condition rendering fixed updated final #43
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
Changes from 3 commits
c23f91e
0b28fae
e380d3d
d4dc9bd
e972427
00f2f2d
497fdea
8484f2f
03a0074
3c56345
5e6b1e1
c32218e
481497d
f314253
07be650
6110e35
01a245c
4775ef3
24c2f77
69c5b66
04af059
909242d
aacb2e9
952fe96
3a12901
71b6254
0e37f81
19132f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 में, आप अलग-अलग कौम्पोनॅन्ट बना सकते हैं जो आपके लिए आवश्यक व्यवहार को संक्षिप्त करते हैं। फिर, आप अपने ऍप की स्टेट के आधार पर उनमें से कुछ को ही रिप्रेजेंट कर सकते हैं। | ||
|
||
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 को अपडेट करके मैच कर देगा। | ||
|
||
Consider these two components: | ||
उदाहरण के तौर पे यह दो कौम्पोनॅन्ट देखो: | ||
saranshkataria marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```js | ||
function UserGreeting(props) { | ||
saranshkataria marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
@@ -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` कौम्पोनॅन्ट बना रहे हे। अगर यूजर लॉगिन हे तभी देखेगा : | ||
arshadkazmi42 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```javascript{3-7,11,12} | ||
function Greeting(props) { | ||
|
@@ -44,13 +44,14 @@ ReactDOM.render( | |
|
||
[**Try it on CodePen**](https://codepen.io/gaearon/pen/ZpVxNq?editors=0011) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this needs to be translated too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CodePen में कोशिश करो There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. इसे CodePen पर आज़माएँ makes more sense |
||
|
||
This example renders a different greeting depending on the value of `isLoggedIn` prop. | ||
यह उदहारण `isLoggedIn` प्रोप के वैल्यू के अनुसार अलग अलग ग्रीटिंग्स रेंडर करता हे। | ||
|
||
### Element Variables {#element-variables} | ||
### एलिमेंट वेरिएबल {#element-variables} | ||
saranshkataria 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. | ||
आप एलिमेंट्स को स्टोर करने के लिए वेरिएबल्स का उसे कर सकते हो। | ||
जिससे आपको कंडीशनल रेंडरिंग में मदद होगी और बाकि का आउटपुट चेंज नहीं होगा। | ||
arshadkazmi42 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Consider these two new components representing Logout and Login buttons: | ||
अब लॉगिन और लॉगआउट बटन्स नए कौम्पोनॅन्टस को देखो : | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not the right translation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. लॉगिन और लॉगआउट बटन्स के नए कौम्पोनॅन्टस पर विचार करें There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. लॉगआउट और लॉगिन बटन्स का प्रतिनिधित्व करने वाले इन दो नए कौम्पोनॅन्टस पर विचार करें: |
||
|
||
```js | ||
function LoginButton(props) { | ||
|
@@ -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`. | ||
|
||
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
|
||
|
||
जो करंट स्टेट के हिसाब से `<LoginButton />` या `<LogoutButton />` को रेंडर करेगा। वो `<Greeting />` को भी रेंडर करेगा जैसे पिछले एक्साम्पल में बताया था: | ||
arshadkazmi42 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```javascript{20-25,29,30} | ||
class LoginControl extends React.Component { | ||
|
@@ -118,11 +120,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 में इन लाइन कंडीशंस के कुछ पर्याय दिए हे। | ||
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
|
||
|
||
### 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) { | ||
|
@@ -148,15 +150,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` हे, फिर रियेक्ट इसको इग्नोर कर स्किप करेगा। | ||
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
arshadkazmi42 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Inline If-Else with Conditional Operator {#inline-if-else-with-conditional-operator} | ||
### कंडीशनल ऑपरेटर्स के साथ इन लाइन if-else {#inline-if-else-with-conditional-operator} | ||
arshadkazmi42 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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) यह इन लाइन एलिमेंट्स की कंडीशनल रेंडरिंग की दूसरी पद्धति हे। | ||
arshadkazmi42 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
In the example below, we use it to conditionally render a small block of text. | ||
जैसे नीचे के एक्साम्पल में, कंडीशनल रेंडर कर छोटे टेक्स्ट ब्लॉक को रेंडर किआ। | ||
|
||
```javascript{5} | ||
render() { | ||
|
@@ -169,7 +171,7 @@ render() { | |
} | ||
``` | ||
|
||
It can also be used for larger expressions although it is less obvious what's going on: | ||
इसे हम बड़े एक्सप्रेशन्स के साथ भी उसे कर सकते हे इससे कैसे काम हो रहा हे यह समझना आसान हो जाता हे: | ||
arshadkazmi42 marked this conversation as resolved.
Show resolved
Hide resolved
arshadkazmi42 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```js{5,7,9} | ||
render() { | ||
|
@@ -186,13 +188,13 @@ 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)। | ||
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
arshadkazmi42 marked this conversation as resolved.
Show resolved
Hide resolved
arshadkazmi42 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Preventing Component from Rendering {#preventing-component-from-rendering} | ||
### कौम्पोनॅन्ट को रेंडर करने से बचाये {#preventing-component-from-rendering} | ||
arshadkazmi42 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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` रीटर्न करना हे। | ||
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
arshadkazmi42 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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) { | ||
|
@@ -240,4 +242,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` फिर भी कॉल होगा। | ||
arshadkazmi42 marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.