Under some circumstances Reacts default api can be a little cumbersome for context creation, especially due to the singleton pattern whereas the old api was component bound. There's also the open question as to how you would pass a context down to consumers. They seem to have let this deliberately open in order to see which patterns emerge.
I tried for a couple of days to come up with something more comfortable in order to make it easier to
a. create providers
b. refer to them from a consumers perspective
c. re-use providers in nested trees with unique identifiers
I came to the conclusion that it's probably best to offer both a hoc and imperative functions for creating/getting/removing a named context. I'm adding this as an issue as a space to collect ideas, suggestions or contributions.
Under some circumstances Reacts default api can be a little cumbersome for context creation, especially due to the singleton pattern whereas the old api was component bound. There's also the open question as to how you would pass a context down to consumers. They seem to have let this deliberately open in order to see which patterns emerge.
I tried for a couple of days to come up with something more comfortable in order to make it easier to
a. create providers b. refer to them from a consumers perspective c. re-use providers in nested trees with unique identifiers
I came to the conclusion that it's probably best to offer both a hoc and imperative functions for creating/getting/removing a named context. I'm adding this as an issue as a space to collect ideas, suggestions or contributions.
Imperative API
Example: https://codesandbox.io/s/30ql1rxzlq
HOC and
subscribe
serving dynamic contextExample: https://codesandbox.io/s/m7q5z407p9