diff --git a/content/docs/lifting-state-up.md b/content/docs/lifting-state-up.md
index c01c5eab2..7c3386754 100644
--- a/content/docs/lifting-state-up.md
+++ b/content/docs/lifting-state-up.md
@@ -1,6 +1,6 @@
---
id: lifting-state-up
-title: Lifting State Up
+title: लिफ्टिंग स्टेट अप
permalink: docs/lifting-state-up.html
prev: forms.html
next: composition-vs-inheritance.html
@@ -9,11 +9,11 @@ redirect_from:
- "docs/flux-todo-list.html"
---
-Often, several components need to reflect the same changing data. We recommend lifting the shared state up to their closest common ancestor. Let's see how this works in action.
+अक्सर, कई कौम्पोनॅन्टस को एक ही बदलते डेटा को प्रतिबिंबित करने की आवश्यकता होती है। हम उनके निकटतम सामान्य पैरेंट तक स्टेट को उठाने की सलाह देते हैं। आइए देखें कि यह कैसे कार्य करता है।
-In this section, we will create a temperature calculator that calculates whether the water would boil at a given temperature.
+इस खंड में, हम एक तापमान कैलकुलेटर बनाएंगे जो गणना करता है कि पानी किसी दिए गए तापमान पर उबलता है या नहीं।
-We will start with a component called `BoilingVerdict`. It accepts the `celsius` temperature as a prop, and prints whether it is enough to boil the water:
+हम `BoilingVerdict` नामक एक कौम्पोनॅन्ट के साथ शुरुआत करेंगे। यह `celsius` तापमान को prop के रूप में स्वीकार करता है, और प्रिंट करता है यदि पानी उबलने वाला है:
```js{3,5}
function BoilingVerdict(props) {
@@ -24,9 +24,9 @@ function BoilingVerdict(props) {
}
```
-Next, we will create a component called `Calculator`. It renders an `` that lets you enter the temperature, and keeps its value in `this.state.temperature`.
+इसके बाद, हम 'Calculator' नामक एक कौम्पोनॅन्ट बनाएंगे। यह एक `` रेंडर करेगा, जिसमे आप तापमान दर्ज कर सकते हैं, जिसकी value `this.state.temperature` में रहेगी।
-Additionally, it renders the `BoilingVerdict` for the current input value.
+इसके अतिरिक्त, यह वर्तमान इनपुट मूल्य के लिए `BoilingVerdict` को रेंडर करेगा।
```js{5,9,13,17-21}
class Calculator extends React.Component {
@@ -56,13 +56,13 @@ class Calculator extends React.Component {
}
```
-[**Try it on CodePen**](https://codepen.io/gaearon/pen/ZXeOBm?editors=0010)
+[**इसे CodePen पर आज़माएँ**](https://codepen.io/gaearon/pen/ZXeOBm?editors=0010)
-## Adding a Second Input {#adding-a-second-input}
+## एक दूसरा इनपुट जोड़ना {#adding-a-second-input}
-Our new requirement is that, in addition to a Celsius input, we provide a Fahrenheit input, and they are kept in sync.
+हमारी नई आवश्यकता यह है कि, एक Celsius इनपुट के अलावा, हम एक Fahrenheit इनपुट प्रदान करें, और वे sync में रहें।
-We can start by extracting a `TemperatureInput` component from `Calculator`. We will add a new `scale` prop to it that can either be `"c"` or `"f"`:
+हम `Calculator` से एक `TemperatureInput` कौम्पोनॅन्ट को निकालने से शुरुआत कर सकते हैं। हम इसमें एक नया `scale` prop जोड़ेंगे, जो या तो `"c"` या `"f"` हो सकता है:
```js{1-4,19,22}
const scaleNames = {
@@ -95,7 +95,7 @@ class TemperatureInput extends React.Component {
}
```
-We can now change the `Calculator` to render two separate temperature inputs:
+अब हम `Calculator` को दो अलग-अलग तापमान इनपुट्स दिखाने के लिए बदल सकते हैं:
```js{5,6}
class Calculator extends React.Component {
@@ -110,15 +110,15 @@ class Calculator extends React.Component {
}
```
-[**Try it on CodePen**](https://codepen.io/gaearon/pen/jGBryx?editors=0010)
+[**इसे CodePen पर आज़माएँ**](https://codepen.io/gaearon/pen/jGBryx?editors=0010)
-We have two inputs now, but when you enter the temperature in one of them, the other doesn't update. This contradicts our requirement: we want to keep them in sync.
+अभ हमारे पास दो इनपुट हैं, लेकिन जब आप उनमें से एक में तापमान दर्ज करते हैं, तो दूसरा अपडेट नहीं होता। यह हमारी आवश्यकता के विपरीत है: हम उन्हें sync में रखना चाहते हैं।
-We also can't display the `BoilingVerdict` from `Calculator`. The `Calculator` doesn't know the current temperature because it is hidden inside the `TemperatureInput`.
+हम `Calculator` से `BoilingVerdict` भी प्रदर्शित नहीं कर सकते। `Calculator` वर्तमान तापमान को नहीं जानता है क्योंकि यह `TemperatureInput` के अंदर छिपा हुआ है।
-## Writing Conversion Functions {#writing-conversion-functions}
+## कन्वर्शन फंक्शन्स लिखना {#writing-conversion-functions}
-First, we will write two functions to convert from Celsius to Fahrenheit and back:
+सबसे पहले, हम दो फंक्शन्स लिखेंगे, Celsius से Fahrenheit और वापस Fahrenheit से Celsius में बदलने के लिए:
```js
function toCelsius(fahrenheit) {
@@ -130,9 +130,9 @@ function toFahrenheit(celsius) {
}
```
-These two functions convert numbers. We will write another function that takes a string `temperature` and a converter function as arguments and returns a string. We will use it to calculate the value of one input based on the other input.
+यह दो फंक्शन्स संख्याओं को परिवर्तित करते हैं। हम एक और फ़ंक्शन लिखेंगे जो एक स्ट्रिंग `temperature` और एक कनवर्टर फ़ंक्शन को आर्गुमेंट के रूप में लेता है और एक स्ट्रिंग वापिस देता है। हम इसका उपयोग एक इनपुट के आधार पर दूसरे इनपुट की गणना करने के लिए करेंगे।
-It returns an empty string on an invalid `temperature`, and it keeps the output rounded to the third decimal place:
+यह अमान्य `temperature` पर एक खाली स्ट्रिंग देता है, और यह आउटपुट को तीसरे दशमलव स्थान तक सीमित रखता है:
```js
function tryConvert(temperature, convert) {
@@ -146,11 +146,11 @@ function tryConvert(temperature, convert) {
}
```
-For example, `tryConvert('abc', toCelsius)` returns an empty string, and `tryConvert('10.22', toFahrenheit)` returns `'50.396'`.
+उदाहरण के लिए, `tryConvert('abc', toCelsius)` एक खाली स्ट्रिंग लौटाता है, और `tryConvert('10.22', toFahrenheit)` `'50.396'` लौटाता है।
-## Lifting State Up {#lifting-state-up}
+## लिफ्टिंग स्टेट अप {#lifting-state-up}
-Currently, both `TemperatureInput` components independently keep their values in the local state:
+वर्तमान में, दोनों `TemperatureInput` कौम्पोनॅन्टस अपनी लोकल स्टेट को स्वतंत्र रूप में बनाये रखते हैं:
```js{5,9,13}
class TemperatureInput extends React.Component {
@@ -169,15 +169,15 @@ class TemperatureInput extends React.Component {
// ...
```
-However, we want these two inputs to be in sync with each other. When we update the Celsius input, the Fahrenheit input should reflect the converted temperature, and vice versa.
+हालाँकि, हम चाहते हैं कि ये दोनों इनपुट एक दूसरे के sync में रहें। जब हम Celsius इनपुट को अपडेट करें, तो Fahrenheit इनपुट अपडेट हो और इसके विपरीत भी रिफ्लेक्ट होना चाहिए।
-In React, sharing state is accomplished by moving it up to the closest common ancestor of the components that need it. This is called "lifting state up". We will remove the local state from the `TemperatureInput` and move it into the `Calculator` instead.
+React में, state साझा करने का कार्य उसे कौम्पोनॅन्टस के निकटतम सामान्य पूर्वज तक ले जाकर पूरा किया जाता है। यह "लिफ्टिंग स्टेट अप" कहलाता है। हम लोकल स्टेट को `TemperatureInput` से हटा देंगे एवं `Calculator` में ले जायेंगे।
-If the `Calculator` owns the shared state, it becomes the "source of truth" for the current temperature in both inputs. It can instruct them both to have values that are consistent with each other. Since the props of both `TemperatureInput` components are coming from the same parent `Calculator` component, the two inputs will always be in sync.
+यदि साझा स्टेट का मालिक `Calculator` हे, तो वह दोनों इन्पुट्स में वर्तमान तापमान के लिए "सत्य का स्रोत" बन जाता है। यह उन दोनों को एक दूसरे के अनुरूप वैल्यूज रखने का निर्देश दे सकता है। चूंकि दोनों `TemperatureInput` कौम्पोनॅन्टस के props एक ही `Calculator` पैरेंट कौम्पोनॅन्ट से हैं, यह दोनों हमेशा sync में रहेंगे।
-Let's see how this works step by step.
+आइए देखें कि यह स्टेप-बाय-स्टेप कैसे काम करता है।
-First, we will replace `this.state.temperature` with `this.props.temperature` in the `TemperatureInput` component. For now, let's pretend `this.props.temperature` already exists, although we will need to pass it from the `Calculator` in the future:
+सबसे पहले, हम `TemperatureInput` कौम्पोनॅन्ट में `this.state.temperature` को `this.props.temperature` से बदल देंगे। अभी के लिए, मान लीजिये कि `this.props.temperature` पहले से ही मौजूद है, हालाँकि हमें भविष्य में इसे `Calculator` से पास करना होगा:
```js{3}
render() {
@@ -186,11 +186,11 @@ First, we will replace `this.state.temperature` with `this.props.temperature` in
// ...
```
-We know that [props are read-only](/docs/components-and-props.html#props-are-read-only). When the `temperature` was in the local state, the `TemperatureInput` could just call `this.setState()` to change it. However, now that the `temperature` is coming from the parent as a prop, the `TemperatureInput` has no control over it.
+हम जानते हैं कि [props read-only हैं](/docs/components-and-props.html#props-are-read-only). जब `temperature` लोकल state में था, तो `TemperatureInput` इसे बदलने के लिए `this.setState()` को कॉल कर सकता था। हालाँकि, अब `temperature` अपने पैरेंट से prop बनकर आ रहा है, `TemperatureInput' का इस पर कोई नियंत्रण नहीं होगा।
-In React, this is usually solved by making a component "controlled". Just like the DOM `` accepts both a `value` and an `onChange` prop, so can the custom `TemperatureInput` accept both `temperature` and `onTemperatureChange` props from its parent `Calculator`.
+React में, यह मसला आमतौर पर कौम्पोनॅन्ट को "controlled" बनाकर हल किया जाता है। जैसे DOM ``, `value` एवं `onChange` prop दोनों को स्वीकार करता है, ठीक वैसे ही, `TemperatureInput` दोनों `temperature` एवं `onTemperatureChange` props को उसके पैरेंट `Calculator` से स्वीकार करेगा।
-Now, when the `TemperatureInput` wants to update its temperature, it calls `this.props.onTemperatureChange`:
+अब, जब `TemperatureInput` अपने तापमान को अपडेट करना चाहेगा, तो वह `this.props.onTemperatureChange` को कॉल करेगा:
```js{3}
handleChange(e) {
@@ -199,13 +199,13 @@ Now, when the `TemperatureInput` wants to update its temperature, it calls `this
// ...
```
->Note:
+>ध्यान दें:
>
->There is no special meaning to either `temperature` or `onTemperatureChange` prop names in custom components. We could have called them anything else, like name them `value` and `onChange` which is a common convention.
+>कस्टम कौम्पोनॅन्टस में `temperature` या `onTemperatureChange` prop नामों का कोई विशेष अर्थ नहीं है। हम उन्हें और कुछ भी कह सकते थे, जैसे कि `value` और `onChange` जो एक आम परंपरा है।
-The `onTemperatureChange` prop will be provided together with the `temperature` prop by the parent `Calculator` component. It will handle the change by modifying its own local state, thus re-rendering both inputs with the new values. We will look at the new `Calculator` implementation very soon.
+पैरेंट `Calculator` कौम्पोनॅन्ट के द्वारा `onTemperatureChange` prop को `temperature` prop के साथ प्रदान किया जाएगा। वह अपने लोकल state में बदलाव के द्वारा इस परिवर्तन को नियंत्रित करेगा, और इस प्रकार दोनों इनपुट्स को नए मूल्यों के साथ फिर से प्रस्तुत करेगा। हम बहुत जल्द नए `Calculator` के इम्प्लीमेंटेशन को देखेंगे।
-Before diving into the changes in the `Calculator`, let's recap our changes to the `TemperatureInput` component. We have removed the local state from it, and instead of reading `this.state.temperature`, we now read `this.props.temperature`. Instead of calling `this.setState()` when we want to make a change, we now call `this.props.onTemperatureChange()`, which will be provided by the `Calculator`:
+आईये `Calculator` में परिवर्तन करने से पहले, `TemperatureInput` कौम्पोनॅन्ट में किये गए परिवर्तनों को संक्षेप में दोहरातें हैं। हमने इसमें से लोकल state को हटा दिया है, और `this.state.temperature` रीड करने के बजाय, हम अब `this.props.temperature` रीड करते हैं। जब हम कोई बदलाव करना चाहते हैं तो `this.setState()` को कॉल करने के बजाय हम अब `this.props.onTemperatureChange()` को कॉल करते हैं, जो `Calculator` उपलब्ध कराता है।
```js{8,12}
class TemperatureInput extends React.Component {
@@ -232,11 +232,11 @@ class TemperatureInput extends React.Component {
}
```
-Now let's turn to the `Calculator` component.
+अब `Calculator` कौम्पोनॅन्ट की ओर मुड़ते हैं।
-We will store the current input's `temperature` and `scale` in its local state. This is the state we "lifted up" from the inputs, and it will serve as the "source of truth" for both of them. It is the minimal representation of all the data we need to know in order to render both inputs.
+हम वर्तमान इनपुट के `temperature` और `scale` को उसके लोकल state में स्टोर करेंगे। यह वही state है जिसे हमने इनपुट्स से "ऊपर उठा लिया था", और यह उन दोनों के लिए "सत्य के स्रोत" के रूप में काम करेगी। यह उन सभी डेटा का न्यूनतम प्रतिनिधित्व है जिन्हें हमें जानना आवश्यक है, दोनों इनपुट को रेंडर करने के लिए|
-For example, if we enter 37 into the Celsius input, the state of the `Calculator` component will be:
+उदाहरण के लिए, यदि हम Celsius इनपुट में 37 दर्ज करते हैं, तो `Calculator` कौम्पोनॅन्ट की state होगी:
```js
{
@@ -245,7 +245,7 @@ For example, if we enter 37 into the Celsius input, the state of the `Calculator
}
```
-If we later edit the Fahrenheit field to be 212, the state of the `Calculator` will be:
+यदि हम बाद में Fahrenheit फ़ील्ड को 212 में संपादित करते हैं, तो `Calculator` की state होगी:
```js
{
@@ -254,9 +254,9 @@ If we later edit the Fahrenheit field to be 212, the state of the `Calculator` w
}
```
-We could have stored the value of both inputs but it turns out to be unnecessary. It is enough to store the value of the most recently changed input, and the scale that it represents. We can then infer the value of the other input based on the current `temperature` and `scale` alone.
+हम दोनों इनपुट्स की वैल्यू स्टोर कर सकते थे लेकिन यह अनावश्यक है। सबसे हाल ही में बदले गये इनपुट की वैल्यू एवं उसका प्रतिनिधित्व करने वाले scale को ही स्टोर करना पर्याप्त है। तब हम वर्तमान `temperature` और `scale` के आधार पर अन्य इनपुट की वैल्यू को निकाल सकते हैं।
-The inputs stay in sync because their values are computed from the same state:
+इनपुट्स sync में रहेंगे क्योंकि उनकी वैल्यूज की गणना एक ही state से हो रही है:
```js{6,10,14,18-21,27-28,31-32,34}
class Calculator extends React.Component {
@@ -299,32 +299,31 @@ class Calculator extends React.Component {
}
```
-[**Try it on CodePen**](https://codepen.io/gaearon/pen/WZpxpz?editors=0010)
+[**इसे CodePen पर आज़माएँ**](https://codepen.io/gaearon/pen/WZpxpz?editors=0010)
-Now, no matter which input you edit, `this.state.temperature` and `this.state.scale` in the `Calculator` get updated. One of the inputs gets the value as is, so any user input is preserved, and the other input value is always recalculated based on it.
+अब, कोई फर्क नहीं पड़ता कि आप किस इनपुट को संपादित करते हैं, `Calculator` के `this.state.temperature` और `this.state.scale` अपडेट हो जायेंगे। इनपुट्स में से एक को वैल्यू मिलती है, इसलिए कोई भी user input संरक्षित रहता है, और अन्य इनपुट वैल्यू हमेशा इसके आधार पर पुनर्गणना होता है।
-Let's recap what happens when you edit an input:
+आइये संक्षेप में देखते हैं की एक इनपुट को संपादित करने पर क्या होता है :
-* React calls the function specified as `onChange` on the DOM ``. In our case, this is the `handleChange` method in the `TemperatureInput` component.
-* The `handleChange` method in the `TemperatureInput` component calls `this.props.onTemperatureChange()` with the new desired value. Its props, including `onTemperatureChange`, were provided by its parent component, the `Calculator`.
-* When it previously rendered, the `Calculator` has specified that `onTemperatureChange` of the Celsius `TemperatureInput` is the `Calculator`'s `handleCelsiusChange` method, and `onTemperatureChange` of the Fahrenheit `TemperatureInput` is the `Calculator`'s `handleFahrenheitChange` method. So either of these two `Calculator` methods gets called depending on which input we edited.
-* Inside these methods, the `Calculator` component asks React to re-render itself by calling `this.setState()` with the new input value and the current scale of the input we just edited.
-* React calls the `Calculator` component's `render` method to learn what the UI should look like. The values of both inputs are recomputed based on the current temperature and the active scale. The temperature conversion is performed here.
-* React calls the `render` methods of the individual `TemperatureInput` components with their new props specified by the `Calculator`. It learns what their UI should look like.
-* React calls the `render` method of the `BoilingVerdict` component, passing the temperature in Celsius as its props.
-* React DOM updates the DOM with the boiling verdict and to match the desired input values. The input we just edited receives its current value, and the other input is updated to the temperature after conversion.
+* React `onChange` के द्वारा निर्दिष्ट फंक्शन को DOM `` पर कॉल करता है। हमारे लिए, यह `TemperatureInput` कौम्पोनॅन्ट का `handleChange` मेथड है।
+* `TemperatureInput` कौम्पोनॅन्ट का `handleChange` मेथड, नए वांछित वैल्यू के साथ `this.props.onTemperChange()` को कॉल करता है। इसके props, जिनमें `onTemperatureChange` शामिल हैं, को इसके पैरेंट कौम्पोनॅन्ट `Calculator` द्वारा प्रदान किया जाता है।
+* जब यह पूर्व में रेंडर किया गया था, तो `Calculator` ने निर्दिष्ट किया है कि Celsius `TemperatureInput` का `onTemperatureChange` ही `Calculator` का `handleCelsiusChange` मेथड है, इसी प्रकार Fahrenheit `TemperatureInput` का `onTemperatureChange` ही `Calculator` का `handleFahrenheitChange` मेथड है। इनपुट के सम्पादन के आधार इन दोनों `Calculator` मेथडस में से किसी एक को कॉल किया जाता है।
+* इन मेथडस के अंदर, `Calculator` कौम्पोनॅन्ट React से `this.setState()` को कॉल करके, नयी इनपुट वैल्यू एवं वर्तमान scale जिसको हमने बस अभी सम्पादित किया, के साथ फिर से रेंडर होने को कहता है।
+* `Calculator` कौम्पोनॅन्ट के `render` मेथड को React कॉल करता है ताकि वह UI कैसा दिखता है यह जान सखे। दोनों इनपुट के वैल्यूज की वर्तमान तापमान और सक्रिय scale के आधार पर पुनर्गणना की जाती है। तापमान रूपांतरण यहां किया जाता है।
+* React `Calculator` द्वारा निर्देशित नए props के साथ `TemperatureInput` कौम्पोनॅन्टस के `render` मेथडस को कॉल करता है।
+* React DOM, boiling verdict के साथ DOM को अपडेट करता है और वांछित इनपुट वैल्यूज से मेल कराता है। जिस इनपुट को हमने अभी संपादित किया है, वह अपनी वर्तमान वैल्यू प्राप्त करता है, और अन्य इनपुट को रूपांतरण के बाद तापमान में अपडेट किया जाता है।
-Every update goes through the same steps so the inputs stay in sync.
+हर अपडेट समान स्टेप्स के माध्यम से जाता है ताकि इनपुट sync में रहें।
-## Lessons Learned {#lessons-learned}
+## सबक सीखा {#lessons-learned}
-There should be a single "source of truth" for any data that changes in a React application. Usually, the state is first added to the component that needs it for rendering. Then, if other components also need it, you can lift it up to their closest common ancestor. Instead of trying to sync the state between different components, you should rely on the [top-down data flow](/docs/state-and-lifecycle.html#the-data-flows-down).
+React एप्लीकेशन में परिवर्तन करने वाले किसी भी डेटा के लिए "सत्य का एक स्रोत" केवल एक होना चाहिए। आमतौर पर, state को पहले कौम्पोनॅन्ट में जोड़ा जाता है जो इसे रेंडर करने के लिए आवश्यक होता है। फिर, अगर अन्य कौम्पोनॅन्टस को भी इसकी आवश्यकता होती है, तो आप इसे अपने निकटतम सामान्य पूर्वज तक उठा सकते हैं।. अलग-अलग कौम्पोनॅन्टस के बीच state को sync करने की कोशिश करने के बजाय, आपको इस पर भरोसा करना चाहिए [ऊपर से नीचे डेटा प्रवाह](/docs/state-and-lifecycle.html#the-data-flows-down).
-Lifting state involves writing more "boilerplate" code than two-way binding approaches, but as a benefit, it takes less work to find and isolate bugs. Since any state "lives" in some component and that component alone can change it, the surface area for bugs is greatly reduced. Additionally, you can implement any custom logic to reject or transform user input.
+state को लिफ्ट करने में दो-तरफ़ा बंधन दृष्टिकोण की तुलना में अधिक "boilerplate" कोड लिखना शामिल है, लेकिन एक लाभ के रूप में, bug को खोजने और अलग करने में कम काम लगता है। चूंकि कोई भी state किसी कौम्पोनॅन्ट में "रहता है" और वह कौम्पोनॅन्ट अकेले इसे बदल सकता है, bug के लिए सतह क्षेत्र बहुत कम हो गया है। इसके अतिरिक्त, आप यूजर इनपुट को अस्वीकार या परिवर्तित करने के लिए कोई भी कस्टम लॉजिक लागू कर सकते हैं।
-If something can be derived from either props or state, it probably shouldn't be in the state. For example, instead of storing both `celsiusValue` and `fahrenheitValue`, we store just the last edited `temperature` and its `scale`. The value of the other input can always be calculated from them in the `render()` method. This lets us clear or apply rounding to the other field without losing any precision in the user input.
+यदि किसी को props या state के द्वारा प्राप्त किया जा सकता है, तो यह संभवतः state में नहीं होना चाहिए। उदाहरण के लिए, दोनों `celsiusValue` और `fahrenheitValue` को स्टोर करने के बजाय, हम केवल अंतिम संपादित `temperature` और इसके `scale` को स्टोर करते हैं। 'render()' मेथड् में उनकी सहायता से अन्य इनपुट की वैल्यू की गणना हमेशा की जा सकती है। यह हमें यूजर इनपुट में कोई भी सटीकता खोए बिना दूसरे फील्ड में राउंडिंग को हटाने या लागू करने देता है।
-When you see something wrong in the UI, you can use [React Developer Tools](https://github.com/facebook/react/tree/master/packages/react-devtools) to inspect the props and move up the tree until you find the component responsible for updating the state. This lets you trace the bugs to their source:
+जब आप UI में कुछ गलत देखते हैं, तब आप उपयोग कर सकते हैं [React Developer Tools](https://github.com/facebook/react-devtools) props का निरीक्षण करने और पेड़ के ऊपर चढ़ने के लिए जब तक कि आप कौम्पोनॅन्ट को state अपडेट करने के लिए जिम्मेदार नहीं पाते। यह आपको bugs के स्रोत का पता लगाने देता है: