Theo's Typesafe CultTTC
Theo's Typesafe Cult2y ago
2 replies
Andrew

Unhelpful useQuery error

I'm trying to either get an id from stored cookies or if not found, query for fresh id using trpc, then using that id for another query. I am getting issues with the second useQuery but the error message is cryptic

export default function FreeChatContext() {
  const [currentMessage, setCurrentMessage] = useState("");
  const [errorMessage, setErrorMessage] = useState("");
  const [isTyping, setIsTyping] = useState(false);
  // get free user account from cookies or create new
  const cookieStore = useCookies();
  const userUUID: string =
    cookieStore.get("user_uuid") ??
    api.account.generateUniqueUser.useQuery().data?.sessionToken ??
    "";

  useEffect(() => {
    if (userUUID) cookieStore.set("user_uuid", userUUID);
  }, [userUUID]);

  // Load messages
  const chatMessageData = api.getChats.getChatUnauth.useQuery({
    uuid: userUUID,
  });

  const utils = api.useUtils();
  const { mutate, error } = api.getChats.getFreeChatMessage.useMutation({
...


I've also tried getting cookies in a wrapper component but I get Error: Rendered fewer hooks than expected.
image.png
Was this page helpful?