Skip to content

Instantly share code, notes, and snippets.

@dgwyer
Last active August 30, 2023 15:42
Show Gist options
  • Save dgwyer/1e8413f74a1c850f2b99dd90a5b010b7 to your computer and use it in GitHub Desktop.
Save dgwyer/1e8413f74a1c850f2b99dd90a5b010b7 to your computer and use it in GitHub Desktop.
import { registerPlugin } from "@wordpress/plugins";
import { useState, useEffect, createPortal } from "@wordpress/element";
const SomeEditorPlugin = () => {
const [portalContainer, setPortalContainer] = useState(null);
useEffect(() => {
// Wait for the DOM element to be available
const container = document.querySelector("#some-element");
setPortalContainer(container);
}, []);
if (!portalContainer) {
return null; // Return null until the container is available
}
return createPortal(
<div>Hey there.</div>,
portalContainer
);
};
registerPlugin("some-editor-plugin", {
render: SomeEditorPlugin,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment