P粉3215842632023-08-18 10:40:57
One way is to use createRoot in the wordpress element function, https://developer.wordpress.org/block-editor/reference-guides/packages/packages-element/. This way we can display React components in DOM nodes. step:
Define DOM nodes in render.php:
<div id="replacement_id">要替换的内容</div>
Render the application on this node by adding the following to view.js:
window.addEventListener("load", (event) => { const domElement = document.getElementById("replacement_id"); const root = createRoot(domElement); root.render(<App />); });