Skip to content

Commit 84532c2

Browse files
Update useCallback.md
1 parent 000faa3 commit 84532c2

File tree

1 file changed

+0
-29
lines changed

1 file changed

+0
-29
lines changed

src/content/reference/react/useCallback.md

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,7 @@ export default function ProductPage({ productId, referrer, theme }) {
5252
5353
पहले रेंडर पर, `useCallback` आपके द्वारा पास किया गया `fn` फंक्शन रिटर्न करता है।
5454
55-
<<<<<<< HEAD
56-
अगले रेंडर पर, यह या तो पिछले रेंडर से कैश्ड `fn` फंक्शन रिटर्न करता है (यदि डिपेंडेंसीज़ नहीं बदली हैं), या इस रेंडर में पास किया गया नया `fn` फंक्शन रिटर्न करता है।
57-
=======
5855
During subsequent renders, it will either return an already stored `fn` function from the last render (if the dependencies haven't changed), or return the `fn` function you have passed during this render.
59-
>>>>>>> 2534424ec6c433cc2c811d5a0bd5a65b75efa5f0
6056
6157
#### Caveats {/*caveats*/}
6258
@@ -212,13 +208,8 @@ function ProductPage({ productId, referrer }) {
212208
213209
यदि आप [`useMemo`](/reference/react/useMemo) से परिचित हैं, तो `useCallback` को इस तरह समझ सकते हैं:
214210
215-
<<<<<<< HEAD
216-
```js
217-
// आसान इम्प्लिमेंटेशन (React में कुछ ऐसा होता है)
218-
=======
219211
```js {expectedErrors: {'react-compiler': [3]}}
220212
// Simplified implementation (inside React)
221-
>>>>>>> 2534424ec6c433cc2c811d5a0bd5a65b75efa5f0
222213
function useCallback(fn, dependencies) {
223214
return useMemo(() => fn, dependencies);
224215
}
@@ -232,15 +223,9 @@ function useCallback(fn, dependencies) {
232223
233224
#### क्या हर जगह `useCallback` जोड़ना चाहिए? {/*should-you-add-usecallback-everywhere*/}
234225
235-
<<<<<<< HEAD
236-
यदि आपका ऐप इस साइट जैसा है, और ज़्यादातर इंटरैक्शन्स मोटे स्तर के हैं (जैसे पूरे पेज या सेक्शन को रिप्लेस करना), तो सामान्यतः मेमोइज़ेशन की ज़रूरत नहीं होती। लेकिन यदि आपका ऐप ड्रॉइंग एडिटर जैसा है और इंटरैक्शन्स छोटे स्तर के हैं (जैसे शेप्स को मूव करना), तो मेमोइज़ेशन बहुत मददगार हो सकता है।
237-
238-
`useCallback` से फंक्शन को कैश करना केवल कुछ स्थितियों में उपयोगी है:
239-
=======
240226
If your app is like this site, and most interactions are coarse (like replacing a page or an entire section), memoization is usually unnecessary. On the other hand, if your app is more like a drawing editor, and most interactions are granular (like moving shapes), then you might find memoization very helpful.
241227
242228
Caching a function with `useCallback` is only valuable in a few cases:
243-
>>>>>>> 2534424ec6c433cc2c811d5a0bd5a65b75efa5f0
244229
245230
* जब आप इसे किसी [`memo`](/reference/react/memo) में रैप किए गए कौम्पोनॅन्ट को प्रॉप के रूप में पास करते हैं। आप चाहते हैं कि वैल्यू न बदलने पर री-रेंडरिंग स्किप हो जाए। मेमोइज़ेशन से कौम्पोनॅन्ट तभी री-रेंडर होगा जब उसकी डिपेंडेंसीज़ बदलेंगी।
246231
* जब आपका पास किया हुआ फंक्शन किसी हुक की डिपेंडेंसी के रूप में उपयोग होता है। उदाहरण के लिए, किसी दूसरे `useCallback` में रैप किए गए फंक्शन की डिपेंडेंसी के रूप में, या [`useEffect`](/reference/react/useEffect) की डिपेंडेंसी के रूप में।
@@ -251,25 +236,11 @@ Caching a function with `useCallback` is only valuable in a few cases:
251236
252237
**नीचे दिए गए सिद्धांतों को फॉलो करके आप काफी मेमोइज़ेशन को अनावश्यक बना सकते हैं:**
253238
254-
<<<<<<< HEAD
255-
1. जब कोई कौम्पोनॅन्ट अन्य कौम्पोनॅन्ट्स को विज़ुअली रैप करता है, तो उसे [JSX को चिल्ड्रन के रूप में स्वीकार](/learn/passing-props-to-a-component#passing-jsx-as-children) करने दें। इससे यदि रैपर कौम्पोनॅन्ट अपने स्टेट को अपडेट करता है, तो React जानता है कि उसके चिल्ड्रन को री-रेंडर करने की ज़रूरत नहीं है।
256-
=======
257239
1. When a component visually wraps other components, let it [accept JSX as children.](/learn/passing-props-to-a-component#passing-jsx-as-children) Then, if the wrapper component updates its own state, React knows that its children don't need to re-render.
258240
2. Prefer local state and don't [lift state up](/learn/sharing-state-between-components) any further than necessary. Don't keep transient state like forms and whether an item is hovered at the top of your tree or in a global state library.
259241
3. Keep your [rendering logic pure.](/learn/keeping-components-pure) If re-rendering a component causes a problem or produces some noticeable visual artifact, it's a bug in your component! Fix the bug instead of adding memoization.
260242
4. Avoid [unnecessary Effects that update state.](/learn/you-might-not-need-an-effect) Most performance problems in React apps are caused by chains of updates originating from Effects that cause your components to render over and over.
261243
5. Try to [remove unnecessary dependencies from your Effects.](/learn/removing-effect-dependencies) For example, instead of memoization, it's often simpler to move some object or a function inside an Effect or outside the component.
262-
>>>>>>> 2534424ec6c433cc2c811d5a0bd5a65b75efa5f0
263-
264-
2. लोकल स्टेट का उपयोग करें और ज़रूरत से ज़्यादा [स्टेट को ऊपर न ले जाएँ](/learn/sharing-state-between-components)। फ़ॉर्म जैसे ट्रांज़िएंट स्टेट या आइटम होवर की जानकारी जैसे स्टेट्स को कौम्पोनॅन्ट ट्री के सबसे ऊपर या ग्लोबल स्टेट लाइब्रेरी में न रखें।
265-
266-
3. अपने [रेंडरिंग लॉजिक को प्योर रखें](/learn/keeping-components-pure)। यदि कौम्पोनॅन्ट के री-रेंडर होने पर समस्या होती है या विज़ुअल ग्लिच दिखता है, तो यह कौम्पोनॅन्ट का बग है। मेमोइज़ेशन जोड़ने के बजाय बग को ठीक करें।
267-
268-
4. [अनावश्यक स्टेट अपडेट्स करने वाले इफ़ेक्ट्स](/learn/you-might-not-need-an-effect) से बचें। React ऐप्स की अधिकतर परफॉर्मेंस समस्याएँ ऐसे इफ़ेक्ट्स से होती हैं जो अपडेट की चेन शुरू करते हैं, जिससे कौम्पोनॅन्ट बार-बार रेंडर होते हैं।
269-
270-
5. इफ़ेक्ट्स में से [अनावश्यक डिपेंडेंसीज़ हटाएँ](/learn/removing-effect-dependencies)। उदाहरण के लिए, मेमोइज़ेशन की बजाय ऑब्जेक्ट या फंक्शन को इफ़ेक्ट के अंदर या कौम्पोनॅन्ट के बाहर रखना आसान होता है।
271-
272-
यदि इसके बाद भी कोई इंटरैक्शन धीमा लगता है, तो [React Developer Tools प्रोफ़ाइलर](https://legacy.reactjs.org/blog/2018/09/10/introducing-the-react-profiler.html) का उपयोग करें ताकि पता लगे कि कौन-से कौम्पोनॅन्ट्स मेमोइज़ेशन से सबसे ज़्यादा लाभ पा सकते हैं, और ज़रूरत के हिसाब से मेमोइज़ेशन जोड़ें। इन सिद्धांतों को अपनाने से आपके कौम्पोनॅन्ट्स को डिबग करना और समझना आसान होगा। लंबे समय के लिए, हम [मेमोइज़ेशन को ऑटोमैटिकली करने पर रिसर्च](https://www.youtube.com/watch?v=lGEMwh32soc) कर रहे हैं।
273244
274245
</DeepDive>
275246

0 commit comments

Comments
 (0)