react components

A react component is a building block of a React application, allowing you to create reusable and self-contained pieces of user interface. React is a popular JavaScript library used for building user interfaces, and its components follow a component-based architecture.


react component एक रिएक्ट एप्लिकेशन का बिल्डिंग ब्लॉक है, जो आपको उपयोगकर्ता इंटरफ़ेस के पुन: प्रयोज्य और स्व-निहित टुकड़े बनाने की अनुमति देता है। रिएक्ट एक लोकप्रिय जावास्क्रिप्ट लाइब्रेरी है जिसका उपयोग यूजर इंटरफेस बनाने के लिए किया जाता है, और इसके components component-आधारित आर्किटेक्चर का पालन करते हैं।


A react component can be a function or a class, and it encapsulates logic and rendering for a specific part of the UI. Components can have their own state, props (properties), and lifecycle methods, making it easy to manage and update the UI in response to changes.


react components  एक फ़ंक्शन या क्लास हो सकता है, और यह UI के एक विशिष्ट भाग के लिए तर्क और प्रतिपादन को समाहित करता है। Components की अपनी state, props (properties) और lifecycle methods हो सकती हैं, जिससे परिवर्तनों के जवाब में UI को प्रबंधित करना और अपडेट करना आसान हो जाता है।


There are two main types of components in React:


रिएक्ट में दो मुख्य प्रकार के घटक हैं:


Function Components: These are stateless components that are typically defined as JavaScript functions. They take props as input and return JSX (JavaScript XML) to describe what should be rendered on the screen. Here's an example of a simple function component:

Function Components: ये स्टेटलेस घटक हैं जिन्हें आमतौर पर जावास्क्रिप्ट फ़ंक्शन के रूप में परिभाषित किया जाता है। वे propsइनपुट के रूप में लेते हैं और स्क्रीन पर क्या प्रस्तुत किया जाना चाहिए इसका वर्णन करने के लिए JSX (जावास्क्रिप्ट XML) लौटाते हैं। यहां एक सरल Function Component का उदाहरण दिया गया है:


jsx
import React from 'react'
const MyComponent = (props) => { 
return <div>Hello, {props.name}!</div>; }; 
export default MyComponent;

Class Components:

These are stateful components defined as ES6 classes. They extend the React.Component class and have more features like state and lifecycle methods. Here's an example of a class component:

Class Components:

 ये स्टेटफुल components हैं जिन्हें ES6 class के रूप में परिभाषित किया गया है। वे React.Component class extend करते हैं और उनमें state  और जीlifecycle methods जैसी अधिक सुविधाएँ होती हैं। यहां Class Components का एक उदाहरण दिया गया है:

jsx
import React from 'react'
class MyComponent extends React.Component
constructor(props) { 
super(props); 
this.state = { count: 0, }; } 
handleClick = () =>
this.setState({ count: this.state.count + 1 }); }; 
render() {
return ( <div> <p>Count: {this.state.count}</p> <button onClick={this.handleClick}>Increment</button> </div> ); } } 
export default MyComponent;


To use these components in other parts of your React application, you can import and include them just like any other JavaScript module: 

अपने रिएक्ट एप्लिकेशन के अन्य भागों में इन components का उपयोग करने के लिए, आप उन्हें किसी अन्य जावास्क्रिप्ट मॉड्यूल की तरह ही import और include कर सकते हैं:


jsx
import React from 'react'
import MyComponent from './MyComponent'
const App = () => { 
return ( <div> <MyComponent name="John" /> </div> ); };
export default App;

Remember to have a proper setup with tools like Babel and Webpack to transpile and bundle your react components for browser compatibility. 

ब्राउज़र संगतता के लिए अपने रिएक्ट घटकों को ट्रांसपाइल और बंडल करने के लिए बैबल और वेबपैक जैसे टूल के साथ उचित सेटअप रखना याद रखें।

Popular Posts