Last active
August 30, 2023 15:42
-
-
Save dgwyer/1e8413f74a1c850f2b99dd90a5b010b7 to your computer and use it in GitHub Desktop.
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
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