Suggestion Allow server-side data fetching in React components
rasco opened this issue · comments
Is your feature request related to a problem? Please describe.
Components can't really fetch data because that would make them asynchronous, and renderToStaticMarkup
doesn't support that.
If you could fetch data inside components, it would shift the responsibility of handling data closer to where it belongs.
Describe the solution you'd like
With React v18 you can use renderToPipeableStream
, as it fully supports Suspense
Describe alternatives you've considered
I'm not sure if there's any other possibility to fetch data outside of pages? Or some workaround?
Additional context
Astro seems to be one of the very few frameworks that supports server-side data fetching inside components. I guess using asynchronous Suspense
combined with React 18's async SSR rendering would be a working solution for slinkity.
This is a really interesting callout rasco! I didn't know renderToPipeableStream
supported suspense. Worth investigating during our 1.0 canary refactor