Skip to content

Commit

Permalink
Missing Block: Use hooks instead of HoC (WordPress#64657)
Browse files Browse the repository at this point in the history
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: t-hamano <[email protected]>
  • Loading branch information
3 people authored and bph committed Aug 31, 2024
1 parent cb4910f commit 63c2037
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions packages/block-library/src/missing/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { __, sprintf } from '@wordpress/i18n';
import { RawHTML } from '@wordpress/element';
import { Button } from '@wordpress/components';
import { createBlock } from '@wordpress/blocks';
import { withDispatch, useSelect } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';
import {
Warning,
useBlockProps,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { safeHTML } from '@wordpress/dom';

function MissingBlockWarning( { attributes, convertToHTML, clientId } ) {
export default function MissingEdit( { attributes, clientId } ) {
const { originalName, originalUndelimitedContent } = attributes;
const hasContent = !! originalUndelimitedContent;
const { hasFreeformBlock, hasHTMLBlock } = useSelect(
Expand All @@ -34,6 +34,16 @@ function MissingBlockWarning( { attributes, convertToHTML, clientId } ) {
},
[ clientId ]
);
const { replaceBlock } = useDispatch( blockEditorStore );

function convertToHTML() {
replaceBlock(
clientId,
createBlock( 'core/html', {
content: originalUndelimitedContent,
} )
);
}

const actions = [];
let messageHTML;
Expand Down Expand Up @@ -81,19 +91,3 @@ function MissingBlockWarning( { attributes, convertToHTML, clientId } ) {
</div>
);
}

const MissingEdit = withDispatch( ( dispatch, { clientId, attributes } ) => {
const { replaceBlock } = dispatch( blockEditorStore );
return {
convertToHTML() {
replaceBlock(
clientId,
createBlock( 'core/html', {
content: attributes.originalUndelimitedContent,
} )
);
},
};
} )( MissingBlockWarning );

export default MissingEdit;

0 comments on commit 63c2037

Please sign in to comment.