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 पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
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 codereferences/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
कमेंट
- …
इस 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 सुनिश्चित करने में उपयोगी है।
मिलती-जुलती skills
angular-developer
280kआपके एजेंट को Angular code बनाने और प्रोजेक्ट स्ट्रक्चर पर सलाह देने में मदद करता है। नए प्रोजेक्ट शुरू करने, code के हिस्से बनाने, या performance और accessibility सुधारने में उपयोगी है।
frontend-a11y
280kआपके एजेंट को web interfaces को सबके लिए accessible बनाने में मदद करता है। यह सुनिश्चित करता है कि websites और apps screen readers और keyboard navigation के साथ अच्छे से काम करें।
frontend-patterns
280kआपके एजेंट को React और Next.js में frontend development के modern patterns लागू करने में मदद करता है। यह performance optimize करता है, state manage करता है और best practices फॉलो करवाता है।