Hacker News new | ask | show | jobs
by just-boris 3033 days ago
Thank you! I appreciate all your replies, but want clarify this one:

> This is impossible to express with a HOC without reimplementing the whole React in it.

What is the problem here? We return `null` from the beginning, then spinner, if reached timeout and finally, the provided component, if data has arrived.

1 comments

Please watch my demo. It doesn’t just unmount the children when I start fetching. It keeps the previous screen in place (and fully interactive) while the new screen is loaded. If the new screen is ready fast enough, then it fully replaces the old screen without any intermediate state (empty or loading).

I know it’s a bit hard to believe because none of JS libraries I’m aware of can do this yet. But that’s what it does thanks to cooperative scheduling and a double buffering-like system we implemented. I totally understand that it doesn’t quite “click” from the first explanation because you really need to try it to get it.

But to explain it again: React doesn’t remove the child tree, it suspends the whole update from committing before the tree is ready. So there’s no “holes” or “spinners” if it loads fast enough.

Intuitively my last example with Img component may help. There’s no a way a leaf Img component could delay the whole page from rendering before. With suspense it is possible.