Discuss how to manage theme switching in a React application.
Instruction: Explain the strategies for implementing theme switching (e.g., light mode/dark mode) in a React application.
Context: This question tests the candidate's ability to implement a common feature in modern web applications, focusing on their approach to state management and component re-rendering.
Updated
Official answer available
Read the opening below, then unlock the full answer and practical guidance.
I would keep the theme choice in one owner and apply semantic color tokens to the subtree it controls. Context is useful when distant controls need the same choice; it is unnecessary for a single local switch.
This complete App.jsx module uses local state and imports theme.css:...