Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: Use hooks instead of HoCs in PostExcerpt #53229

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;