-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add useSettings hook for reading multiple settings at once #55337
Changes from 1 commit
02d9b61
d157e18
501b039
ffd13a2
5c88662
09becfc
bf20388
938b1ff
9740868
79e62a3
c994be1
2205c38
0160429
f8beb3e
c8e020c
7e530bc
9ebf699
8a312be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,15 @@ import { __ } from '@wordpress/i18n'; | |
/** | ||
* Internal dependencies | ||
*/ | ||
import useSetting from '../../use-setting'; | ||
import { useSettings } from '../../use-setting'; | ||
|
||
export default function useSpacingSizes() { | ||
const spacingSizes = [ | ||
{ name: 0, slug: '0', size: 0 }, | ||
...( useSetting( 'spacing.spacingSizes' ) || [] ), | ||
]; | ||
const spacingSizes = [ { name: 0, slug: '0', size: 0 } ]; | ||
|
||
const [ settingsSizes ] = useSettings( 'spacing.spacingSizes' ); | ||
if ( settingsSizes ) { | ||
spacingSizes.push( ...settingsSizes ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice to avoid the mutation here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that local mutation is fine, it's not worse in any way than creating a new array and concatenating existing arrays into it with the spread operator. |
||
} | ||
|
||
if ( spacingSizes.length > 8 ) { | ||
spacingSizes.unshift( { | ||
|
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.
Should we keep the
EMPTY_OBJECT
fallback here?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.
That's not needed because
defaultLayout
is used only with an object spread operator,...defaultLayout
, which treatsundefined
ornull
as an empty object already.