Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugins: Deprecate 'withPluginContext' HOC #66363

Merged
merged 3 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ _Returns_

#### withPluginContext

> **Deprecated** 6.8.0 Use `usePluginContext` hook instead.

A Higher Order Component used to inject Plugin context to the wrapped component.

_Parameters_
Expand Down
1 change: 1 addition & 0 deletions packages/plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@babel/runtime": "7.25.7",
"@wordpress/components": "*",
"@wordpress/compose": "*",
"@wordpress/deprecated": "*",
"@wordpress/element": "*",
"@wordpress/hooks": "*",
"@wordpress/icons": "*",
Expand Down
7 changes: 7 additions & 0 deletions packages/plugins/src/components/plugin-context/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { createContext, useContext } from '@wordpress/element';
import { createHigherOrderComponent } from '@wordpress/compose';
import deprecated from '@wordpress/deprecated';

/**
* Internal dependencies
Expand Down Expand Up @@ -34,6 +35,8 @@ export function usePluginContext() {
* A Higher Order Component used to inject Plugin context to the
* wrapped component.
*
* @deprecated 6.8.0 Use `usePluginContext` hook instead.
*
* @param mapContextToProps Function called on every context change,
* expected to return object of props to
* merge with the component's own props.
Expand All @@ -47,6 +50,10 @@ export const withPluginContext = (
) => T & PluginContext
) =>
createHigherOrderComponent( ( OriginalComponent ) => {
deprecated( 'wp.plugins.withPluginContext', {
since: '6.8.0',
alternative: 'wp.plugins.usePluginContext',
} );
return ( props ) => (
<Context.Consumer>
{ ( context ) => (
Expand Down
1 change: 1 addition & 0 deletions packages/plugins/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"references": [
{ "path": "../components" },
{ "path": "../compose" },
{ "path": "../deprecated" },
{ "path": "../element" },
{ "path": "../hooks" },
{ "path": "../icons" },
Expand Down
Loading