admin管理员组文章数量:1296894
Looking through older tutorials or code for blocks built in 2018/2019 vs the more current blocks, I see two different ways attribute values are set.
For example, the "old" way for an attribute called "content" might be:
onChange={ (newContent) => setAttributes({ content: newContent })}
Whereas in a more modern block:
onChange={ ( content ) => setAttributes( { content } )}
I get it's a minor change but I'm curious if anyone here knows why.
Thanks!
Looking through older tutorials or code for blocks built in 2018/2019 vs the more current blocks, I see two different ways attribute values are set.
For example, the "old" way for an attribute called "content" might be:
onChange={ (newContent) => setAttributes({ content: newContent })}
Whereas in a more modern block:
onChange={ ( content ) => setAttributes( { content } )}
I get it's a minor change but I'm curious if anyone here knows why.
Thanks!
Share Improve this question asked Mar 30, 2021 at 19:28 llysa llysa 1631 silver badge5 bronze badges 01 Answer
Reset to default 5Because { content }
is shorthand for { content: content }
it's a JS thing not a WordPress thing.
Both methods work and do the same thing, but the { content }
syntax is shorter, so the variable was named content
in newer examples to allow it.
Otherwise, there are no security or performance improvements, it's just a shorter syntax for the same thing.
本文标签: block editorWhy is onChange ( content ) gt setAttributes(content) now used
版权声明:本文标题:block editor - Why is onChange={ ( content ) => setAttributes( { content } )} now used? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741645884a2390181.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论