There’s often time where you want to observe width/height of an element in an easy way. There’s been many trick but with the new
ResizeObserver API, it’s easier than ever. Though not every browser supports this API, so there should still be a fallback to dirty checking/other method if needed.
Here is an example of what a simple implementation for size observation custom attribute would be:
The usage of such attribute would be:
Now whenever size of the div element above changes, our
size property will be updated with the new width/height accordingly.