Skip to content

TypeScript + useQuery - Type guarding #930

Answered by boschni
alinjie asked this question in General
Discussion options

You must be logged in to vote

Hi @alinjie! You could do it like this for example:

function Component() {
  const { data, error } = useQuery('key', queryFn)
  if (error) return <div>Error</div>
  if (!data) return <div>Loading</div>
  return <div>Data: {data}</div>
}

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@alinjie
Comment options

@boschni
Comment options

boschni Aug 28, 2020
Collaborator

@alinjie
Comment options

Answer selected by alinjie
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants