diff --git a/beta/src/pages/learn/writing-markup-with-jsx.md b/beta/src/pages/learn/writing-markup-with-jsx.md index 4e4ff9298..704283ce4 100644 --- a/beta/src/pages/learn/writing-markup-with-jsx.md +++ b/beta/src/pages/learn/writing-markup-with-jsx.md @@ -1,24 +1,24 @@ --- -title: Writing Markup with JSX +title: JSX के साथ मार्कअप लिखना --- -*JSX* is a syntax extension for JavaScript that lets you write HTML-like markup inside a JavaScript file. Although there are other ways to write components, most React developers prefer the conciseness of JSX, and most codebases use it. +*JSX* जावास्क्रिप्ट के लिए एक सिंटैक्स एक्सटेंशन है जो आपको जावास्क्रिप्ट फ़ाइल के अंदर HTML जैसा मार्कअप लिखने देता है। यद्यपि कौम्पोनॅन्ट्स को लिखने के अन्य तरीके हैं, अधिकांश React डेवलपर्स JSX की संक्षिप्तता को पसंद करते हैं, और अधिकांश कोडबेस इसका उपयोग करते हैं। -* Why React mixes markup with rendering logic -* How JSX is different from HTML -* How to display information with JSX +* React मार्कअप को रेंडरिंग लॉजिक के साथ क्यों मिलाता है +* JSX HTML से कैसे अलग है +* JSX के साथ जानकारी कैसे डिस्प्ले करें -## JSX: Putting markup into JavaScript {/*jsx-putting-markup-into-javascript*/} +## JSX: जावास्क्रिप्ट में मार्कअप डालना {/*jsx-putting-markup-into-javascript*/} -The Web has been built on HTML, CSS, and JavaScript. For many years, web developers kept content in HTML, design in CSS, and logic in JavaScript—often in separate files! Content was marked up inside HTML while the page's logic lived separately in JavaScript: +वेब को HTML, CSS और जावास्क्रिप्ट पर बनाया गया है। कई वर्षों तक, वेब डेवलपर्स ने HTML में कंटेंट, CSS में डिज़ाइन और जावास्क्रिप्ट में लॉजिक अक्सर अलग-अलग फाइलों में रखा! कंटेंट को HTML के अंदर चिह्नित किया गया था जबकि पेज का लॉजिक जावास्क्रिप्ट में अलग से रहता था: @@ -36,7 +36,7 @@ JavaScript -But as the Web became more interactive, logic increasingly determined content. JavaScript was in charge of the HTML! This is why **in React, rendering logic and markup live together in the same place—components.** +लेकिन जैसे-जैसे वेब अधिक इंटरैक्टिव होता गया, लॉजिक कंटेंट को अधिकाधिक निर्धारित करता गया। जावास्क्रिप्ट HTML का इन्चार्ज था! यही कारण है कि **React में, रेंडरिंग लॉजिक और मार्कअप एक ही स्थान पर एक साथ रहते हैं—कौम्पोनॅन्टस!** @@ -54,19 +54,19 @@ But as the Web became more interactive, logic increasingly determined content. J -Keeping a button's rendering logic and markup together ensures that they stay in sync with each other on every edit. Conversely, details that are unrelated, such as the button's markup and a sidebar's markup, are isolated from each other, making it safer to change either of them on their own. +एक बटन के रेंडरिंग लॉजिक और मार्कअप को एक साथ रखने से यह सुनिश्चित होता है कि वे प्रत्येक संपादन पर एक दूसरे के साथ तालमेल बिठाते रहें। इसके विपरीत, जो डिटेल्स असंबंधित हैं, जैसे कि बटन का मार्कअप और साइडबार का मार्कअप, एक दूसरे से अलग हो जाते हैं, जिससे उनमें से किसी एक को अपने आप बदलना सुरक्षित हो जाता है। -Each React component is a JavaScript function that may contain some markup that React renders into the browser. React components use a syntax extension called JSX to represent that markup. JSX looks a lot like HTML, but it is a bit stricter and can display dynamic information. The best way to understand this is to convert some HTML markup to JSX markup. +प्रत्येक React कौम्पोनॅन्ट एक जावास्क्रिप्ट फ़ंक्शन है जिसमें कुछ मार्कअप हो सकते हैं जो React ब्राउज़र में रेंडर करता है। React कौम्पोनॅन्ट मार्कअप को रिप्रेजेंट करने के लिए JSX नामक एक सिंटैक्स एक्सटेंशन का उपयोग करते हैं। JSX HTML की तरह दिखता है, लेकिन यह थोड़ा सख्त है और डायनामिक जानकारी डिस्प्ले कर सकता है। इसे समझने का सबसे अच्छा तरीका कुछ HTML मार्कअप को JSX मार्कअप में बदलना है। -[JSX and React are two separate things](/blog/2020/09/22/introducing-the-new-jsx-transform.html#whats-a-jsx-transform) you _can_ use independently of each other. +[JSX और React दो अलग चीजें हैं](/blog/2020/09/22/introducing-the-new-jsx-transform.html#whats-a-jsx-transform) आप एक दूसरे से स्वतंत्र रूप से उपयोग कर सकते हैं। -## Converting HTML to JSX {/*converting-html-to-jsx*/} +## HTML को JSX में बदलना {/*converting-html-to-jsx*/} -Suppose that you have some (perfectly valid) HTML: +मान लीजिए कि आपके पास कुछ (पूरी तरह से वैलिड) HTML है: ```html

