Why use React/JS to create a Meta Box

In my previous post I mentioned that the reason why we need to learn to do this is to get all the new features. But what is the new features?

You can read more in my previous post: Custom Field & Meta Box in Gutenberg Editor.

In this short blog post, I want to give a simple example, to transform the field to a full sidebar panel.

From this:

To this (video):

How cool is that?

And we can do this very easily. We simply need to change our code from:

<PluginDocumentSettingPanel name="my-data" title="My Data">
	<TextControl value={myData} onChange={setMyData} />

To this:

	<PluginSidebarMoreMenuItem target={sidebarName}>
		{ sidebarLabel }
	<PluginSidebar name={sidebarName} title={ sidebarLabel }>
			<TextControl value={myData} onChange={setMyData} />

So, basically we simply change the wrapper from PluginDocumentSettingPanel to PluginSidebar.

I create a new branch “feature/sidebar-panel”, you can download it on GitHub:

1 Comment

  1. Asif

    Thank u brother for teaching such important codes and WordPess things…plz continue Blogging more often

Comments are closed.