# BeforeMerge: react-review Comprehensive code review knowledge base for React applications (framework-agnostic). Contains rules across security, performance, architecture, and quality categories. Each rule includes detailed explanations, real-world examples comparing incorrect vs. correct implementations, impact ratings, and formal weakness mappings (CWE) to guide both AI agents and human reviewers. ## Table of Contents ### 1. Security Anti-Patterns (CRITICAL) - 1. Sanitize Content Before dangerouslySetInnerHTML — CRITICAL [CWE-79] - 2. Never Use eval() or new Function() with User Input — CRITICAL [CWE-95] - 3. Use Cryptographic Randomness for Tokens and IDs — CRITICAL [CWE-338] - 4. Prevent Prototype Pollution from Untrusted Input — CRITICAL [CWE-1321] ### 2. Performance Patterns (HIGH) - 5. Split Large Contexts to Prevent Unnecessary Consumer Re-renders — HIGH - 6. Memoize Expensive Computations with useMemo — HIGH - 7. Virtualize Large Lists Instead of Rendering All Items — HIGH - 8. Avoid Inline Object/Array/Function Creation in JSX Props — HIGH ### 3. Architecture Patterns (MEDIUM) - 9. Prefer Composition Over Monolithic Conditional Rendering — MEDIUM - 10. Extract Duplicated Stateful Logic into Custom Hooks — MEDIUM - 11. Eliminate Prop Drilling Through 3+ Component Levels — MEDIUM - 12. Colocate State with the Components That Use It — MEDIUM ### 4. Code Quality (LOW-MEDIUM) - 13. Do Not Mix Controlled and Uncontrolled Input Patterns — MEDIUM - 14. Add Error Boundaries Around Unreliable UI Sections — MEDIUM - 15. Never Use Array Index as Key for Dynamic Lists — MEDIUM - 16. Always Clean Up useEffect Side Effects — MEDIUM --- ## Rules ## Sanitize Content Before dangerouslySetInnerHTML **Impact: CRITICAL (prevents cross-site scripting (XSS) attacks)** React escapes all content rendered via JSX by default, which is a strong XSS defense. However, `dangerouslySetInnerHTML` explicitly bypasses this protection. If the HTML string originates from user input, an API response, a CMS, or any untrusted source, an attacker can inject `