Skip to content

Commit

Permalink
change hook
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras committed Dec 10, 2020
1 parent 2b13593 commit 09be23e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function BlockNavigationBlockSelectButton(
// If label is defined we prioritize it over possible possible
// block variation match title.
const blockDisplayName =
blockLabel !== blockType.title ? blockLabel : blockInformation.title;
blockLabel !== blockType.title ? blockLabel : blockInformation?.title;
const blockPositionDescription = getBlockPositionDescription(
position,
siblingBlockCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,21 @@ import { useSelect } from '@wordpress/data';
// TODO write jsdoc example
// TODO write tests
export default function useMatchingVariationInformation( clientId ) {
const { attributes, name } = useSelect(
return useSelect(
( select ) => {
if ( ! clientId ) return {};
if ( ! clientId ) return null;
const { getBlockName, getBlockAttributes } = select(
'core/block-editor'
);
return {
attributes: getBlockAttributes( clientId ),
name: getBlockName( clientId ),
};
},
[ clientId ]
);
const displayInformation = useSelect(
( select ) => {
if ( ! ( name && attributes ) ) return null;
const { getBlockDisplayInformation } = select( 'core/blocks' );
return getBlockDisplayInformation( name, attributes );
const attributes = getBlockAttributes( clientId );
const name = getBlockName( clientId );
return (
name &&
attributes &&
getBlockDisplayInformation( name, attributes )
);
},
[ name, attributes ]
[ clientId ]
);
return displayInformation;
}

0 comments on commit 09be23e

Please sign in to comment.