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. They write to it with subject.next(...) via useSetMode().
Both components inside the provider share the same subject, so switching the mode updates them together. The component outside the provider reads the default context value and never changes.
Last updated on