React context
Observables travel through React context like any other value. Here a Subject lives in a context provider; components read it with useObservable via a small useModeValue() hook and write to it with subject.next(...) via useSetMode().
Both components inside the provider share the same subject, so switching the mode updates them together — while the component outside the provider reads the default context value and never changes.
Last updated on