Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List View: Use default parameters instead of defaultProps #46266

Merged
merged 3 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions packages/block-editor/src/components/list-view/branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const countReducer =
function ListViewBranch( props ) {
const {
blocks,
selectBlock,
selectBlock = () => {},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to declare this as a constant outside of the component, so it won't be redeclared on every re-render that doesn't have a selectBlock prop?

Similar to how it's done here:

const noop = () => {};
function BlockAlignmentMatrixControl( props ) {
const {
label = __( 'Change matrix alignment' ),
onChange = noop,

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good I will push the update in few minutes.

Btw, I've seen both patterns used in the codebase. Example:

onChange = () => {},
onInputChange = () => {},
onFocus = undefined,

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True! I see those as potential optimizations we can do in the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 8ca2a1c.

showBlockMovers,
selectedClientIds,
level = 1,
Expand Down Expand Up @@ -215,8 +215,4 @@ function ListViewBranch( props ) {
);
}

ListViewBranch.defaultProps = {
selectBlock: () => {},
};

export default memo( ListViewBranch );
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const countReducer =
function ListViewBranch( props ) {
const {
blocks,
selectBlock,
selectBlock = () => {},
Mamaduka marked this conversation as resolved.
Show resolved Hide resolved
showBlockMovers,
selectedClientIds,
level = 1,
Expand Down Expand Up @@ -203,8 +203,4 @@ function ListViewBranch( props ) {
);
}

ListViewBranch.defaultProps = {
selectBlock: () => {},
};

export default memo( ListViewBranch );