brillout / telefunc

Remote Functions. Instead of API.
https://telefunc.com
MIT License
688 stars 31 forks source link

[React] Using Telefunc for initial SSR data (like Next.js's Server Actions) #102

Open brillout opened 8 months ago

brillout commented 8 months ago

Thanks to the SSR streaming capabilities of React 18, Telefunc can be used for fetching the initial SSR data. (Instead, for example, of using Vike's data() hook.)

You can already do that today by using Telefunc with the useAsync() component hook of react-streaming.

If you use vike-react, vike-react already installs react-streaming.

If you use vike-react-query, then see vike-react-query > Usage with Telefunc. (Such Telefunc + React Query usage is very much recommended if you want to use React Query. This ticket is about having integrations without using React Query.)

[!WARNING] There is also an integration with react-streaming built directly into Telefunc, but it isn't ready for public usage yet and breaking change will occur. You can play around with it at /examples/react-streaming. But you're warned: the API as it is today will be deprecated.