Skip to content

Commit

Permalink
Avoid mutation of props
Browse files Browse the repository at this point in the history
  • Loading branch information
stokesman committed Jul 21, 2021
1 parent 2d02f12 commit f1463db
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions packages/widgets/src/blocks/legacy-widget/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,22 @@ export default function Edit( props ) {
ref.current.focus();
}, [ setIsEditing ] );

props = { ...props, isEditing, stopEditing };

// isWide is applicable only at breakpoints greater than small
// wide display of widgets applies only at breakpoints greater than small
const canWideFit = useViewportMatch( 'small' );
props.isWide &&= canWideFit;
const isWide = props.isWide && canWideFit;

const ref = useRef();

useEffect( () => {
if ( props.isSelected ) {
setIsEditing( true );
} else {
setIsEditing( false );
}
}, [ props.isSelected ] );
useEffect( () => setIsEditing( props.isSelected ), [ props.isSelected ] );

const blockProps = useBlockProps( {
ref,
className: classnames( {
'is-wide-widget': props.isWide,
'is-wide-widget': isWide,
} ),
} );

if ( props.isWide ) {
if ( isWide ) {
blockProps.onClick = ( { currentTarget, target } ) => {
if ( currentTarget.contains( target ) ) {
setIsEditing( true );
Expand All @@ -76,7 +68,7 @@ export default function Edit( props ) {
{ ! id && ! idBase ? (
<Empty { ...props } />
) : (
<NotEmpty { ...props } />
<NotEmpty { ...{ ...props, isWide, isEditing, stopEditing } } />
) }
</div>
);
Expand Down

0 comments on commit f1463db

Please sign in to comment.