Open hasanaktas opened 1 year ago
Cc @georgiev-anton has done some SSR work with prefetch may weigh in here.
hi @hasanaktas do you mean prefetch function?
hi @georgiev-anton. In this structure (if hooks are created), it is not possible to not only prefetch function but also make API requests within server components.
@hasanaktas @georgiev-anton if you guys wuld like to work on a PR together that would be great. I don't use SSR so i know its not something I am going to work on.
@melloware
Actually, all we need to do is create the hooks in a separate file.
Just as we create the schemas in a separate file when mode split or tag-split, we can also create the hooks for the react-query or swr in a separate hooks.ts file.
@hasanaktas can you show an example of why you can’t use requests from the same file with hooks? I don't see a problem
there is an export of requests
@georgiev-anton
When Next js 13 was first released, if you used getCategories from the file below in the server component, it would cause an error.
Now, when I try it on an empty project in Next 14, it does not give an error. I do not know in which intermediate version this problem was solved.
That's why I wanted to extract the hooks to be used on the client side as a separate file.
I'm sorry for wasting your time.
In Nextjs 13, in order to send requests to server components, there must be no hooks in the file containing the function to be used.
We need to be able to extract requests and hooks into separate files with a parameter added to the config.
In this way, we can use the hooks directory only on the client side and the requests directory everywhere.
We are happy to use Orval, and this is one of the things that makes us think the most when updating the dependencies of our project.