lukas
Explore posts from serversTransform server response on the client before caching
Yes, makes sense - "sometimes is not possible" - yeah, those cases where we don't have control of the backend definitely we need something in the f.e to shape the data haha. But I guess if trpc allow to override the query fn would be a anti-pattern and better to use the raw
trpc client
and just call the async function together with react query - can't think a lot of useful scenarios for that, since when someone is using trpc the whole idea is to have control of the full stack code. Anyway, thanks for sharing your findings 🙂12 replies
Transform server response on the client before caching
Hey @João Bezerra nice that you got that solved at the end, but I definitely think that transforming and parsing data in the client side/frontend is definitely a bad choice - except for scenarios that we have no control of our backend or is impossible to change it - it's a personal opinion but throughout the years I have seem too many issues/frontend problems because the shape of the data doesn't match on how the frontend needs it, definitely it adds more complexity, like in your cause, you are calling procedures inside the query FN, which is breaking the integration to use just trpc out of the box.
But at the end glad you got it solved 🙂
But at the end glad you got it solved 🙂
12 replies
Transform server response on the client before caching
I think the way to go is use selector, in react query you could customize the queryFn but not sure on trpc. Anyway this is an anti patern if the server is returning the data not in the shape that the frontend needs, that's why I'd definitely create a new method or talk to your backend devs to modify the existent.
12 replies
Transform server response on the client before caching
Why transform the response on the client? I believe this is not optimal and can't you just send the data from the server exactlly on the way the client will use it to avoid unecessary bandwidght, etc?
Alternatively you can use
selectors
of react-query to filter/select only specfic fields of your data before reading that in the component.12 replies
It is possible to define a middleware for all routes?
Yeah, that makes sense. I am replicating it again but in my case is because I am developing a multi tenancy app where I have multiple roles and I am developing a sub route for each Roles as trpc/next doesn't support multi trpc clients atm yet
11 replies