Pass value to nested attribute #45370
Unanswered
tomektomczuk
asked this question in
Q&A
Replies: 2 comments
-
ok so we have done it this way and it's now working. Is there a better way?
|
Beta Was this translation helpful? Give feedback.
0 replies
-
I would do this (not tested): const updateSpacingAttributes = ( property, breakPoint, direction, value ) => {
const newAttribute = {
...attribute[ property ],
[ breakPoint ]: {
...attribute[ property ][ breakPoint ],
[ direction ]: value,
}
}
setAttributes( { [ property ]: newAttribute } )
}; Since the spread syntax is shallow copy, the key is to explicitly copy nested properties as well. Argument names are also made more meaningful. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a problem with passing value to nested attribute.
I have an object
and a function that passing 4 values
For some reasons when I pass updateProps(xl, margin, marginTop, 16) all breakpoints (xs, md, lg, xl, hd) get the same value from size. Could you tell me what am I doing incorrectly ?
Beta Was this translation helpful? Give feedback.
All reactions