Skip to content

Commit

Permalink
Editor: Use hooks instead of HoCs in PostComments (#53231)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla committed Aug 1, 2023
1 parent d5d9161 commit c05c66c
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions packages/editor/src/components/post-comments/index.js
Expand Up @@ -3,17 +3,23 @@
*/
import { __ } from '@wordpress/i18n';
import { CheckboxControl } from '@wordpress/components';
import { compose } from '@wordpress/compose';
import { withSelect, withDispatch } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';

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

function PostComments( { commentStatus = 'open', ...props } ) {
function PostComments() {
const commentStatus = useSelect(
( select ) =>
select( editorStore ).getEditedPostAttribute( 'comment_status' ) ??
'open',
[]
);
const { editPost } = useDispatch( editorStore );
const onToggleComments = () =>
props.editPost( {
editPost( {
comment_status: commentStatus === 'open' ? 'closed' : 'open',
} );

Expand All @@ -27,16 +33,4 @@ function PostComments( { commentStatus = 'open', ...props } ) {
);
}

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

1 comment on commit c05c66c

@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 c05c66c.
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/5727616540
📝 Reported issues:

Please sign in to comment.