Skip to content

Commit

Permalink
Mobile - ReusableBlocksTab - Fix useSelect warning by extracting filt…
Browse files Browse the repository at this point in the history
…ering logic outside into a useMemo
  • Loading branch information
geriux committed Aug 18, 2023
1 parent 3b429cd commit 46f89c3
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { useMemo } from '@wordpress/element';

/**
* Internal dependencies
Expand All @@ -12,18 +13,22 @@ import { store as blockEditorStore } from '../../store';
import { createInserterSection, filterInserterItems } from './utils';

function ReusableBlocksTab( { onSelect, rootClientId, listProps } ) {
const { items } = useSelect(
const { inserterItems } = useSelect(
( select ) => {
const { getInserterItems } = select( blockEditorStore );
const allItems = getInserterItems( rootClientId );

return {
items: filterInserterItems( allItems, { onlyReusable: true } ),
inserterItems: allItems,
};
},
[ rootClientId ]
);

const items = useMemo( () => {
return filterInserterItems( inserterItems, { onlyReusable: true } );
}, [ inserterItems ] );

const sections = [ createInserterSection( { key: 'reuseable', items } ) ];

return (
Expand Down

0 comments on commit 46f89c3

Please sign in to comment.