erquhartE
Convex Community17mo ago
4 replies
erquhart

Convex cache `useQuery` breaks type safety

import { useQuery } from 'convex/react'
import { useQuery as useCachedQuery } from  'convex-helpers/react/cache'

const Component = () => {
  const data = useQuery(my.func, {})
  // TypeScript will error here because `data` may be undefined
  console.log(data.prop)

  const cachedData = useCachedQuery(my.func, {})
  // TypeScript does not complain, but the value still may be undefined
  console.log(cachedData.prop)
}

Any chance I'm holding this wrong?
Was this page helpful?