Skip to content

Commit

Permalink
Create IBE using React's in the isolated non-WP browser example
Browse files Browse the repository at this point in the history
To match the new React 18 API.
  • Loading branch information
fullofcaffeine committed Mar 21, 2024
1 parent 4eac66c commit b1241a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions build-browser/isolated-block-editor.js

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions src/browser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/

import { render, unmountComponentAtNode } from '@wordpress/element';
import { createRoot, unmountComponentAtNode } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -68,20 +68,21 @@ function attachEditor( textarea, userSettings = {} ) {
const editor = document.createElement( 'div' );
editor.classList.add( 'editor' );

const editorReactRoot = createRoot( editor );

// Insert after the textarea, and hide it
// @ts-ignore
textarea.parentNode.insertBefore( editor, textarea.nextSibling );
textarea.style.display = 'none';

// Render the editor
render(
editorReactRoot.render(
<IsolatedBlockEditor
settings={ { ...settings, ...userSettings } }
onLoad={ ( parser, rawHandler ) => onLoad( textarea.value, parser, rawHandler ) }
onSaveContent={ ( content ) => saveBlocks( content, textarea ) }
onError={ () => document.location.reload() }
></IsolatedBlockEditor>,
editor
></IsolatedBlockEditor>
);
}

Expand Down

0 comments on commit b1241a0

Please sign in to comment.