|
|
|
|
|
by ctidd
2232 days ago
|
|
It sounds like you're talking about network resolved state. I like to share this sort of state using a subscription model, where components subscribe to a property of a state root (which anchors/owns the state and how to fetch it), resolving that property's state when mounted. Where that root is in the tree determines the lifecycle of the state (e.g. it's gone when unmounted), and multiple subscribers to the same property can mount, unmount, etc. at any point during that lifecycle without duplication. I believe this model has similarities to both Apollo and Angular services, though I don't have direct experience with either. |
|
EDIT: quick example here https://codesandbox.io/s/unruffled-easley-ry6x2?file=/src/Ap...
This is a fairly innocuous example since the bug is immediately apparent from the button not working. Now imagine the failure mode is more subtle, and these components are about two dozen layers apart down the tree.