Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
18 replies
batata

Wait for useQuery result

 const favShop = trpc.favorite.getById.useQuery({
    userId: session.data?.user?.id,
    shopId: coffeeShop.id,
  })

  const [favorite, setFavorite] = useState(
    favShop.data?.length !== 0 && favShop.data !== undefined ? true : false
  )

so im checking on load if the current shop is a favourite shop or not, but the favShop is undefined at load then you get the result, since i cant use async await on it, how do i wait for the result so i can use it in the useState
Was this page helpful?