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 for PostPingbacks #53228

Merged
merged 2 commits into from
Aug 1, 2023
Merged
Changes from 1 commit
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: 11 additions & 15 deletions packages/editor/src/components/post-pingbacks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@
*/
import { __ } from '@wordpress/i18n';
import { CheckboxControl } 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 PostPingbacks( { pingStatus = 'open', ...props } ) {
function PostPingbacks() {
const pingStatus =
useSelect(
( select ) =>
select( editorStore ).getEditedPostAttribute( 'ping_status' ),
[]
) ?? 'open';
Copy link
Member

Choose a reason for hiding this comment

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

Nit (non-blocking): What do you think about returning the default value from inside the mapSelect? For some reason, I found this pattern of useSelect() ?? defaultValue bit odd 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good 👍 Moved in 08ae4a0

const { editPost } = useDispatch( editorStore );
const onTogglePingback = () =>
props.editPost( {
editPost( {
ping_status: pingStatus === 'open' ? 'closed' : 'open',
} );

Expand All @@ -27,14 +33,4 @@ function PostPingbacks( { pingStatus = 'open', ...props } ) {
);
}

export default compose( [
withSelect( ( select ) => {
return {
pingStatus:
select( editorStore ).getEditedPostAttribute( 'ping_status' ),
};
} ),
withDispatch( ( dispatch ) => ( {
editPost: dispatch( editorStore ).editPost,
} ) ),
] )( PostPingbacks );
export default PostPingbacks;
Loading