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 badges1 Answer
Reset to default 1Turns 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.