-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Conversation
Size Change: +99 B (0%) Total Size: 1.33 MB
ℹ️ View Unchanged
|
@@ -82,7 +82,7 @@ const countReducer = | |||
function ListViewBranch( props ) { | |||
const { | |||
blocks, | |||
selectBlock, | |||
selectBlock = () => {}, |
There was a problem hiding this comment.
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:
gutenberg/packages/block-editor/src/components/block-alignment-matrix-control/index.js
Lines 12 to 17 in f0fe8f6
const noop = () => {}; | |
function BlockAlignmentMatrixControl( props ) { | |
const { | |
label = __( 'Change matrix alignment' ), | |
onChange = noop, |
There was a problem hiding this comment.
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:
gutenberg/packages/components/src/form-token-field/index.tsx
Lines 52 to 54 in 8c44ccb
onChange = () => {}, | |
onInputChange = () => {}, | |
onFocus = undefined, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in 8ca2a1c.
packages/block-editor/src/components/off-canvas-editor/branch.js
Outdated
Show resolved
Hide resolved
/** | ||
* Internal dependencies | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to this change. Just found a duplicate comment and removed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thank you @Mamaduka 🚀
…46266) * List View: Use default parameters instead of defaultProps * Use 'noop' with a stable reference * Remove duplicate comment
What?
PR updates
ListViewBranch
to use ES6 default function parameters instead ofdefaultProps
.Why?
All other defaults are defined using this method, and
defaultProps
for the functional components is getting deprecated. See facebook/react#25699.Testing Instructions
CI checks are green.