-
-
Save bahiirwa/7287f7445659d768ab64fd2f2ea36658 to your computer and use it in GitHub Desktop.
Gutenberg Log Deprecations
This file contains hidden or 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
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