Using RTK-query codegen, is there a recommended way to use generated hooks on the server? #4535
Unanswered
LukeCSYello
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I am using NextJS and need typed/generated API methods based on an OpenAPI specfication.
Before I was using OpenAPIAxiosClient to generate a typed API client using an OpenAPI specification. However, when it came to client-side caching and loading and erroring logic it did not meet our requirements.
I then found RTKQuery could generate query and mutation hooks based on your specification with control over cache invalidation etc which we have been switching to use.
The issue is that obviously hooks cannot be run on the client.
I found a similar issue/discussion that said you can use
store.dispatch(api.endpoints.getBlogs.initiate({ limit: 3 }))
which will return a promise, which can be used on server-side code.
I want this functionality to avoid having to analyse the code to avoid using OpenAPIAxiosClient anywhere in client-side code so that it and Axios do not additionally bloat the bundle size with functionality RTKQuery is already capable of. I would only use this functionality like a typed/generated fetch wrapper and not passing the store down to load on the client.
Beta Was this translation helpful? Give feedback.
All reactions