React › Context API

What is a common real world use case for the Context API besides sharing a theme?

Beginner

Answer

Context is commonly used for information that many parts of an app need at once, such as the currently logged in user, the selected language for translations, or shopping cart contents in an online store, avoiding the need to pass this shared data through many layers of components manually.
const LanguageContext = React.createContext('english');

function App() {
  const [language, setLanguage] = useState('english');
  return (
    <LanguageContext.Provider value={language}>
      <Header />
      <MainContent />
    </LanguageContext.Provider>
  );
}
Real-world example A travel booking site lets a user change their preferred language once at the top of the app, and every page, from the search bar to the footer, instantly displays text in that chosen language using shared context.

Common follow-ups: How would you let a user actually change the context value, not just read it?;Is Context a good replacement for every use case of a dedicated state management library?