Passing an SDK object to an RTKQuery slice #1942
-
Hello! I'm struggling to find a good way of using an SDK with RTKQuery's queryFn, without having to pass the SDK object in on every call.
I'm having to call the endpoint using useGetDataQuery(client), but it would be nice to be able to do this without having to pass the client to every component and sending it to the query, as the client is created within the AppContext when the application starts and never changes. (This is in a big, old codebase so most of it was written without Redux.) Is there a way to do this by:
It is not a strict requirement that the Api client lives within the context, but would make integration with the existing code easier. Thanks for the read. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Managed to get it working by creating the slice within the context itself. Rather than having the API then exported in a global context, I then get access to it by referring to an API object within the context. |
Beta Was this translation helpful? Give feedback.
Managed to get it working by creating the slice within the context itself. Rather than having the API then exported in a global context, I then get access to it by referring to an API object within the context.