Skip to content

Commit

Permalink
Button block: use early return to optimize save.js. (#29781)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZebulanStanphill committed Mar 12, 2021
1 parent f8052e1 commit 27cb4f6
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions packages/block-library/src/button/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export default function save( { attributes, className } ) {
url,
width,
} = attributes;

if ( ! text ) {
return null;
}

const colorProps = getColorAndStyleProps( attributes );
const buttonClasses = classnames(
'wp-block-button__link',
Expand All @@ -45,19 +50,17 @@ export default function save( { attributes, className } ) {
} );

return (
text && (
<div { ...useBlockProps.save( { className: wrapperClasses } ) }>
<RichText.Content
tagName="a"
className={ buttonClasses }
href={ url }
title={ title }
style={ buttonStyle }
value={ text }
target={ linkTarget }
rel={ rel }
/>
</div>
)
<div { ...useBlockProps.save( { className: wrapperClasses } ) }>
<RichText.Content
tagName="a"
className={ buttonClasses }
href={ url }
title={ title }
style={ buttonStyle }
value={ text }
target={ linkTarget }
rel={ rel }
/>
</div>
);
}

0 comments on commit 27cb4f6

Please sign in to comment.