tRPCttRPC
Powered by
MugetsuM
tRPC•3y ago•
7 replies
Mugetsu

How to enforce usequery as NonNullable

I have a custom hook with infinite query. I check for undefined at the app first render and then it is reused so I know by then, the type should not be undefined. I would like to be able to infer its type without undefined conditionally. Can I do that? How to if so??

export const useAppContext = (enabled = true) =>
  api.appContext.getAppContext.useQuery(undefined, {
    staleTime: Infinity,
    enabled,
    select: (data) => {
      currentRoles = data?.authorisation?.roles ?? []
      return data
    },
  })
export const useAppContext = (enabled = true) =>
  api.appContext.getAppContext.useQuery(undefined, {
    staleTime: Infinity,
    enabled,
    select: (data) => {
      currentRoles = data?.authorisation?.roles ?? []
      return data
    },
  })
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

Data from useQuery is inferred as data: {} | undefined
zirkelcZzirkelc / ❓-help
3y ago
How to call useQuery with params inside JSX
SonSSon / ❓-help
3y ago
useQuery context
Answer OverflowAAnswer Overflow / ❓-help
3y ago
tRPC useQuery waits for all queries—How to render ASAP?
ThomasTThomas / ❓-help
13mo ago