You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/docs/lists-and-keys.md
+39-39
Original file line number
Diff line number
Diff line change
@@ -1,30 +1,30 @@
1
-
---
1
+
---
2
2
id: lists-and-keys
3
3
title: Lists and Keys
4
4
permalink: docs/lists-and-keys.html
5
5
prev: conditional-rendering.html
6
6
next: forms.html
7
7
---
8
8
9
-
First, let's review how you transform lists in JavaScript.
9
+
पहले, आइए समीक्षा करें कि आप जावास्क्रिप्ट में लिस्ट्स को कैसे बदलते हैं।
10
10
11
-
Given the code below, we use the [`map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)function to take an array of `numbers` and double their values. We assign the new array returned by `map()` to the variable `doubled` and log it:
11
+
नीचे दिए गए कोड में हम `numbers` की एक array के मूल्यों को दोगुना करने के लिए [`map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)फ़ंक्शन का उपयोग करते हैं। हम `map()` द्वारा दिए गए नए array को `doubled` नाम के वेरिएबल को सौपते हैं और फिर लॉग करते हैं।
12
12
13
13
```javascript{2}
14
14
const numbers = [1, 2, 3, 4, 5];
15
15
const doubled = numbers.map((number) => number * 2);
16
16
console.log(doubled);
17
17
```
18
18
19
-
This code logs `[2, 4, 6, 8, 10]` to the console.
19
+
यह कोड [2, 4, 6, 8, 10] को कंसोल में लोग करता है।
20
20
21
-
In React, transforming arrays into lists of [elements](/docs/rendering-elements.html)is nearly identical.
21
+
React में, array को [एलिमेंट्स](/docs/rendering-elements.html)की लिस्ट में बदलना लगभग समान है।
### कई कौम्पोनॅन्टस को रेंडर करना {#rendering-multiple-components}
24
24
25
-
You can build collections of elements and [include them in JSX](/docs/introducing-jsx.html#embedding-expressions-in-jsx) using curly braces `{}`.
25
+
आप एलिमेंट्स का संग्रह बना सकते हैं और कर्ली ब्रेसिज़ `{}` का उपयोग करके [उन्हें JSX में शामिल कर सकते हैं।](/docs/introducing-jsx.html#embedding-expressions-in-jsx)
26
26
27
-
Below, we loop through the `numbers` array using the JavaScript [`map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)function. We return a `<li>`element for each item. Finally, we assign the resulting array of elements to`listItems`:
27
+
हमने जावास्क्रिप्ट [`map()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)फंक्शन का उपयोग करके `numbers` नाम की array में लूप लगाया है। हमने प्रत्येक आइटम के लिए `<li>`एलिमेंट को रिटर्न किया है। अंत में, हम परिणामस्वरूप आयी हुई एलिमेंट्स की array को`listItems` को सौपते है:
We include the entire `listItems` array inside a `<ul>`element, and [render it to the DOM](/docs/rendering-elements.html#rendering-an-element-into-the-dom):
36
+
हम पुरे `listItems` array को `<ul>`एलिमेंट में शामिल करके इसे [DOM में रेंडर करते हैं](/docs/rendering-elements.html#rendering-an-element-into-the-dom):
37
37
38
38
```javascript{2}
39
39
ReactDOM.render(
@@ -42,15 +42,15 @@ ReactDOM.render(
42
42
);
43
43
```
44
44
45
-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/GjPyQr?editors=0011)
45
+
[**इसे CodePen पर आज़माएँ**](https://codepen.io/gaearon/pen/GjPyQr?editors=0011)
46
46
47
-
This code displays a bullet list of numbers between 1 and 5.
47
+
यह कोड 1 से 5 के बीच संख्याओं की एक बुलेट लिस्ट प्रदर्शित करता है।
48
48
49
-
### Basic List Component {#basic-list-component}
49
+
### मूल लिस्टस कौम्पोनॅन्ट {#basic-list-component}
50
50
51
-
Usually you would render lists inside a [component](/docs/components-and-props.html).
51
+
आमतौर पर आप एक [कौम्पोनॅन्ट](/docs/components-and-props.html) के अंदर लिस्ट रेंडर करते हैं।
52
52
53
-
We can refactor the previous example into a component that accepts an array of `numbers` and outputs a list of elements.
53
+
हम पिछले उदाहरण को एक कौम्पोनॅन्ट में बदल सकते हैं जो `numbers` की एक array को स्वीकार करता है और एलिमेंटस की लिस्ट को आउटपुट करता है।
54
54
55
55
```javascript{3-5,7,13}
56
56
function NumberList(props) {
@@ -70,9 +70,9 @@ ReactDOM.render(
70
70
);
71
71
```
72
72
73
-
When you run this code, you'll be given a warning that a key should be provided for list items. A "key" is a special string attribute you need to include when creating lists of elements. We'll discuss why it's important in the next section.
73
+
जब आप यह कोड चलाते हैं, तो आपको एक चेतावनी दी जाती है कि लिस्ट आइटम के लिए एक key प्रदान की जानी चाहिए। "key" एक विशेष स्ट्रिंग एट्रिब्यूट है जिसे आपको एलिमेंटस की सूची बनाते समय शामिल करने की आवश्यकता होती है। हम अगले भाग में चर्चा करेंगे कि यह महत्वपूर्ण क्यों है।
74
74
75
-
Let's assign a `key` to our list items inside `numbers.map()` and fix the missing key issue.
75
+
आइए `numbers.map()` के अंदर हमारी लिस्ट आइटम को एक `key`असाइन करें और लापता key की समस्या को ठीक करें।
76
76
77
77
```javascript{4}
78
78
function NumberList(props) {
@@ -94,11 +94,11 @@ ReactDOM.render(
94
94
);
95
95
```
96
96
97
-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/jrXYRR?editors=0011)
97
+
[**इसे CodePen पर आज़माएँ**](https://codepen.io/gaearon/pen/jrXYRR?editors=0011)
98
98
99
99
## Keys {#keys}
100
100
101
-
Keys help React identify which items have changed, are added, or are removed. Keys should be given to the elements inside the array to give the elements a stable identity:
101
+
Keys React को पहचानने में मदद करती हैं कि कौन से आइटम ऐड किये गए हैं, या हटा दिए गए हैं। एलिमेंट्स को स्टेबल करने के लिए array के अंदर एलिमेंट्स को key दी जानी चाहिए:
The best way to pick a key is to use a string that uniquely identifies a list item among its siblings. Most often you would use IDs from your data as keys:
112
+
Key चुनने का सबसे अच्छा तरीका एक string का उपयोग करना है जो विशिष्ट रूप से अपने सिब्लिंग्स के बीच एक लिस्ट आइटम की पहचान करता है। अक्सर आप अपने डेटा की IDs को key के रूप में उपयोग करेंगे:
We don't recommend using indexes for keys if the order of items may change. This can negatively impact performance and may cause issues with component state. Check out Robin Pokorny's article for an [in-depth explanation on the negative impacts of using an index as a key](https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318). If you choose not to assign an explicit key to list items then React will default to using indexes as keys.
133
+
यदि आइटम का क्रम बदल सकता है तो हम key के लिए इंडेक्स का उपयोग ना करने की सिफारिश करते हैं। इसका नकारात्मक प्रभाव पड़ सकता हैं और यह कौम्पोनॅन्ट की अवस्था के साथ समस्या भी पैदा कर सकता है। अधिक जानकारी के लिए Robin Pokorny के [इंडेक्स को key के रूप में उपयोग करने के नकारात्मक प्रभाव](https://medium.com/@robinpokorny/index-as-a-key-is-an-anti-pattern-e0349aece318) के आर्टिकल को देखें। यदि आप लिस्ट आइटम्स को एक स्पष्ट key नहीं देते हैं, तो React key के रूप में इंडेक्स का उपयोग करता है।
134
134
135
-
Here is an [in-depth explanation about why keys are necessary](/docs/reconciliation.html#recursing-on-children)if you're interested in learning more.
135
+
यदि आप अधिक सीखने में रुचि रखते हैं, तो यहाँ [key की आवशयकताओ के बारे में गहराई से स्पष्टीकरणं](/docs/reconciliation.html#recursing-on-children)दिया गया हैं।
136
136
137
-
### Extracting Components with Keys {#extracting-components-with-keys}
137
+
### Key के साथ कौम्पोनॅन्टस निकालना {#extracting-components-with-keys}
138
138
139
-
Keys only make sense in the context of the surrounding array.
139
+
Keys केवल आस-पास के array के संदर्भ में ही समझ में आती हैं।
140
140
141
-
For example, if you [extract](/docs/components-and-props.html#extracting-components)a `ListItem` component, you should keep the key on the`<ListItem />`elements in the array rather than on the `<li>`element in the `ListItem` itself.
141
+
उदाहरण के लिए, यदि आप एक ListItem कौम्पोनॅन्ट को [निकालते](/docs/components-and-props.html#extracting-components)हैं, तो आपको key `ListItem` के`<li>`एलिमेंट पर रखने के बजाये array में `<ListItem />`एलिमेंट पर रखनी चाहिए।
142
142
143
-
**Example: Incorrect Key Usage**
143
+
**उदाहरण: key का गलत उपयोग**
144
144
145
145
```javascript{4,5,14,15}
146
146
function ListItem(props) {
@@ -173,7 +173,7 @@ ReactDOM.render(
173
173
);
174
174
```
175
175
176
-
**Example: Correct Key Usage**
176
+
**उदाहरण: key का सही उपयोग**
177
177
178
178
```javascript{2,3,9,10}
179
179
function ListItem(props) {
@@ -202,13 +202,13 @@ ReactDOM.render(
202
202
);
203
203
```
204
204
205
-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/ZXeOGM?editors=0010)
205
+
[**इसे CodePen पर आज़माएँ**](https://codepen.io/gaearon/pen/ZXeOGM?editors=0010)
206
206
207
-
A good rule of thumb is that elements inside the `map()`call need keys.
207
+
एक अच्छा नियम यह है `map()`कॉल के एलिमेंट्स को key की आवशयकता होती हैं ।
208
208
209
-
### Keys Must Only Be Unique Among Siblings {#keys-must-only-be-unique-among-siblings}
209
+
### Keys सिर्फ़ सिब्लिंग्स के बीच अद्वितीय होनी चाहिए {#keys-must-only-be-unique-among-siblings}
210
210
211
-
Keys used within arrays should be unique among their siblings. However they don't need to be globally unique. We can use the same keys when we produce two different arrays:
211
+
Arrays के भीतर उपयोग की जाने वाली key उनके सिब्लिंग्स के बीच अद्वितीय होनी चाहिए। हालाँकि उन्हें पूरी तरह से अद्वितीय होने की आवश्यकता नहीं है। हम अलग-अलग arrays के लिए सामान keys का उपयोग कर सकते हैं:
212
212
213
213
```js{2,5,11,12,19,21}
214
214
function Blog(props) {
@@ -246,9 +246,9 @@ ReactDOM.render(
246
246
);
247
247
```
248
248
249
-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/NRZYGN?editors=0010)
249
+
[**इसे CodePen पर आज़माएँ**](https://codepen.io/gaearon/pen/NRZYGN?editors=0010)
250
250
251
-
Keys serve as a hint to React but they don't get passed to your components. If you need the same value in your component, pass it explicitly as a prop with a different name:
251
+
Keys React के लिए संकेत के रूप में काम करती हैं लेेकिन वह आपके कौम्पोनॅन्टस को नहीं दी जाती हैं। यदि आपको अपने कौम्पोनॅन्ट में समान वैल्यू की आवश्यकता है, तो इसे अलग नाम के साथ स्पष्ट रूप से prop की तरह पास करें:
With the example above, the `Post`component can read `props.id`, but not `props.key`.
262
+
ऊपर के उदाहरण के साथ, `Post`कौम्पोनॅन्ट `props.id` पढ़ सकता है, लेकिन `props.key` नहीं।
263
263
264
-
### Embedding map() in JSX {#embedding-map-in-jsx}
264
+
### JSX में map() को एम्बेड करना {#embedding-map-in-jsx}
265
265
266
-
In the examples above we declared a separate`listItems`variable and included it in JSX:
266
+
ऊपर दिए गए उदाहरणों में हमने एक अलग`listItems`वेरिएबल को घोषित किया था और इसे JSX में शामिल किया था:
267
267
268
268
```js{3-6}
269
269
function NumberList(props) {
@@ -280,7 +280,7 @@ function NumberList(props) {
280
280
}
281
281
```
282
282
283
-
JSX allows [embedding any expression](/docs/introducing-jsx.html#embedding-expressions-in-jsx)in curly braces so we could inline the `map()`result:
283
+
JSX कर्ली ब्रेसिज़ में किसी भी [एक्सप्रेशन की एम्बेडिंग](/docs/introducing-jsx.html#embedding-expressions-in-jsx)करने की अनुमति देता है ताकि हम `map()`के परिणाम को इनलाइन कर सकें:
284
284
285
285
```js{5-8}
286
286
function NumberList(props) {
@@ -296,6 +296,6 @@ function NumberList(props) {
296
296
}
297
297
```
298
298
299
-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/BLvYrB?editors=0010)
299
+
[**इसे CodePen पर आज़माएँ**](https://codepen.io/gaearon/pen/BLvYrB?editors=0010)
300
300
301
-
Sometimes this results in clearer code, but this style can also be abused. Like in JavaScript, it is up to you to decide whether it is worth extracting a variable for readability. Keep in mind that if the `map()`body is too nested, it might be a good time to [extract a component](/docs/components-and-props.html#extracting-components).
301
+
कभी-कभी इसका परिणाम स्पष्ट कोड होता है, लेकिन इस शैली का दुरुपयोग भी किया जा सकता है। जैसे जावास्क्रिप्ट में ये आपको तय करना होता है की readability के लिए एक variable को extract करना चाहिए या नहीं। ध्यान रखें कि यदि `map()`बॉडी बहुत नेस्टेड है, तो [कंपोनेंट निकालने](/docs/components-and-props.html#extracting-components) का अच्छा समय हो सकता है।
0 commit comments