React List
In React, a list is a way to render a collection of similar components or elements in a dynamic and efficient manner. Lists are commonly used when you have an array of data and you want to render each item in the array as a component. React provides a mechanism to iterate over the array and create a component for each item, allowing you to display the data in a structured way. react list
रिएक्ट में, एक सूची समान components या elements के संग्रह को गतिशील और कुशल तरीके से प्रस्तुत करने का एक तरीका है। Lists आमतौर पर तब उपयोग की जाती हैं जब आपके पास डेटा की एक array होती है और आप array में प्रत्येक item को एक component के रूप में प्रस्तुत करना चाहते हैं। रिएक्ट array पर पुनरावृति करने और प्रत्येक आइटम के लिए एक component बनाने के लिए एक mechanism प्रदान करता है, जिससे आप डेटा को संरचित तरीके से प्रदर्शित कर सकते हैं। react list
Here's how you typically work with lists in React:
यहां बताया गया है कि आप आमतौर पर रिएक्ट में सूचियों के साथ कैसे काम करते हैं:
Creating a List Component:
To create a list component in React, you define a JavaScript array that holds the data you want to display. Then, you use themap()function to iterate over the array and create a component for each item. This is often done within therender()method of a parent component.react list componentएक List Component बनाना:
- रिएक्ट में एक सूची घटक बनाने के लिए, आप एक जावास्क्रिप्ट सरणी परिभाषित करते हैं जिसमें वह डेटा होता है जिसे आप प्रदर्शित करना चाहते हैं। फिर, आप
map()सरणी पर पुनरावृति करने और प्रत्येक आइटम के लिए एक घटक बनाने के लिए फ़ंक्शन का उपयोग करते हैं। यह अक्सरrender()मूल घटक की विधि के अंतर्गत किया जाता है।jsximport React from 'react'; const ListComponent = () => { const items = ['Item 1', 'Item 2', 'Item 3']; const itemComponents = items.map((item, index) => ( <li key={index}>{item}</li> )); return ( <ul> {itemComponents} </ul> ); }; export default ListComponent;Note the use of the
keyprop in thelielements. React uses this key to efficiently update and re-render the list when necessary. li elements keyमें prop के उपयोग पर ध्यान दें । आवश्यकता पड़ने पर list को कुशलतापूर्वक update करने और re-render करने के लिए रिएक्ट इस key का उपयोग करता है।Keys and Reconciliation:
Keys are important when rendering lists in React. They help React identify which items have changed, been added, or been removed. Each key should be unique within the list. Using a unique identifier from your data (like an ID) as the key is recommended.
Keys और समाधान(Reconciliation):
रिएक्ट में lists प्रस्तुत करते समय Keys महत्वपूर्ण होती हैं। वे रिएक्ट को यह पहचानने में मदद करते हैं कि कौन से आइटम बदल गए हैं, जोड़े गए हैं या हटा दिए गए हैं। सूची में प्रत्येक key unique होनी चाहिए. key के रूप में आपके डेटा से एक unique identifire (ID की तरह) का उपयोग करने की अनुशंसा की जाती है।
Dynamic Lists with Data:
Often, you'll use dynamic data from props or states to render lists. This allows you to update the list based on changes to the data.
Data के साथ Dynamic list :
अक्सर, आप lists render करने के लिए props or state से डायनामिक डेटा का उपयोग करेंगे। यह आपको डेटा में परिवर्तन के आधार पर lists को update करने की अनुमति देता है।
- jsx
import React, { Component } from 'react'; class DynamicListComponent extends Component { state = { items: ['Apple', 'Banana', 'Orange'], }; render() { const { items } = this.state; const itemComponents = items.map((item, index) => ( <li key={index}>{item}</li> )); return ( <ul> {itemComponents} </ul> ); } } export default DynamicListComponent; Conditional rendering and Empty Lists:
You can conditionally render your list of components based on certain conditions. If the list is empty, you can display a message indicating that there are no items to show. conditional rendering react
Conditional rendering और Empty Lists:
- आप कुछ शर्तों के आधार पर अपनी lists के components को conditionally प्रस्तुत कर सकते हैं। यदि lists empty है, तो आप एक message प्रदर्शित कर सकते हैं जो दर्शाता है कि दिखाने के लिए कोई item नहीं हैं।jsx
import React from 'react'; const ConditionalListComponent = ({ items }) => { if (items.length === 0) { return <p>No items to display.</p>; } const itemComponents = items.map((item, index) => ( <li key={index}>{item}</li> )); return ( <ul> {itemComponents} </ul> ); }; export default ConditionalListComponent;
These are the basics of working with lists in React. Lists are a fundamental concept in building dynamic and data-driven user interfaces. By understanding how to create, iterate over, and render lists, you can efficiently display and update collections of data in your React applications. conditional rendering react todo listreact conditional render
ये रिएक्ट में lists के साथ काम करने की मूल बातें हैं। गतिशील और डेटा-संचालित उपयोगकर्ता इंटरफ़ेस के निर्माण में lists एक मौलिक अवधारणा हैं। lists बनाने, पुनरावृत्त करने और प्रस्तुत करने का तरीका समझकर, आप अपने रिएक्ट अनुप्रयोगों में डेटा के संग्रह को कुशलतापूर्वक प्रदर्शित और अपडेट कर सकते हैं। react todo list react conditional render