Reducers and external stores
useReducer(reducer, initial) keeps every transition of a value in one function.
useReducer(reducer, initial) keeps every transition of a value in one function. It returns [state, dispatch],
and a read right after dispatch already sees the new state, like every write.
useExternalStore(subscribe, getSnapshot, options) reads a value that lives outside ShadowJS: a store from another
library, a browser API, an observable. subscribe(notify) runs in an effect after the owner is created and returns
the unsubscribe function, which runs when the owner is disposed. getSnapshot() is read untracked. The accessor
changes only when the snapshot differs by equals. On the server nothing is subscribed; the accessor returns
getServerSnapshot() when you give one. This one API is the ShadowJS form of React's useSyncExternalStore and of
Solid's from and observable.