Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> You cannot load any data in a regular React application before you loaded both React and your React components that trigger the fetch.

You totally can!

Don't call fetch directly from a component - it's brittle. Write a hook to abstract that into one place. In your hook you can support prefetching by awaiting the promise you fired before you loaded your JS bundle (if you don't want to modify the server), or else take advantage of the browser cache. In this way your data and code can load in parallel.

Is it common? Not really. But it's a technique that is in the toolbox of a conscientious webdev.





Hm, I guess with the new "use" hook and Suspense I guess you could more easily sync up the Promise from another bundle with React later.

However, I have never seen such an approach recommended before.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: