Skip to content

Commit

Permalink
Memoize useSelect callbacks on the header toolbar items (#23337)
Browse files Browse the repository at this point in the history
  • Loading branch information
diegohaz authored Jun 20, 2020
1 parent 5e0b80a commit 9fae92f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions packages/editor/src/components/editor-history/redo.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import { redo as redoIcon } from '@wordpress/icons';
import { forwardRef } from '@wordpress/element';

function EditorHistoryRedo( props, ref ) {
const hasRedo = useSelect( ( select ) =>
select( 'core/editor' ).hasEditorRedo()
const hasRedo = useSelect(
( select ) => select( 'core/editor' ).hasEditorRedo(),
[]
);
const { redo } = useDispatch( 'core/editor' );
return (
Expand Down
5 changes: 3 additions & 2 deletions packages/editor/src/components/editor-history/undo.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import { undo as undoIcon } from '@wordpress/icons';
import { forwardRef } from '@wordpress/element';

function EditorHistoryUndo( props, ref ) {
const hasUndo = useSelect( ( select ) =>
select( 'core/editor' ).hasEditorUndo()
const hasUndo = useSelect(
( select ) => select( 'core/editor' ).hasEditorUndo(),
[]
);
const { undo } = useDispatch( 'core/editor' );
return (
Expand Down
3 changes: 2 additions & 1 deletion packages/editor/src/components/table-of-contents/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import TableOfContentsPanel from './panel';

function TableOfContents( { hasOutlineItemsDisabled, ...props }, ref ) {
const hasBlocks = useSelect(
( select ) => !! select( 'core/block-editor' ).getBlockCount()
( select ) => !! select( 'core/block-editor' ).getBlockCount(),
[]
);
return (
<Dropdown
Expand Down
3 changes: 2 additions & 1 deletion packages/editor/src/components/table-of-contents/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ function TableOfContentsPanel( { hasOutlineItemsDisabled, onRequestClose } ) {
paragraphCount: getGlobalBlockCount( 'core/paragraph' ),
numberOfBlocks: getGlobalBlockCount(),
};
}
},
[]
);
return (
/*
Expand Down

0 comments on commit 9fae92f

Please sign in to comment.