Hedy Lamarr's Todos

@@ -74,15 +74,15 @@ Suppose that you have some (perfectly valid) HTML: src="https://i.imgur.com/yXOvdOSs.jpg" alt="Hedy Lamarr" class="photo" -> + > ``` -And you want to put it into your component: +और आप इसे अपने कौम्पोनॅन्ट में रखना चाहते हैं: ```js export default function TodoList() { @@ -92,25 +92,24 @@ export default function TodoList() { } ``` -If you copy and paste it as is, it will not work: - +यदि आप इसे वैसे ही कॉपी और पेस्ट करते हैं, तो यह काम नहीं करेगा: ```js export default function TodoList() { return ( - // This doesn't quite work! + // यह काम नहीं करता!

Hedy Lamarr's Todos

- Hedy Lamarr ); } @@ -122,28 +121,27 @@ img { height: 90px }
-This is because JSX is stricter and has a few more rules than HTML! If you read the error messages above, they'll guide you to fix the markup, or you can follow the guide below. +ऐसा इसलिए है क्योंकि JSX सख्त है और इसमें HTML की तुलना में कुछ और नियम हैं! यदि आप ऊपर दिए गए एरर मैसेजेस को पढ़ते हैं, तो वे मार्कअप को ठीक करने के लिए आपका मार्गदर्शन करेंगे, या आप नीचे दी गई गाइड का फॉलो कर सकते हैं। -Most of the times, React's on-screen error messages will help you find where the problem is. Give them a read if you get stuck! - +अधिकांश समय, React के ऑन-स्क्रीन एरर मैसेजेस आपको यह पता लगाने में मदद करेंगे कि समस्या कहाँ है। अगर आप फंस गए हैं तो उन्हें पढ़ लें! -## The Rules of JSX {/*the-rules-of-jsx*/} +## JSX के नियम {/*the-rules-of-jsx*/} -### 1. Return a single root element {/*1-return-a-single-root-element*/} +### 1. एक सिंगल रुट एलिमेंट रिटर्न करें {/*1-return-a-single-root-element*/} -To return multiple elements from a component, **wrap them with a single parent tag**. +एक कौम्पोनॅन्ट से कई एलिमेंट्स को रिटर्न करने के लिए, **उन्हें सिंगल पैरेंट टैग मैं ऐड करें**। -For example, you can use a `
`: +उदाहरण के लिए, आप एक `
` का उपयोग कर सकते हैं: ```js {1,11}

Hedy Lamarr's Todos

- Hedy Lamarr
    @@ -152,15 +150,14 @@ For example, you can use a `
    `:
    ``` - -If you don't want to add an extra `
    ` to your markup, you can write `<>` and `` instead: +यदि आप अपने मार्कअप में एक्स्ट्रा `
    ` ऐड नहीं करना चाहते हैं, तो आप इसके बजाय `<>` और `` लिख सकते हैं: ```js {1,11} <>

    Hedy Lamarr's Todos

    - Hedy Lamarr
      @@ -169,62 +166,62 @@ If you don't want to add an extra `
      ` to your markup, you can write `<>` and ``` -This empty tag is called a *[React fragment](TODO)*. React fragments let you group things without leaving any trace in the browser HTML tree. +इस खाली टैग को *[React fragment](TODO)* कहा जाता है। React fragments आपको ब्राउज़र HTML ट्री में कोई निशान छोड़े बिना चीजों को ग्रुप करने देते हैं। - + -JSX looks like HTML, but under the hood it is transformed into plain JavaScript objects. You can't return two objects from a function without wrapping them into an array. This explains why you also can't return two JSX tags without wrapping them into another tag or a fragment. +JSX HTML की तरह दिखता है, लेकिन असल में प्लेन जावास्क्रिप्ट ऑब्जेक्ट्स में बदल दिया जाता है। आप किसी फ़ंक्शन से दो ऑब्जेक्ट्स को एक ऐरे में रैप किये बिना रिटर्न नहीं कर सकते। यह बताता है कि आप दो JSX टैग को दूसरे टैग या fragment में रैप किये बिना रिटर्न क्यों नहीं कर सकते। -### 2. Close all the tags {/*2-close-all-the-tags*/} +### 2. सभी टैग बंद करें {/*2-close-all-the-tags*/} -JSX requires tags to be explicitly closed: self-closing tags like `` must become ``, and wrapping tags like `
    • oranges` must be written as `
    • oranges
    • `. +JSX को टैग को स्पष्ट रूप से बंद करने की आवश्यकता है: `` जैसे सेल्फ-क्लोजिंग टैग `` बनने चाहिए, और `
    • संतरा` जैसे रैपिंग टैग को `
    • संतरा
    • ` के रूप में लिखा जाना चाहिए। -This is how Hedy Lamarr's image and list items look closed: +इस प्रकार Hedy Lamarr की इमेज और लिस्ट आइटम बंद दिखते हैं: ```js {2-6,8-10} <> Hedy Lamarr
        -
      • Invent new traffic lights
      • -
      • Rehearse a movie scene
      • -
      • Improve the spectrum technology
      • +
      • नई ट्रैफिक लाइट का आविष्कार करें
      • +
      • एक फिल्म के दृश्य का पूर्वाभ्यास करें
      • +
      • स्पेक्ट्रम तकनीक में सुधार
      ``` -### 3. camelCase all most of the things! {/*3-camelcase-salls-most-of-the-things*/} +### 3. camelCase करें सब ज़्यादातर चीज़ें! {/*3-camelcase-salls-most-of-the-things*/} -JSX turns into JavaScript and attributes written in JSX become keys of JavaScript objects. In your own components, you will often want to read those attributes into variables. But JavaScript has limitations on variable names. For example, their names can't contain dashes or be reserved words like `class`. +JSX जावास्क्रिप्ट में बदल जाता है और JSX में लिखी ऐट्रिब्यूट्स जावास्क्रिप्ट ऑब्जेक्ट्स की keys बन जाती हैं। अपने स्वयं के कौम्पोनॅन्ट्स में, आप अक्सर उन ऐट्रिब्यूट्स को वेरिएबल्स में पढ़ना चाहेंगे। लेकिन जावास्क्रिप्ट में वेरिएबल के नामों की सीमाएँ हैं। उदाहरण के लिए, उनके नामों में डैश नहीं हो सकते हैं या `class` जैसे रिज़र्व शब्द नहीं हो सकते हैं। -This is why, in React, many HTML and SVG attributes are written in camelCase. For example, instead of `stroke-width` you use `strokeWidth`. Since `class` is a reserved word, in React you write `className` instead, named after the [corresponding DOM property](https://developer.mozilla.org/en-US/docs/Web/API/Element/className): +यही कारण है कि, React में, कई HTML और SVG ऐट्रिब्यूट्स camelCase में लिखी जाती हैं। उदाहरण के लिए, `stroke-width` के बजाय आप `strokeWidth` का उपयोग करते हैं। चूंकि `class` एक रिजर्व्ड शब्द है, इसलिए React में आप इसके बजाय `className` लिखते हैं, जिसका नाम [संबंधित DOM प्रॉपर्टी](https://developer.mozilla.org/en-US/docs/Web/API/Element/className) के नाम पर रखा गया है।: ```js {4} Hedy Lamarr ``` -You can [find all these attributes in the React DOM Elements](TODO). If you get one wrong, don't worry—React will print a message with a possible correction to the [browser console](https://developer.mozilla.org/docs/Tools/Browser_Console). +आप [इन सभी ऐट्रिब्यूट्स को React DOM एलिमेंट्स में पा सकते हैं](TODO). यदि आप एक गलत पाते हैं, तो चिंता न करें React संभावित सुधार के साथ एक संदेश [ब्राउज़र कंसोल](https://developer.mozilla.org/docs/Tools/Browser_Console) पर प्रिंट करेगी। -For historical reasons, [`aria-*`](https://developer.mozilla.org/docs/Web/Accessibility/ARIA) and [`data-*`](https://developer.mozilla.org/docs/Learn/HTML/Howto/Use_data_attributes) attributes are written as in HTML with dashes. +ऐतिहासिक कारणों से, [`aria-*`](https://developer.mozilla.org/docs/Web/Accessibility/ARIA) और [`data-*`](https://developer.mozilla.org/docs/Learn/HTML/Howto/Use_data_attributes) ऐट्रिब्यूट्स HTML में डैश के साथ लिखी जाती हैं। -### Pro-tip: Use a JSX Converter {/*pro-tip-use-a-jsx-converter*/} +### प्रो-टिप: JSX कन्वर्टर का उपयोग करें {/*pro-tip-use-a-jsx-converter*/} -Converting all these attributes in existing markup can be tedious! We recommend using a [converter](https://transform.tools/html-to-jsx) to translate your existing HTML and SVG to JSX. Converters are very useful in practice, but it's still worth understanding what is going on so that you can comfortably write JSX on your own. +इन सभी ऐट्रिब्यूट्स को मौजूदा मार्कअप में बदलना थकाऊ हो सकता है! हम रिकमेंड करते हैं कि आप अपने मौजूदा HTML और SVG का JSX में अनुवाद करने के लिए [कन्वर्टर](https://transform.tools/html-to-jsx) का उपयोग करें। कन्वर्टर्स व्यवहार में बहुत उपयोगी होते हैं, लेकिन यह अभी भी समझने योग्य है कि क्या हो रहा है ताकि आप आराम से JSX को स्वयं लिख सकें। -Here is your final result: +यहाँ आपका अंतिम परिणाम है: @@ -233,15 +230,15 @@ export default function TodoList() { return ( <>

      Hedy Lamarr's Todos

      - Hedy Lamarr
        -
      • Invent new traffic lights
      • -
      • Rehearse a movie scene
      • -
      • Improve the spectrum technology
      • +
      • नई ट्रैफिक लाइट का आविष्कार करें
      • +
      • एक फिल्म के दृश्य का पूर्वाभ्यास करें
      • +
      • स्पेक्ट्रम तकनीक में सुधार
      ); @@ -249,28 +246,26 @@ export default function TodoList() { ``` ```css -img { height: 90px } +img { height: 90px; } ```
      -Now you know why JSX exists and how to use it in components: +अब आप जानते हैं कि JSX क्यों मौजूद है और इसे कौम्पोनॅन्ट्स में कैसे उपयोग किया जाए: -* React components group rendering logic together with markup because they are related. -* JSX is similar to HTML, with a few differences. You can use a [converter](https://transform.tools/html-to-jsx) if you need to. -* Error messages will often point you in the right direction to fixing your markup. +* React कौम्पोनॅन्ट समूह मार्कअप के साथ लॉजिक रेंडर करता है क्योंकि वे संबंधित हैं। +* JSX कुछ अंतरों के साथ HTML के समान है। जरूरत पड़ने पर आप [कन्वर्टर](https://transform.tools/html-to-jsx) का उपयोग कर सकते हैं। +* एरर मैसेजेस अक्सर आपको अपना मार्कअप ठीक करने की सही दिशा में इंगित करेंगे। - - -### Convert some HTML to JSX {/*convert-some-html-to-jsx*/} +### कुछ HTML को JSX में बदलें {/*convert-some-html-to-jsx*/} -This HTML was pasted into a component, but it's not valid JSX. Fix it: +यह HTML एक कौम्पोनॅन्ट में पेस्ट गया था, लेकिन यह JSX वैलिड नहीं है। इसे ठीक करें: @@ -278,12 +273,12 @@ This HTML was pasted into a component, but it's not valid JSX. Fix it: export default function Bio() { return (
      -

      Welcome to my website!

      +

      मेरी वेबसाइट पर स्वागत है!

      - You can find my thoughts here. + आप यहां मेरे विचार पा सकते हैं।

      - And pictures of scientists! + और तस्वीरें वैज्ञानिकों की!

      ); } @@ -306,7 +301,7 @@ export default function Bio() {
      -Whether to do it by hand or using the converter is up to you! +इसे हाथ से करना है या कनवर्टर का उपयोग करना आप पर निर्भर है! @@ -317,12 +312,12 @@ export default function Bio() { return (
      -

      Welcome to my website!

      +

      मेरी वेबसाइट पर स्वागत है!

      - You can find my thoughts here. + आप यहां मेरे विचार पा सकते हैं।

      - And pictures of scientists! + और तस्वीरें वैज्ञानिकों की!

      );