React to a change of the block alignment

So, I have a Gutenberg block that has a custom component inside, that needs to be refreshed if the dimensions of the blo

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745335810a4623097.html

相关推荐

  • React to a change of the block alignment

    So, I have a Gutenberg block that has a custom component inside, that needs to be refreshed if the dimensions of the blo

    7小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信