"Clean" way to centralize API calls in RQ while still keeping some typesafety?
Currently I have something like this (using
And usage would be:
But this looks kind of ugly to me, though I have no idea how it's usually implemented. This is basically just writing 1 custom hook for every single kind of API call I would have, which doesn't seem right.
I tried one other version with a single custom hook called
ky which is kinda like axios)And usage would be:
But this looks kind of ugly to me, though I have no idea how it's usually implemented. This is basically just writing 1 custom hook for every single kind of API call I would have, which doesn't seem right.
I tried one other version with a single custom hook called
useApi() which accepted all kinds of props, and returns a specific useQuery() call for that query only (though this looks like it violates the rules of hooks), however the problem with this is that const { data } = useApi() would type data as a union of all possible return types instead, ruining any typesafety I'd have.