-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add withRegistry HigherOrderComponent (#14370)
- Loading branch information
1 parent
f58c60d
commit af4288e
Showing
3 changed files
with
36 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createHigherOrderComponent } from '@wordpress/compose'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { RegistryConsumer } from '../registry-provider'; | ||
|
||
/** | ||
* Higher-order component which renders the original component with the current | ||
* registry context passed as its `registry` prop. | ||
* | ||
* @param {WPComponent} OriginalComponent Original component. | ||
* | ||
* @return {WPComponent} Enhanced component. | ||
*/ | ||
const withRegistry = createHigherOrderComponent( | ||
( OriginalComponent ) => ( props ) => ( | ||
<RegistryConsumer> | ||
{ ( registry ) => ( | ||
<OriginalComponent | ||
{ ...props } | ||
registry={ registry } | ||
/> | ||
) } | ||
</RegistryConsumer> | ||
), | ||
'withRegistry' | ||
); | ||
|
||
export default withRegistry; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters