WeezyEzo
WeezyEzo
TtRPC
Created by SansPapyrus683 on 2/14/2024 in #❓-help
is there a better way to do this?
your implementation is against the laws of hooks. Hooks should not be called conditionally. Instead, you can make use of the enabled option of react query. I think this is the good way of doing what you want.
const { data: posts, isPlaceholderData: isPlaceholderPosts } = api.user.userPosts.useQuery({
user: uid, what: getWhat as 'posts' | 'likes', cursor: at
}, {
enabled: getWhat === 'posts' || getWhat === 'likes',
placeholderData: (prevRes) => prevRest ?? initPosts
})

const { data: following, isPlaceholderData: isPlaceholderFollowing } = api.user.followedPosts.useQuery(undefined, {
enabled: getWhat === 'following',
placeholderData: (prevRes) => prevRest ?? initPosts
})
const { data: posts, isPlaceholderData: isPlaceholderPosts } = api.user.userPosts.useQuery({
user: uid, what: getWhat as 'posts' | 'likes', cursor: at
}, {
enabled: getWhat === 'posts' || getWhat === 'likes',
placeholderData: (prevRes) => prevRest ?? initPosts
})

const { data: following, isPlaceholderData: isPlaceholderFollowing } = api.user.followedPosts.useQuery(undefined, {
enabled: getWhat === 'following',
placeholderData: (prevRes) => prevRest ?? initPosts
})
If you want to use only one variable for any of the data you can do this:
const data = posts || following
const isPlaceholderData = isPlaceholderPosts || isPlaceholderFollowing
const data = posts || following
const isPlaceholderData = isPlaceholderPosts || isPlaceholderFollowing
This issue is more of react-query related rather than trpc.
3 replies
TtRPC
Created by WeezyEzo on 2/9/2024 in #❓-help
Ability to mutate/extend `input` from middlewares
Is there any hope that this will be a feature request or something? I would appreciate this
20 replies
TtRPC
Created by WeezyEzo on 2/9/2024 in #❓-help
Ability to mutate/extend `input` from middlewares
For now, i will fix the data before sending it to trpc
20 replies
TtRPC
Created by WeezyEzo on 2/9/2024 in #❓-help
Ability to mutate/extend `input` from middlewares
Currently, there is no way to implement this functionality outside @trpc/server package. I do not have time to work on this. But if you have a working approach I would be more than happy.
20 replies
TtRPC
Created by WeezyEzo on 2/9/2024 in #❓-help
Ability to mutate/extend `input` from middlewares
So here is what i found. tldr: none of the functions are exported for external use. There is a function called createNewBuilder It does what i want, but it is not exported for external use. There are some other functions that could help (for example, createResolver to create a custom reoslver with my middlewares applied), but I was not able to import them.
20 replies
TtRPC
Created by WeezyEzo on 2/9/2024 in #❓-help
Ability to mutate/extend `input` from middlewares
It would be nice if you can provide a sample code that works for my case
20 replies
TtRPC
Created by WeezyEzo on 2/9/2024 in #❓-help
Ability to mutate/extend `input` from middlewares
I have to mention that I like TRPC and since I have used I didn't use any other approach for backend routes. Just to be clear.
20 replies
TtRPC
Created by WeezyEzo on 2/9/2024 in #❓-help
Ability to mutate/extend `input` from middlewares
This idea will introduce the same overhead, that is, I have to change every schema to transform to coerce empty strings to undefined.
20 replies
TtRPC
Created by WeezyEzo on 2/9/2024 in #❓-help
Ability to mutate/extend `input` from middlewares
I still think that mutating input is the responsibility of trpc. A lot of web frameworks allow you to mutate the input passed. Trpc itself lets you extend the context. Implementing it for input would be convenient as well.
20 replies
TtRPC
Created by WeezyEzo on 2/9/2024 in #❓-help
Ability to mutate/extend `input` from middlewares
This would be an overhead. In my application, empty strings are considered as undefined. Using something like sendDataToTrpcRoute({ a: a === '' ? undefined: a}) for every piece of data is not a good solution for me
20 replies