Comment

Comment by recursive

I'm not a react expert, obviously, but what would be wrong with this?

    class MyComponent {
        constructor() {
            watchViewPort((x, y) => {
                this.something += x + y;
            });
        }

        render() { /* ... */ }
    }

    watchViewPort(callback) {
        addEventListener("resize", (event) => {
            // get x and y
            callback(x, y);
        });
    }
This is obviously not production code, and I haven't tried it, so maybe something doesn't work? What is this missing that hooks provide?
parent recursive 3 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton