ReactReact Context API

The Context API allows you to share values like state or functions between components without passing props manually at every level.

Use React.createContext() to create context and useContext() to consume it.

import React, { createContext, useContext } from 'react';

const ThemeContext = createContext('light');

function ThemedComponent() {
  const theme = useContext(ThemeContext);
  return <p>Theme is: {theme}</p>;
}

function App() {
  return (
    <ThemeContext.Provider value=\"dark\">
      <ThemedComponent />
    </ThemeContext.Provider>
  );