मुख्य सामग्री पर जाएँ
Skillpedia
वेबसाइट और UI (frontend)40k · #7383

react18-batching-patterns

यह क्या करती है

यह टूल React 18 इस्तेमाल करने वाले पुराने code ('class components') की एक आम समस्या ठीक करने में मदद करता है। यह ध्यान रखता है कि स्क्रीन के updates अलग-अलग होने के बजाय एक साथ हों, जिससे performance बेहतर होती है।

कब इस्तेमाल करें

  • ✓जब आपके पास कई screen updates हों जो एक साथ दिखाई नहीं देते।
  • ✓अगर आपका code async functions (async/await, Promises, setTimeout) के अंदर कई बार state update करता है।
  • ✓React 18 में update करने के बाद performance की समस्या या visual bugs आ रहे हों।

Skill का लिंक

https://github.com/github/awesome-copilot/blob/main/skills/react18-batching-patterns/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/github/awesome-copilot/blob/main/skills/react18-batching-patterns/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“React 18 के साथ मेरे class component के screen updates सही तरीके से कैसे काम करें?”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

यह विश्लेषण करता है कि आपके code में screen updates (setState) कहाँ बुलाए जाते हैं। अगर वे ऐसी जगह हैं जहाँ React 18 अपने आप batching करता है (जैसे events के अंदर), तो यह सुधार का तरीका बताता है। अगर नहीं, तो यह मदद करता है कि तुरंत update करने के लिए flushSync इस्तेमाल करें या code को refactor करें।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

React 18 Automatic Batching Patterns

Reference for diagnosing and fixing the most dangerous silent breaking change in React 18 for class-component codebases.

The Core Change

Location of setState React 17 React 18
React event handler Batched Batched (same)
setTimeout Immediate re-render Batched
Promise .then() / .catch() Immediate re-render Batched
async/await Immediate re-render Batched
Native addEventListener callback Immediate re-render Batched

Batched means: all setState calls within that execution context flush together in a single re-render at the end. No intermediate renders occur.

Quick Diagnosis

Read every async class method. Ask: does any code after an await read this.state to make a decision?

Code reads this.state after await?
  YES → Category A (silent state-read bug)
  NO, but intermediate render must be visible to user?
    YES → Category C (flushSync needed)
    NO → Category B (refactor, no flushSync)

For the full pattern for each category, read:

  • references/batching-categories.md - Category A, B, C with full before/after code
  • references/flushSync-guide.md - when to use flushSync, when NOT to, import syntax

The flushSync Rule

Use flushSync sparingly. It forces a synchronous re-render, bypassing React 18's concurrent scheduler. Overusing it negates the performance benefits of React 18.

Only use flushSync when:

  • The user must see an intermediate UI state before an async operation begins
  • A spinner/loading state must render before a fetch starts
  • Sequential UI steps have distinct visible states (progress wizard, multi-step flow)

In most cases, the fix is a refactor - restructuring the code to not read this.state after await. Read references/batching-categories.md for the correct approach per category.

अक्सर पूछे जाने वाले सवाल

'batching' क्या है?

'Batching' का मतलब है कि React कई screen updates को मिलाकर एक कर देता है, ताकि user interface को कई बार दोबारा न बनाना पड़े, और इससे performance बेहतर होती है।

React 18 में क्या बदला?

React 18 में 'batching' (updates को मिलाना) ज़्यादा जगहों पर अपने आप काम करने लगा, जैसे async functions (setTimeout, Promises) के अंदर। यह अच्छा है, लेकिन पुराना code, जो तुरंत updates पर निर्भर था, टूट सकता है।

मुझे `flushSync` कब इस्तेमाल करना चाहिए?

`flushSync` तभी इस्तेमाल करें जब किसी लंबे काम के शुरू होने से पहले user का तुरंत स्क्रीन update देखना ज़रूरी हो। ज़्यादातर मामलों में code को ठीक ('refactor') करना `flushSync` इस्तेमाल करने से बेहतर है।

जानकारी

लेखक का मूल विवरण

Provides exact patterns for diagnosing and fixing automatic batching regressions in React 18 class components. Use this skill whenever a class component has multiple setState calls in an async method, inside setTimeout, inside a Promise .then() or .catch(), or in a native event handler. Use it before writing any flushSync call - the decision tree here prevents unnecessary flushSync overuse. Also u

repo: github/awesome-copilot

लोकप्रियता

GitHub स्टार
40k
रैंकिंग में स्थान
#7383
लाइसेंस
MIT
अपडेट की गई
15/10/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

acquire-codebase-knowledge

40k

आपके एजेंट को किसी मौजूदा code प्रोजेक्ट को समझने और उसका documentation बनाने में मदद करता है। यह नए लोगों को प्रोजेक्ट से जोड़ने या architecture का सार जानने में उपयोगी है।

लेखन और डॉक्यूमेंटडॉक्यूमेंटेशन

acreadiness-assess

40k

आपके एजेंट को किसी प्रोजेक्ट की AI के लिए तैयारी जाँचने और रिपोर्ट बनाने देता है। यह समझने में उपयोगी है कि प्रोजेक्ट AI tools इस्तेमाल करने के लिए कितना तैयार है।

लेखन और डॉक्यूमेंटडॉक्यूमेंटेशन

acreadiness-generate-instructions

40k

आपके एजेंट को assessment के आधार पर AI tools के लिए निर्देश बनाने में मदद करता है। यह बताता है कि AI कोड के साथ बेहतर कैसे काम करे और पहचानी गई कमियाँ कैसे दूर हों।

लेखन और डॉक्यूमेंटडॉक्यूमेंटेशन

acreadiness-policy

40k

आपके एजेंट को AI प्रोजेक्ट assessment के लिए नीतियाँ तय करने या लागू करने में मदद करता है। यह प्रोजेक्ट्स के मूल्यांकन को मानक बनाने और compliance सुनिश्चित करने में उपयोगी है।

AI और एजेंटएजेंट

मिलती-जुलती skills