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({
...
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.
No description
1 Reply
Andrew
AndrewOP9mo ago
This only errors out once on first load and not again afterwards
Want results from more Discord servers?
Add your server