最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

React to a change of the block alignment

programmeradmin1浏览0评论

So, I have a Gutenberg block that has a custom component inside, that needs to be refreshed if the dimensions of the block change. However, apparently there's no way for me to detect when the alignment attribute (wide or full) has changed.

Is there a way to listen to changes on that attribute, and run a custom callback, when needed?

Thanks!

So, I have a Gutenberg block that has a custom component inside, that needs to be refreshed if the dimensions of the block change. However, apparently there's no way for me to detect when the alignment attribute (wide or full) has changed.

Is there a way to listen to changes on that attribute, and run a custom callback, when needed?

Thanks!

Share Improve this question asked Jul 9, 2019 at 8:09 AndreaAndrea 235 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Turns out that if one uses wp.data.subscribe, you're able to intercept any change that occurr in the editor. As you can imagine, this is not very performant. So I've decided to create an extra hidden attribute that stores the old alignment value for the block, and fire the callback only when that attribute and the align one are not the same.

发布评论

评论列表(0)

  1. 暂无评论