Skip to content

Commit

Permalink
Editor: Use hooks instead of HoCs in PostExcerpt (#53229)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored Aug 1, 2023
1 parent 9a5f3db commit d5d9161
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions packages/editor/src/components/post-excerpt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,27 @@
*/
import { __ } from '@wordpress/i18n';
import { ExternalLink, TextareaControl } from '@wordpress/components';
import { withSelect, withDispatch } from '@wordpress/data';
import { compose } from '@wordpress/compose';
import { useDispatch, useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import { store as editorStore } from '../../store';

function PostExcerpt( { excerpt, onUpdateExcerpt } ) {
function PostExcerpt() {
const excerpt = useSelect(
( select ) => select( editorStore ).getEditedPostAttribute( 'excerpt' ),
[]
);
const { editPost } = useDispatch( editorStore );

return (
<div className="editor-post-excerpt">
<TextareaControl
__nextHasNoMarginBottom
label={ __( 'Write an excerpt (optional)' ) }
className="editor-post-excerpt__textarea"
onChange={ ( value ) => onUpdateExcerpt( value ) }
onChange={ ( value ) => editPost( { excerpt: value } ) }
value={ excerpt }
/>
<ExternalLink
Expand All @@ -32,15 +37,4 @@ function PostExcerpt( { excerpt, onUpdateExcerpt } ) {
);
}

export default compose( [
withSelect( ( select ) => {
return {
excerpt: select( editorStore ).getEditedPostAttribute( 'excerpt' ),
};
} ),
withDispatch( ( dispatch ) => ( {
onUpdateExcerpt( excerpt ) {
dispatch( editorStore ).editPost( { excerpt } );
},
} ) ),
] )( PostExcerpt );
export default PostExcerpt;

1 comment on commit d5d9161

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in d5d9161.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5727612008
📝 Reported issues:

Please sign in to comment.