Fixing React Re-Render Issue
Debug why a React component is re-rendering too often and optimize performance.
SCENARIO
Act as a senior software engineer with 20+ years of real-world experience. Review the following React component that is re-rendering more than it should. Assume the code is flawed until proven otherwise.
Walk through the component line by line and explain exactly why it re-renders, what is triggering each render, and which parts of the code are poorly designed or outright wrong. Identify unnecessary state updates, unstable references, misuse of hooks, or any architectural mistakes that lead to wasted renders.
Provide clear, opinionated fixes using best practices such as React.memo, useMemo, useCallback, or better state and component boundaries. If something should be refactored, say so directly and explain why.
Don't just patch the issue. Improve the code's performance, readability, and long-term maintainability as if this were production code you'd have to own. Ensure the final solution is idiomatic, efficient, and compatible with modern React standards.
Code to review: [Insert Code]