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

Fix the useSelect warning of the “Copy all blocks” menu item #53833

Closed
wants to merge 1 commit into from
Closed
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
12 changes: 5 additions & 7 deletions packages/edit-post/src/plugins/copy-content-menu-item/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@
* WordPress dependencies
*/
import { MenuItem } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { select, useDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { useCopyToClipboard } from '@wordpress/compose';
import { store as noticesStore } from '@wordpress/notices';
import { store as editorStore } from '@wordpress/editor';

export default function CopyContentMenuItem() {
const { createNotice } = useDispatch( noticesStore );
const getText = useSelect(
( select ) => () =>
select( editorStore ).getEditedPostAttribute( 'content' ),
[]
);

function onSuccess() {
createNotice( 'info', __( 'All content copied.' ), {
Expand All @@ -23,7 +18,10 @@ export default function CopyContentMenuItem() {
} );
}

const ref = useCopyToClipboard( getText, onSuccess );
const ref = useCopyToClipboard(
() => select( editorStore ).getEditedPostAttribute( 'content' ),
onSuccess
);

return <MenuItem ref={ ref }>{ __( 'Copy all blocks' ) }</MenuItem>;
}
Loading