how to update react context inside functional component

JavaScript
const themes = {
  light: {
    foreground: "#000000",
    background: "#eeeeee"
  },
  dark: {
    foreground: "#ffffff",
    background: "#222222"
  }
};

const ThemeContext = React.createContext(themes.light);

function App() {
  return (
    <ThemeContext.Provider value={themes.dark}>
      <Toolbar />
    </ThemeContext.Provider>
  );
}

// Child Component
function Toolbar(props) {
  return (
    <div>
      <ThemedButton />
    </div>
  );
}


// Accessing Context in Functional Component
function ThemedButton() {
  // This is how, you can Access Context
  const theme = useContext(ThemeContext);
  
  return (
    <button style={{ background: theme.background, color: theme.foreground }}>
      I am styled by theme context!
    </button>
  );
}
Source

Also in JavaScript: