Skip to content

Commit

Permalink
Remove internal state, derive from props.
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonjd committed Jan 9, 2024
1 parent 89c2a7d commit 98e7908
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions packages/block-library/src/post-content/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
import { useSelect, useDispatch } from '@wordpress/data';
import { Placeholder, Button } from '@wordpress/components';
import { postContent as icon } from '@wordpress/icons';
import { useState, useEffect } from '@wordpress/element';
import { createBlock } from '@wordpress/blocks';

/**
Expand Down Expand Up @@ -87,7 +86,7 @@ function PostContentPlaceholder( { layoutClassNames } ) {
<div { ...blockProps }>
<Placeholder
className="wp-block-post-content__content-placeholder"
withIllustration={ true }
withIllustration
>
<p>
{ __( 'This block will be replaced with your content.' ) }
Expand Down Expand Up @@ -123,12 +122,11 @@ function EditableContent( { context = {}, clientId } ) {
);

const hasInnerBlocks = !! entityRecord?.content?.raw || blocks?.length;
const [ hasPlaceholder, setHasPlaceholder ] = useState( ! hasInnerBlocks );

const { children, ...props } = useInnerBlocksProps(
useBlockProps( {
className: classnames( 'entry-content', {
'wp-block-post-content__placeholder': hasPlaceholder,
'wp-block-post-content__placeholder': ! hasInnerBlocks,
} ),
} ),
{
Expand All @@ -138,13 +136,7 @@ function EditableContent( { context = {}, clientId } ) {
}
);

useEffect(
() => setHasPlaceholder( ! hasInnerBlocks ),
[ hasInnerBlocks ]
);

const onClose = () => {
setHasPlaceholder( false );
const initialBlock = createBlock( 'core/paragraph' );
insertBlock( initialBlock, 0, clientId );
selectBlock( initialBlock.clientId );
Expand All @@ -161,7 +153,7 @@ function EditableContent( { context = {}, clientId } ) {
return (
<div { ...props }>
{ children }
{ hasPlaceholder && (
{ ! hasInnerBlocks && (
<EmptyContentPlaceholder
context={ context }
onClose={ onClose }
Expand Down

0 comments on commit 98e7908

Please sign in to comment.