tRPCttRPC
Powered by
SansPapyrus683S
tRPC•2y ago•
2 replies
SansPapyrus683

is there a better way to do this?

  let query;
  let params;
  switch (getWhat) {
    case "posts":
      query = api.user.userPosts;
      params = { user: uid, what: "posts", cursor: at };
      break;
    case "likes":
      query = api.user.userPosts;
      params = { user: uid, what: "likes", cursor: at };
      break;
    case "following":
      query = api.user.followedPosts;
  }

  //@ts-ignore
  const { data, isPlaceholderData } = query.useQuery(params, {
    //@ts-ignore
    placeholderData: (prevRes) => prevRes ?? initPosts,
  });
  let query;
  let params;
  switch (getWhat) {
    case "posts":
      query = api.user.userPosts;
      params = { user: uid, what: "posts", cursor: at };
      break;
    case "likes":
      query = api.user.userPosts;
      params = { user: uid, what: "likes", cursor: at };
      break;
    case "following":
      query = api.user.followedPosts;
  }

  //@ts-ignore
  const { data, isPlaceholderData } = query.useQuery(params, {
    //@ts-ignore
    placeholderData: (prevRes) => prevRes ?? initPosts,
  });
so i have a component that renders a post list according to varying api calls
however, this requires the two
ts-ignore
ts-ignore
at the bottom.
is there a way to tell ts that the two api calls result in the exact same type?
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

is there a way to do client-side "middleware"?
TomTTom / ❓-help
3y ago
is there a way to send a streaming response
DerockDDerock / ❓-help
3y ago
Is there a way to extract a procedure signature?
zomarsZzomars / ❓-help
3y ago
Is there a way to use versioning for procedures?
v1narthVv1narth / ❓-help
3y ago