@wordpress/data: Export entire registry context#15445
Conversation
This is needed for any consuming code that wants to implement the `useContext` hook for the registry.
- also fixes some wrapping in earlier changelog entry
aduth
left a comment
There was a problem hiding this comment.
I think based on the availability of useContext and its usage pattern, we should want to expose this object anywhere we also expose the provider and consumer subcomponents. If agreeable, we should consider auditing and creating a tracking issue.
For confirmation, this capitalization (UpperCamelCase) does seem to be what is promoted by React in their documentation:
|
|
||
| Undocumented declaration. | ||
|
|
||
| <a name="RegistryContext" href="#RegistryContext">#</a> **RegistryContext** |
There was a problem hiding this comment.
Can we make sure this is documented? See also #15176, which proposes documentation for RegistryConsumer and RegistryProvider.
|
I forgot about this pull! I think we should actually either close this or rework it so that it instead just exposes the |
|
@nerrad But |
In the case of for the registry, I think any implementation would just use We'd still need to export |
|
Okay, this seems like a good conservative default for now. My thinking was less about registry context specifically, but context consumers generally. I think we tend to not expose the consumers anyways (intentionally?), so no need to be premature with exposing the context object I suppose. The only potential downside is that if we do choose to have a generic pattern, we'd need to decide how to reconcile this with |
Good points there, but I think context (a a general term, not an intentional pun!) matters here. I think we should generally avoid exposing low level things from |
|
Fwiw, we probably could avoid exposing |
|
This pull is now invalid. There is a |
Description
As a part of the work being done on #15444, the
useContexthook is being used to obtain theregistryvalue from the context. However in order to do this the entire registry context object must be exposed from@wordpress/data. This pull does so.This has utility for anywhere else where
useContextmight be implemented with the registry context.How has this been tested?
Types of changes
This is a non-breaking change and is an enhancement exposing the entire RegistryContext object. Existing Consumer and Provider values are left alone so there's no impact to existing code.
Checklist: