Skip to content

Instantly share code, notes, and snippets.

@bahiirwa
Forked from youknowriad/log.js
Created April 25, 2024 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bahiirwa/7287f7445659d768ab64fd2f2ea36658 to your computer and use it in GitHub Desktop.
Save bahiirwa/7287f7445659d768ab64fd2f2ea36658 to your computer and use it in GitHub Desktop.
Gutenberg Log Deprecations
const { createElement: el, useState, useEffect } = React;
const PanelBody = wp.components.PanelBody;
const PluginSidebar = wp.editor.PluginSidebar;
const addAction = wp.hooks.addAction;
const registerPlugin = wp.plugins.registerPlugin;
function MyPluginSidebar() {
const [ deprecations, setDeprecations ] = useState( [] );
useEffect( () => {
addAction(
'deprecated',
'myplugin/track-deprecations',
( feature, options, message ) => {
console.log( 'new deprecation' );
setDeprecations( ( current ) => [
...current,
{ feature, options, message },
] );
}
);
}, [] );
console.log( 'rerender', deprecations );
return el(
PluginSidebar,
{
name: 'my-sidebar',
title: 'My deprecations',
icon: 'smiley',
},
el(
PanelBody,
{},
deprecations.map( ( deprecation, index ) => {
return el(
'p',
{ key: index },
el( 'strong', {}, deprecation.feature + ' : ' ),
deprecation.message
);
} )
)
);
}
registerPlugin( 'myplugin', {
render: MyPluginSidebar,
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment